mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-27 19:53:45 +02:00
video.c: working version, with screen grabber
This commit is contained in:
parent
b85ae15479
commit
18f2957cd4
@ -56,6 +56,9 @@
|
||||
#define DEFAULT_COUNT (1000*1000)
|
||||
|
||||
|
||||
static uint8_t thres = 63;
|
||||
|
||||
|
||||
/* ----- Ben hardware ------------------------------------------------------ */
|
||||
|
||||
|
||||
@ -127,23 +130,32 @@ static void release_timer(void)
|
||||
}
|
||||
|
||||
|
||||
static void ben_setup(void)
|
||||
static void *map(off_t addr, size_t size)
|
||||
{
|
||||
volatile void *base;
|
||||
int fd;
|
||||
void *mem;
|
||||
|
||||
fd = open("/dev/mem", O_RDWR | O_SYNC);
|
||||
if (fd < 0) {
|
||||
perror("/dev/mem");
|
||||
exit(1);
|
||||
}
|
||||
base = mmap(NULL, PAGE_SIZE*3*16, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
fd, SOC_BASE);
|
||||
if (base == MAP_FAILED) {
|
||||
mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr);
|
||||
if (mem == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
|
||||
static void ben_setup(void)
|
||||
{
|
||||
volatile void *base;
|
||||
|
||||
base = map(SOC_BASE, PAGE_SIZE*3*16);
|
||||
|
||||
icmr = base+0x1004;
|
||||
icmsr = base+0x1008;
|
||||
icmcr = base+0x100c;
|
||||
@ -201,10 +213,9 @@ static uint32_t pick(int set, int bit, uint32_t val)
|
||||
}
|
||||
|
||||
|
||||
static uint32_t pattern(int r, int g, int b, int hsync, int vsync, int set)
|
||||
static uint32_t pattern(int set, int r, int g, int b)
|
||||
{
|
||||
return pick(set, r, R) | pick(set, g, G) | pick(set, b, B) |
|
||||
pick(set, hsync, HSYNC) | pick(set, vsync, VSYNC);
|
||||
return pick(set, r, R) | pick(set, g, G) | pick(set, b, B);
|
||||
}
|
||||
|
||||
|
||||
@ -360,13 +371,31 @@ static void grid(uint8_t *f)
|
||||
}
|
||||
|
||||
|
||||
static void grab(uint8_t *f)
|
||||
{
|
||||
uint32_t *fb = map(0x01d00000, 4*320*240);
|
||||
int x, y;
|
||||
uint32_t pix;
|
||||
|
||||
for (y = 0; y != 240; y++)
|
||||
for (x = 0; x != 320; x++) {
|
||||
pix = *fb++;
|
||||
*f++ = pattern(!(x & 1),
|
||||
((pix >> 16) & 255) >= thres,
|
||||
((pix >> 8) & 255) >= thres,
|
||||
(pix & 255) >= thres);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void session(int n)
|
||||
{
|
||||
uint8_t f[320*(240+1)];
|
||||
int i;
|
||||
|
||||
memset(f, 0, sizeof(f));
|
||||
grid(f);
|
||||
grab(f);
|
||||
// grid(f);
|
||||
|
||||
disable_interrupts();
|
||||
|
||||
@ -379,6 +408,7 @@ static void session(int n)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
thres = atoi(argv[2]);
|
||||
setup();
|
||||
session(atoi(argv[1]));
|
||||
cleanup();
|
||||
|
Loading…
Reference in New Issue
Block a user