Sample argument parser inproved.

This commit is contained in:
Kai Lauterbach 2011-12-31 18:24:05 +01:00
parent 779e522e33
commit 3e746efaab
3 changed files with 43 additions and 11 deletions

View file

@ -23,7 +23,7 @@
// External functions to control the ledcube. // External functions to control the ledcube.
extern void lc_setFrame(unsigned long); extern void lc_setFrame(unsigned long);
extern void lc_setMode(int); extern void lc_setMode(int);
extern void lc_saveFrame(unsigned long, int); extern int lc_saveFrame(unsigned long, int, int);
extern void lc_init(void); extern void lc_init(void);
extern void lc_close(void); extern void lc_close(void);
@ -32,17 +32,47 @@ int main(int argc, char **argv)
lc_init(); lc_init();
//lc_close();
//return 0;
if (argc == 2 && !strcmp((char*)argv[1], "--stop"))
{
printf("stop animation loop\n");
lc_setMode(MODE_ANIMATION_STOP);
}
else if (argc == 2 && !strcmp((char*)argv[1], "--loop"))
{
printf("starting animation loop\n");
lc_setMode(MODE_ANIMATION_LOOP);
}
else if (argc == 5 && !strcmp((char*)argv[1], "--save"))
{
lc_setMode(MODE_ANIMATION_STOP); lc_setMode(MODE_ANIMATION_STOP);
/*printf(">>> %s <<<\n", argv[1]);
printf(">>> %s <<<\n", argv[2]);
printf(">>> %s <<<\n", argv[3]);*/
// TODO parse commandline parameters // TODO parse commandline parameters
unsigned int frame = 0; unsigned int pos = 0;
if ( sscanf((char*)argv[1], "0x%08x", &frame) ) if ( sscanf((char*)argv[2], "%d", &pos) )
{ {
printf("0x%08x\n", frame); unsigned int delay = 0;
lc_setFrame(frame); if ( sscanf((char*)argv[3], "%d", &delay) )
{
unsigned int frame = 0;
if ( sscanf((char*)argv[4], "0x%08x", &frame) )
{
printf("saving frame: index=%d delay=%d frame=0x%08x\n", pos, delay, frame);
//lc_setFrame(frame);
lc_saveFrame(frame, delay, pos);
}
}
}
} }
//lc_setMode(MODE_ANIMATION_LOOP);
lc_close(); lc_close();
return 0; return 0;

View file

@ -12,6 +12,7 @@
#define MODE_ANIMATION_SINGLE 1 #define MODE_ANIMATION_SINGLE 1
#define MODE_ANIMATION_LOOP 2 #define MODE_ANIMATION_LOOP 2
// 32 * 4 byte (32bit unsigned integer) = 128 byte eeprom
#define MAX_EEPROM_FRAMES 32 #define MAX_EEPROM_FRAMES 32
#ifndef EEMEM #ifndef EEMEM

View file

@ -79,8 +79,9 @@ for (my $i=0; $i<=$#ARGV; $i++)
printf("0b%032b\n", $frame); printf("0b%032b\n", $frame);
my $tmp = ""; my $tmp = "";
$tmp = sprintf("0x%08x", $frame); $tmp = sprintf("0x%08x", $frame);
system("../client/clcc $tmp"); system("../client/clcc --save $i ". ($frame >> 27)." $tmp");
#print("../client/clcc $tmp\n"); #print("../client/clcc --save $i ". ($frame >> 27)." $tmp\n");
usleep(250000); #usleep(250000);
sleep 1;
} }