mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 22:42:49 +02:00
ubb-vga.c: a bit more cleanup
- ubb-vga.c: added more section titles - ubb-vga.c (pick, pattern): grouped pixel-generating functions with image generation - ubb-vga.c (usage, main): properly parse command-line options ("getopt" is a bit of overkill at the moment but will be needed later)
This commit is contained in:
parent
554c6645d8
commit
dae21696b3
@ -226,7 +226,7 @@ static void until(uint16_t cycles)
|
||||
}
|
||||
|
||||
|
||||
/* ----- Interface --------------------------------------------------------- */
|
||||
/* ----- Frame buffer output ----------------------------------------------- */
|
||||
|
||||
|
||||
void setup(void)
|
||||
@ -237,18 +237,6 @@ void setup(void)
|
||||
}
|
||||
|
||||
|
||||
static uint32_t pick(int set, int bit, uint32_t val)
|
||||
{
|
||||
return set == bit ? val >> 8 : 0;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void line(const uint8_t *line, const uint8_t *fetch)
|
||||
{
|
||||
const uint8_t *p = line;
|
||||
@ -317,6 +305,21 @@ static void frame(const uint8_t *f)
|
||||
}
|
||||
|
||||
|
||||
/* ----- Frame buffer image generation ------------------------------------- */
|
||||
|
||||
|
||||
static uint32_t pick(int set, int bit, uint32_t val)
|
||||
{
|
||||
return set == bit ? val >> 8 : 0;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void tricolor(uint32_t *f)
|
||||
{
|
||||
int i;
|
||||
@ -377,7 +380,10 @@ static void grab(uint8_t *f)
|
||||
}
|
||||
|
||||
|
||||
static void session(int n)
|
||||
/* ----- Command-line parsing and main loop -------------------------------- */
|
||||
|
||||
|
||||
static void session(int frames)
|
||||
{
|
||||
uint8_t f[320*(240+1)];
|
||||
int i;
|
||||
@ -388,18 +394,45 @@ static void session(int n)
|
||||
|
||||
disable_interrupts();
|
||||
|
||||
for (i = 0; i != n; i++)
|
||||
for (i = 0; i != frames; i++)
|
||||
frame(f);
|
||||
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
static void usage(const char *name)
|
||||
{
|
||||
thres = atoi(argv[2]);
|
||||
fprintf(stderr, "usage: %s frames [threshold]\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
int frames;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "")) != EOF)
|
||||
switch (c) {
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
switch (argc-optind) {
|
||||
case 2:
|
||||
thres = atoi(argv[optind+1]);
|
||||
/* fall through */
|
||||
case 1:
|
||||
frames = atoi(argv[optind]);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
setup();
|
||||
session(atoi(argv[1]));
|
||||
session(frames);
|
||||
cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user