From b814761438a2ecabbc4a244873473e1e2ee846b7 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 14:53:13 +0200 Subject: [PATCH 01/35] All LEDs default to off now --- firmware/basic/basic.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/firmware/basic/basic.c b/firmware/basic/basic.c index 749547b..f0deb7d 100644 --- a/firmware/basic/basic.c +++ b/firmware/basic/basic.c @@ -43,27 +43,20 @@ void rbInit() { IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO; gpioSetDir(RB_LED0, gpioDirection_Output); - gpioSetValue (RB_LED0, 1); + gpioSetValue (RB_LED0, 0); gpioSetDir(RB_LED1, gpioDirection_Output); - gpioSetValue (RB_LED1, 1); + gpioSetValue (RB_LED1, 0); gpioSetDir(RB_LED2, gpioDirection_Output); - gpioSetValue (RB_LED2, 1); + gpioSetValue (RB_LED2, 0); gpioSetDir(RB_LED3, gpioDirection_Output); - gpioSetValue (RB_LED3, 1); + gpioSetValue (RB_LED3, 0); + // Set LED3 to ? IOCON_PIO1_11 = 0x41; - // prepare IR - //gpioSetDir(RB_IROUT, gpioDirection_Output); - //gpioSetValue (RB_IROUT, 1); - - //gpioSetDir(RB_IRIN, gpioDirection_Input); - //gpioSetPullup (&RB_IRIN_IO, gpioPullupMode_PullUp); - - // prepare lcd // TODO FIXME more init needed ? gpioSetDir(RB_LCD_BL, gpioDirection_Output); @@ -127,16 +120,13 @@ void rbInit() { gpioSetPullup (&RB_BUSINT_IO, gpioPullupMode_PullUp); gpioSetInterrupt(RB_BUSINT, gpioInterruptSense_Edge, gpioInterruptEdge_Single, gpioInterruptEvent_ActiveLow); gpioIntEnable(RB_BUSINT); - // add this to catch interrupt: - /* - - */ //nrf_init(); backlightInit(); font=&Font_7x8; ECIES_setup(); } + #define WEAK_ALIAS(f) __attribute__ ((weak, alias (#f))); void interrupt_undefined(void) { } From 2e1f1a69d169fe1b808fbea46c1f8911cf3a104b Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 14:54:16 +0200 Subject: [PATCH 02/35] Mesh now turns message LED on on new message --- firmware/applications/final/mesh.c | 8 ++++++++ firmware/funk/mesh.c | 7 ++++++- firmware/funk/mesh.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c index ef3fa22..dceaffb 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -128,6 +128,9 @@ void m_choose(){ char list[99]; int i=0; + meshmsg=0; + gpioSetValue (RB_LED1, 0); + while(1){ char *p=list; strcpy(p,"Note"); @@ -231,5 +234,10 @@ void m_choose(){ void tick_mesh(void){ if(GLOBAL(privacy)<2) mesh_systick(); + if(_timectr%64) + if(meshmsg){ + gpioSetValue (RB_LED1, 1); + meshmsg=0; + }; }; diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index e15656d..ee64126 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -9,6 +9,7 @@ char meshgen=0; // Generation char meshincctr=0; +char meshmsg=0; MPKT meshbuffer[MESHBUFSIZE]; uint32_t const meshkey[4] = { @@ -124,9 +125,13 @@ void mesh_recvloop(void){ // only accept newer/better packets if(mpkt->flags==MF_USED) - if(MO_TIME(buf)pkt)) + if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) continue; + if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || + (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C')) + meshmsg=1; + memcpy(mpkt->pkt,buf,MESHPKTSIZE); mpkt->flags=MF_USED; diff --git a/firmware/funk/mesh.h b/firmware/funk/mesh.h index 2ff8f35..1fe069d 100644 --- a/firmware/funk/mesh.h +++ b/firmware/funk/mesh.h @@ -30,6 +30,7 @@ typedef struct { extern char meshgen; // Generation extern char meshincctr; // Time checker +extern char meshmsg; // Is there something interesting? extern MPKT meshbuffer[MESHBUFSIZE]; void initMesh(void); From ff2c8919615f1e53464afbd3c64cdfa75da3021f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 14:55:09 +0200 Subject: [PATCH 03/35] config cleanups --- firmware/applications/final/config.c | 12 ------------ firmware/basic/config.c | 2 ++ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c index 3761494..4002e10 100644 --- a/firmware/applications/final/config.c +++ b/firmware/applications/final/config.c @@ -13,18 +13,6 @@ /**************************************************************************/ -void readcfg(void) { - readConfig(); -}; - -void savecfg(void){ - saveConfig(); -}; - -void applycfg(void){ - applyConfig(); -}; - //# MENU config void changer(void){ uint8_t numentries = 0; diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 2533e06..cccb782 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -49,6 +49,8 @@ int saveConfig(void){ UINT allwrite=0; int res; + lcdClear(); + res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE); lcdPrint("create:"); lcdPrintln(f_get_rc_string(res)); From 323143d734362199cc74bb67544eadbf87c32a38 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 15:02:51 +0200 Subject: [PATCH 04/35] Support for develmode --- firmware/basic/config.c | 7 ++++--- firmware/basic/config.h | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index cccb782..cd26120 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -7,7 +7,7 @@ #include "basic/random.h" #include "basic/config.h" -#define CFGVER 1 +#define CFGVER 2 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER, 0, 0}, @@ -20,7 +20,8 @@ struct CDESC the_config[]= { {"lcdmirror", 0, 0, 1 , 0, 0}, {"lcdinvert", 0, 0, 1 , 0, 0}, {"lcdcontrast", 14, 0, 31 , 0, 0}, - {"alivechk", 0, 0, 2 , 0, 0}, + {"alivechk", 0, 0, 2 , 1, CFG_TYPE_DEVEL}, + {"develmode", 0, 0, 1 , 1, CFG_TYPE_DEVEL}, {"flamemax", 255, 0, 255, 1, CFG_TYPE_FLAME}, {"flamemin", 0, 0, 255, 1, CFG_TYPE_FLAME}, {"flamespeed", 1, 1, 100, 1, CFG_TYPE_FLAME}, @@ -40,7 +41,7 @@ char nickfont[FILENAMELEN]; void applyConfig(){ if(GLOBAL(lcdcontrast)>0) lcdSetContrast(GLOBAL(lcdcontrast)); - return; + enableConfig(CFG_TYPE_DEVEL,GLOBAL(develmode)); }; int saveConfig(void){ diff --git a/firmware/basic/config.h b/firmware/basic/config.h index 9654b38..106dc5b 100644 --- a/firmware/basic/config.h +++ b/firmware/basic/config.h @@ -34,11 +34,12 @@ extern char nickfont[]; #define GLOBALlcdinvert (the_config[ 7].value) #define GLOBALlcdcontrast (the_config[ 8].value) #define GLOBALalivechk (the_config[ 9].value) -#define GLOBALflamemax (the_config[10].value) -#define GLOBALflamemin (the_config[11].value) -#define GLOBALflamespeed (the_config[12].value) -#define GLOBALflamemaxw (the_config[13].value) -#define GLOBALflameminw (the_config[14].value) +#define GLOBALdevelmode (the_config[10].value) +#define GLOBALflamemax (the_config[11].value) +#define GLOBALflamemin (the_config[12].value) +#define GLOBALflamespeed (the_config[13].value) +#define GLOBALflamemaxw (the_config[14].value) +#define GLOBALflameminw (the_config[15].value) #define GLOBALnickname (nickname) #define GLOBALnickfont (nickfont) From 5452f6dd9de1323955c81da6ab9169cc0a859ae1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 15:24:49 +0200 Subject: [PATCH 05/35] Add camp-font.ttf --- tools/font/ttf/SOVIET4.TTF | Bin 0 -> 11228 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 tools/font/ttf/SOVIET4.TTF diff --git a/tools/font/ttf/SOVIET4.TTF b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ymy?&R z9^LF@i?Z6noqaV2KfYH}ZOiy^#hHy$2K;n!PGaP+GpBnOoo`w4zK`kti#30DV~SSi zACwl~P|dsJSy4ylZVZ?aV4AslntMvzJ4e!=IpH(ye$dR1O%qPby3e@W#&$3`yKeW% zxzV?y_XRf3AH8SyYpa%&b&IH+z3BB$J=%0!aO>5s1!0yKUVU+KapCYUKAX8=yt4P9 zPd~a7xZQow>ZN&=p6ScZ4J)~K^_%rYY1ej~{&mWfo4(7>PadE)RqxjIJ@k3x#D0UW z-Y+joY59J2_sGAViET}`;WK|K(CzWE Date: Thu, 4 Aug 2011 16:05:30 +0200 Subject: [PATCH 06/35] Fix config with disabled entries --- firmware/applications/final/config.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c index 4002e10..a3a0921 100644 --- a/firmware/applications/final/config.c +++ b/firmware/applications/final/config.c @@ -43,41 +43,37 @@ void changer(void){ lcdNl(); uint8_t j=0; - for (uint8_t i=0;i"); }; + lcdRefresh(); } lcdRefresh(); - j=menuselection; - int t=0; - while(j){ - if(!the_config[t].disabled) - j--; - t++; - } - switch (getInputWaitRepeat()) { case BTN_UP: menuselection--; From 13f544474552ecb3a83e6d98496cc8487e7f6081 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 16:29:13 +0200 Subject: [PATCH 07/35] option added for menus to show "JUSTONCE" --- firmware/basic/basic.h | 1 + firmware/basic/menu.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 0493eaa..008baef 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -180,6 +180,7 @@ struct MENU { }; #define MENU_TIMEOUT (1<<0) +#define MENU_JUSTONCE (1<<1) extern uint8_t menuflags; diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 97b0b60..3b9a76a 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -68,6 +68,10 @@ void handleMenu(const struct MENU *the_menu) { case BTN_RIGHT: if (the_menu->entries[menuselection].callback!=NULL) the_menu->entries[menuselection].callback(); + + if (menuflags&MENU_JUSTONCE) + return; + break; case BTN_ENTER: lcdClear(); @@ -77,6 +81,10 @@ void handleMenu(const struct MENU *the_menu) { if (the_menu->entries[menuselection].callback!=NULL) the_menu->entries[menuselection].callback(); lcdRefresh(); + + if (menuflags&MENU_JUSTONCE) + return; + getInputWait(); break; From a5c2ce55a6ac13d7873613194ce198e45535de20 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 16:34:56 +0200 Subject: [PATCH 08/35] 1boot alpha --- firmware/l0dable/1boot.c | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 firmware/l0dable/1boot.c diff --git a/firmware/l0dable/1boot.c b/firmware/l0dable/1boot.c new file mode 100644 index 0000000..cf8ce62 --- /dev/null +++ b/firmware/l0dable/1boot.c @@ -0,0 +1,53 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/print.h" +#include "usetable.h" + +static void set_privacy(); +static void privacy0(); +static void privacy1(); +static void privacy2(); + +static const char levels[][12] = {"0-trackable","1-mesh only","2-RF OFF"}; + +static const struct MENU submenu_privacy={ "Privacy?", { + { levels[0], &privacy0}, + { levels[1], &privacy1}, + { levels[2], &privacy2}, + {NULL,NULL} +}}; + +void ram(void){ + // check privacy + menuflags|=MENU_JUSTONCE; + if ((GLOBAL(privacy)!=3)) { //TODO Change! + handleMenu(&submenu_privacy); + } + + menuflags&= (~MENU_JUSTONCE); +}; + +static void privacy0() { + set_privacy(0); +} + +static void privacy1() { + set_privacy(1); +} + +static void privacy2() { + set_privacy(2); +} + +static void set_privacy(int level) { + lcdClear(); + lcdPrintln("Privacy:"); + lcdPrintln(levels[level]); + lcdRefresh(); + getInput(); + GLOBAL(privacy) = level; +} + From d69cf154a0c4a2d6c56a442c3c346fd3c0bb7222 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 16:38:50 +0200 Subject: [PATCH 09/35] Add life.c nickscroller. I hacked around quite a bit to get it small. --- firmware/l0dable/nick_life.c | 246 +++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 firmware/l0dable/nick_life.c diff --git a/firmware/l0dable/nick_life.c b/firmware/l0dable/nick_life.c new file mode 100644 index 0000000..9b042b3 --- /dev/null +++ b/firmware/l0dable/nick_life.c @@ -0,0 +1,246 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/display.h" + +#include "basic/config.h" + +#include "usetable.h" + +#define BITSET_X (RESX+2) +#define BITSET_Y (RESY+2) +#define BITSET_SIZE (BITSET_X*BITSET_Y) + +#define BITSETCHUNKSIZE 32 + +#define one ((uint32_t)1) + +struct bitset { + uint16_t size; + uint32_t bits[BITSET_SIZE/BITSETCHUNKSIZE+1]; +}; + + +typedef uint8_t uchar; + +int pattern=0; +#define PATTERNCOUNT 3 + +uchar stepmode=0; +uchar randdensity=0; +//uint8_t bl=0; + +struct bitset _buf1,*buf1=&_buf1; +struct bitset _buf2,*buf2=&_buf2; + +struct bitset *life =&_buf1; +struct bitset *new =&_buf2; + + +static void draw_area(); +static void calc_area(); +static void random_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value); +static void reset_area(); +static void nextledcycle(); + +void ram(void) { + getInputWaitRelease(); + reset_area(); + random_area(life,1,1,RESX,RESY,40); + + lcdClear(); + setExtFont(GLOBAL(nickfont)); + DoString(20,20,GLOBAL(nickname)); + +#if 0 + gpioSetValue (RB_LED0, CFG_LED_ON); + gpioSetValue (RB_LED1, CFG_LED_ON); + gpioSetValue (RB_LED2, CFG_LED_ON); + gpioSetValue (RB_LED3, CFG_LED_ON); +#endif + while (1) { + draw_area(); // xor life pattern over display content + lcdDisplay(); + draw_area(); // xor life pattern again to restore original display content + lcdShift(1,-2,1); + if(getInputRaw()) + return; + delayms_queue(10); + calc_area(); + } + return; +} + +static inline void bitset_set(struct bitset *bs,uint16_t index, uint8_t value) { + uint16_t base=index/BITSETCHUNKSIZE; + uint16_t offset=index%BITSETCHUNKSIZE; + if(value) { + bs->bits[base]|=(one<bits[base]&=~(one<bits[base]^=(one<bits[base]&(one<>24) Date: Thu, 4 Aug 2011 16:55:52 +0200 Subject: [PATCH 10/35] Sample nickname application --- firmware/l0dable/nick_plain.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 firmware/l0dable/nick_plain.c diff --git a/firmware/l0dable/nick_plain.c b/firmware/l0dable/nick_plain.c new file mode 100644 index 0000000..47821e2 --- /dev/null +++ b/firmware/l0dable/nick_plain.c @@ -0,0 +1,32 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "usetable.h" + +void ram(void) { + int dx=0; + int dy=0; + static uint32_t ctr=0; + ctr++; + + setExtFont(GLOBAL(nickfont)); + dx=DoString(0,0,GLOBAL(nickname)); + dx=(RESX-dx)/2; + if(dx<0) + dx=0; + dy=(RESY-getFontHeight())/2; + + lcdClear(); + DoString(dx,dy,GLOBAL(nickname)); + lcdRefresh(); + + while(getInputRaw()==BTN_NONE){ + work_queue(); + }; + return; +} From 16da194336ea8e5f44fc2de4ac3a1b37ac39a8cd Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 16:57:18 +0200 Subject: [PATCH 11/35] Support l0dable nickname display. --- firmware/applications/final/nickname.c | 27 ++++++++++++++++++++++++++ firmware/basic/config.c | 4 +++- firmware/basic/config.h | 5 ++++- firmware/filesystem/execute.c | 11 ++++++----- firmware/filesystem/execute.h | 2 +- firmware/l0dable/EXPORTS | 5 +++++ firmware/l0dable/Makefile | 4 ---- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/firmware/applications/final/nickname.c b/firmware/applications/final/nickname.c index 11cf4ed..2882293 100644 --- a/firmware/applications/final/nickname.c +++ b/firmware/applications/final/nickname.c @@ -16,7 +16,20 @@ /**************************************************************************/ +void simpleNickname(void); + void fancyNickname(void) { + if(GLOBAL(l0nick)){ + if(execute_file(GLOBAL(nickl0),0,0)) + GLOBAL(l0nick)=0; + } + + if(!GLOBAL(l0nick)) + simpleNickname(); + return; +} + +void simpleNickname(void) { int dx=0; int dy=0; static uint32_t ctr=0; @@ -44,6 +57,7 @@ void fancyNickname(void) { void init_nick(void){ readFile("nick.cfg",GLOBAL(nickname),MAXNICK); readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN); + readFile("l0nick.cfg",GLOBAL(nickl0),FILENAMELEN); }; //# MENU nick editNick @@ -71,3 +85,16 @@ void doFont(void){ setIntFont(&Font_7x8); while(!getInputRaw())delayms(10); }; + +//# MENU nick chooseAnim +void doAnim(void){ + getInputWaitRelease(); + if( selectFile(GLOBAL(nickl0),"NIK") != 0){ + lcdPrintln("No file selected."); + GLOBAL(l0nick)=0; + return; + }; + writeFile("l0nick.cfg",GLOBAL(nickl0),strlen(GLOBAL(nickl0))); + GLOBAL(l0nick)=1; + getInputWaitRelease(); +}; diff --git a/firmware/basic/config.c b/firmware/basic/config.c index cd26120..351015f 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -7,7 +7,7 @@ #include "basic/random.h" #include "basic/config.h" -#define CFGVER 2 +#define CFGVER 3 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER, 0, 0}, @@ -27,11 +27,13 @@ struct CDESC the_config[]= { {"flamespeed", 1, 1, 100, 1, CFG_TYPE_FLAME}, {"flamemaxw", 255, 1, 255, 1, CFG_TYPE_FLAME}, {"flameminw", 0x8f, 1, 255, 1, CFG_TYPE_FLAME}, + {"l0nick", 0, 0, 1 , 0, 0}, { NULL, 0, 0, 0 , 0, 0}, }; char nickname[MAXNICK]="anonymous"; char nickfont[FILENAMELEN]; +char nickl0[FILENAMELEN]; #define CONFFILE "r0ket.cfg" #define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++) diff --git a/firmware/basic/config.h b/firmware/basic/config.h index 106dc5b..f018fc2 100644 --- a/firmware/basic/config.h +++ b/firmware/basic/config.h @@ -21,8 +21,9 @@ struct CDESC { #define MAXNICK 20 extern struct CDESC the_config[]; -extern char nickname[MAXNICK]; +extern char nickname[]; extern char nickfont[]; +extern char nickl0[]; #define GLOBALversion (the_config[ 0].value) #define GLOBALprivacy (the_config[ 1].value) @@ -40,8 +41,10 @@ extern char nickfont[]; #define GLOBALflamespeed (the_config[13].value) #define GLOBALflamemaxw (the_config[14].value) #define GLOBALflameminw (the_config[15].value) +#define GLOBALl0nick (the_config[16].value) #define GLOBALnickname (nickname) #define GLOBALnickfont (nickfont) +#define GLOBALnickl0 (nickl0) #define GLOBAL(x) GLOBAL ## x diff --git a/firmware/filesystem/execute.c b/firmware/filesystem/execute.c index 3ae2a86..c50426c 100644 --- a/firmware/filesystem/execute.c +++ b/firmware/filesystem/execute.c @@ -20,7 +20,7 @@ extern void * sram_top; /**************************************************************************/ -void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ +uint8_t execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ FRESULT res; FIL file; UINT readbytes; @@ -38,7 +38,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ //lcdPrintln(f_get_rc_string(res)); //lcdRefresh(); if(res){ - return; + return -1; }; res = f_read(&file, (char *)dst, RAMCODE, &readbytes); @@ -46,7 +46,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ //lcdPrintln(f_get_rc_string(res)); //lcdRefresh(); if(res){ - return; + return -1; }; if( decode || checksignature ) //only accept files with fixed length @@ -55,7 +55,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ lcdPrint("readbytes&3"); lcdRefresh(); while(1); - return; + return -1; } if( checksignature ){ uint32_t mac[4]; @@ -72,7 +72,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ lcdPrintIntHex(mac[3]); lcdNl(); lcdRefresh(); while(1); - return; + return -1; } //lcdPrint("macok"); //lcdRefresh(); @@ -90,6 +90,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode! dst(); + return 0; }; diff --git a/firmware/filesystem/execute.h b/firmware/filesystem/execute.h index 8c52cae..4e2c654 100644 --- a/firmware/filesystem/execute.h +++ b/firmware/filesystem/execute.h @@ -1,7 +1,7 @@ #ifndef _EXECUTE_H_ #define _EXECUTE_H_ -void execute_file (const char * fname, uint8_t checksignature, uint8_t decode); +uint8_t execute_file (const char * fname, uint8_t checksignature, uint8_t decode); void executeSelect(char *ext); #endif diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index c8ddcd5..68ede56 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -72,3 +72,8 @@ nrf_check_reset sspSend sspReceive sspSendReceive +getInputWait +lcdGetPixel +nickfont +setExtFont +getFontHeight diff --git a/firmware/l0dable/Makefile b/firmware/l0dable/Makefile index 8da03dc..c97d8de 100644 --- a/firmware/l0dable/Makefile +++ b/firmware/l0dable/Makefile @@ -44,10 +44,6 @@ $(LDFILE): clean: rm -f *.o *.elf *.bin usetable.h -IDIR=/cygdrive/f -install: - for a in $(BINS) ; do f=$${a#*/};cp $$a $(IDIR)/$${f%.bin}.c0d ; done - $(OBJS): usetable.h usetable.h: From b933ebce4081a37618554df548a2f1f0feaa05d9 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 16:59:01 +0200 Subject: [PATCH 12/35] add menuflags export for iggy's 1boot --- firmware/l0dable/EXPORTS | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index 68ede56..b0d95e9 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -77,3 +77,4 @@ lcdGetPixel nickfont setExtFont getFontHeight +menuflags From 9da6d74f2eb063bd006e1450b07dda0fb99d3ab9 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 17:20:24 +0200 Subject: [PATCH 13/35] Use 1boot loadable for real --- firmware/applications/final.c | 16 ++++++++++++++++ firmware/l0dable/1boot.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/firmware/applications/final.c b/firmware/applications/final.c index cce4e3b..b46a770 100644 --- a/firmware/applications/final.c +++ b/firmware/applications/final.c @@ -8,6 +8,8 @@ #include "basic/ecc.h" +#include "basic/config.h" + /**************************************************************************/ #include "final.gen" @@ -16,6 +18,20 @@ void init_nick(); void fancyNickname(); void main_final(void) { + if(GLOBAL(privacy)>2){ //firstboot + if(execute_file("1boot.int",0,0)){ + lcdPrintln("Badge SETUP"); + lcdPrintln("error."); + lcdPrintln("Features may"); + lcdPrintln("be broken."); + lcdRefresh(); + getInputWait(); + getInputWaitRelease(); + GLOBAL(privacy)=0; + }else{ + saveConfig(); + }; + }; //checkFirstBoot(); init_final(); menuflags|=MENU_TIMEOUT; diff --git a/firmware/l0dable/1boot.c b/firmware/l0dable/1boot.c index cf8ce62..b45bc95 100644 --- a/firmware/l0dable/1boot.c +++ b/firmware/l0dable/1boot.c @@ -23,10 +23,7 @@ static const struct MENU submenu_privacy={ "Privacy?", { void ram(void){ // check privacy menuflags|=MENU_JUSTONCE; - if ((GLOBAL(privacy)!=3)) { //TODO Change! - handleMenu(&submenu_privacy); - } - + handleMenu(&submenu_privacy); menuflags&= (~MENU_JUSTONCE); }; From 0f533527635e7d9d1832b9b6953853f2da08503a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 17:52:38 +0200 Subject: [PATCH 14/35] Break receiving down. --- firmware/funk/mesh.c | 155 ++++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 70 deletions(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index ee64126..1a567f4 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -71,76 +71,6 @@ void mesh_cleanup(void){ }; }; -void mesh_recvloop(void){ - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - int recvend=M_RECVTIM/SYSTICKSPEED+getTimer(); - int pktctr=0; - - nrf_config_get(&oldconfig); - - nrf_set_channel(MESH_CHANNEL); - nrf_set_rx_mac(0,MESHPKTSIZE,strlen(MESH_MAC),(uint8_t*)MESH_MAC); - - mesh_cleanup(); - - nrf_rcv_pkt_start(); - do{ - len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,meshkey); - - // Receive - if(len<=0){ - delayms_power(10); - continue; - }; - pktctr++; - - if(MO_GEN(buf)>meshgen){ - if(meshgen) - meshgen++; - else - meshgen=MO_GEN(buf); - _timet=0; - meshincctr=0; - }; - - if(MO_TYPE(buf)=='T'){ - time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); - if (toff>_timet){ // Do not live in the past. - _timet = toff; - meshincctr++; - }; - continue; - }; - - // Safety: Truncate ascii packets by 0-ing the CRC - buf[MESHPKTSIZE-2]=0; - - // Store packet in a same/free slot - MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); - - // Skip locked packet - if(mpkt->flags&MF_LOCK) - continue; - - // only accept newer/better packets - if(mpkt->flags==MF_USED) - if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) - continue; - - if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || - (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C')) - meshmsg=1; - - memcpy(mpkt->pkt,buf,MESHPKTSIZE); - mpkt->flags=MF_USED; - - }while(getTimer()MESHBUFSIZE); - - nrf_rcv_pkt_end(); - nrf_config_set(&oldconfig); -} - void mesh_sendloop(void){ int ctr=0; __attribute__ ((aligned (4))) uint8_t buf[32]; @@ -168,6 +98,90 @@ void mesh_sendloop(void){ nrf_config_set(&oldconfig); }; +void mesh_recvqloop_setup(void){ + + nrf_config_get(&oldconfig); + + nrf_set_channel(MESH_CHANNEL); + nrf_set_rx_mac(0,MESHPKTSIZE,strlen(MESH_MAC),(uint8_t*)MESH_MAC); + + mesh_cleanup(); + + nrf_rcv_pkt_start(); +}; + +uint8_t mesh_recvqloop_work(void){ + __attribute__ ((aligned (4))) uint8_t buf[32]; + int len; + + len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,meshkey); + + // Receive + if(len<=0){ + return 0; + }; + + if(MO_GEN(buf)>meshgen){ + if(meshgen) + meshgen++; + else + meshgen=MO_GEN(buf); + _timet=0; + meshincctr=0; + }; + + if(MO_TYPE(buf)=='T'){ + time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); + if (toff>_timet){ // Do not live in the past. + _timet = toff; + meshincctr++; + }; + return 1; + }; + + // Safety: Truncate ascii packets by 0-ing the CRC + buf[MESHPKTSIZE-2]=0; + + // Store packet in a same/free slot + MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); + + // Skip locked packet + if(mpkt->flags&MF_LOCK) + return 1; + + // only accept newer/better packets + if(mpkt->flags==MF_USED) + if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) + return 1; + + if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || + (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C')) + meshmsg=1; + + memcpy(mpkt->pkt,buf,MESHPKTSIZE); + mpkt->flags=MF_USED; +}; + +void mesh_recvqloop_end(void){ + nrf_rcv_pkt_end(); + nrf_config_set(&oldconfig); +} + +void mesh_recvloop(void){ + int recvend=M_RECVTIM/SYSTICKSPEED+getTimer(); + int pktctr=0; + + mesh_recvqloop_setup(); + do{ + if( mesh_recvqloop_work() ){ + pktctr++; + }else{ + delayms_power(10); + }; + }while(getTimer()MESHBUFSIZE); + mesh_recvqloop_end(); +}; + void mesh_systick(void){ static int rcvctr=0; static int sendctr=0; @@ -184,3 +198,4 @@ void mesh_systick(void){ sendctr+=getRandom()%(sendctr*2); }; }; + From 5bcb504a1d61bb1f701436fb564f175077b2d503 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 17:57:59 +0200 Subject: [PATCH 15/35] tell me who you are. --- firmware/funk/mesh.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 1a567f4..2b73995 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -6,6 +6,7 @@ #include "funk/nrf24l01p.h" #include "basic/byteorder.h" #include "basic/random.h" +#include "basic/config.h" char meshgen=0; // Generation char meshincctr=0; @@ -83,6 +84,10 @@ void mesh_sendloop(void){ // Update [T]ime packet MO_TIME_set(meshbuffer[0].pkt,getSeconds()); MO_GEN_set(meshbuffer[0].pkt,meshgen); + if(GLOBAL(provacy)==0) + uint32touint8p(GetUUID32(),MO_BODY(meshbuffer[0].pkt)); + else + uint32touint8p(0,MO_BODY(meshbuffer[0].pkt)); for (int i=0;i Date: Thu, 4 Aug 2011 19:00:02 +0200 Subject: [PATCH 16/35] Fix stupidity. nrf needs to go in the queue --- firmware/applications/default.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 6b0c843..db93123 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -8,6 +8,7 @@ #include "filesystem/ff.h" #include "usb/usbmsc.h" #include "basic/random.h" +#include "funk/nrf24l01p.h" /**************************************************************************/ @@ -18,6 +19,9 @@ void main_default(void) { case BTN_ENTER: ISPandReset(); break; + case BTN_UP: // Reset config + f_unlink("r0ket.cfg"); + break; case BTN_DOWN: usbMSCInit(); while(1) @@ -84,7 +88,7 @@ void tick_default(void) { }; EVERY(4096,17){ - nrf_check_reset(); + push_queue(nrf_check_reset); }; return; }; From a41ca4d93d31ebd31ba2511d2c1091b672956cf2 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 19:10:22 +0200 Subject: [PATCH 17/35] queue_plus: allows for incremental queue stuff (nrf receive mostly) --- firmware/basic/basic.h | 7 +++ firmware/basic/idle.c | 92 ++++++++++++++++++++++++++--------- firmware/basic/idle.h | 16 +++++- firmware/funk/mesh.c | 36 ++++++++++++-- firmware/l0dable/EXPORTS | 1 + firmware/l0dable/nick_plain.c | 3 +- 6 files changed, 126 insertions(+), 29 deletions(-) diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 008baef..8d0bcc1 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -205,5 +205,12 @@ const char* IntToStr(int num, unsigned int mxlen, char flag); // global #define SYSTICKSPEED 10 +#ifdef __arm__ +#define WFI __asm volatile ("WFI") +#else +#define WFI delayms(SYSTICKSPEED) +#endif + + #endif diff --git a/firmware/basic/idle.c b/firmware/basic/idle.c index 623154b..9682675 100644 --- a/firmware/basic/idle.c +++ b/firmware/basic/idle.c @@ -13,36 +13,70 @@ extern uint32_t simTimeCounter(); /**************************************************************************/ -void work_queue(void){ - void (*elem)(void); + +uint8_t work_queue_minimal(void){ int start; if (the_queue.qstart == the_queue.qend){ -#ifdef __arm__ - __asm volatile ("WFI"); -#else - delayms(SYSTICKSPEED); -#endif - return; + return 0; }; start=the_queue.qstart; start=(start+1)%MAXQENTRIES; - elem=the_queue.queue[start].callback; - the_queue.qstart=start; + if(the_queue.queue[start].type == QT_NORMAL){ + void (*elem)(void); + elem=the_queue.queue[start].u.callback; + the_queue.qstart=start; + elem(); + return 0; + }else if(the_queue.queue[start].type == QT_PLUS){ + uint8_t (*elem)(uint8_t); + uint8_t state=the_queue.queue[start].state; + elem=the_queue.queue[start].u.callbackplus; + state=elem(state); + if(state==QS_END){ + the_queue.qstart=start; + return 0; + }else{ + the_queue.queue[start].state=state; + return 1; + }; + }; +}; - elem(); +void work_queue(void){ + int start; + + if (the_queue.qstart == the_queue.qend){ + WFI; + return; + }; + + while(work_queue_minimal()); +}; + + +uint8_t delayms_queue_plus(uint32_t ms, uint8_t final){ + int ret; + int end=_timectr+ms/SYSTICKSPEED; + do { + if (the_queue.qstart == the_queue.qend){ + WFI; + }else{ + ret=work_queue_minimal(); + }; + } while (end >_timectr); + if(ret && final){ + while(work_queue_minimal()); + }; + return ret; }; void delayms_queue(uint32_t ms){ int end=_timectr+ms/SYSTICKSPEED; do { if (the_queue.qstart == the_queue.qend){ -#ifdef __arm__ - __asm volatile ("WFI"); -#else - delayms(SYSTICKSPEED); -#endif + WFI; }else{ work_queue(); }; @@ -53,11 +87,7 @@ void delayms_power(uint32_t ms){ ms/=SYSTICKSPEED; ms+=_timectr; do { -#ifdef __arm__ - __asm volatile ("WFI"); -#else - delayms(SYSTICKSPEED); -#endif + WFI; } while (ms >_timectr); }; @@ -70,7 +100,25 @@ int push_queue(void (*new)(void)){ if(end == the_queue.qstart) // Queue full return -1; - the_queue.queue[end].callback=new; + the_queue.queue[end].u.callback=new; + the_queue.queue[end].type=QT_NORMAL; + the_queue.qend=end; + + return 0; +}; + +int push_queue_plus(uint8_t (*new)(uint8_t)){ + int end; + + end=the_queue.qend; + end=(end+1)%MAXQENTRIES; + + if(end == the_queue.qstart) // Queue full + return -1; + + the_queue.queue[end].u.callbackplus=new; + the_queue.queue[end].type=QT_PLUS; + the_queue.queue[end].state=QS_START; the_queue.qend=end; return 0; diff --git a/firmware/basic/idle.h b/firmware/basic/idle.h index 8e406a8..5d73dac 100644 --- a/firmware/basic/idle.h +++ b/firmware/basic/idle.h @@ -3,8 +3,18 @@ #define MAXQENTRIES 8 +#define QT_NORMAL 0 +#define QT_PLUS 1 +#define QS_START 0x0 +#define QS_END 0x7f + typedef struct { - void (*callback)(void); + union { + void (*callback)(void); + uint8_t (*callbackplus)(uint8_t); + } u; + unsigned type :1; + unsigned state :7; } QENTRY; typedef struct { @@ -17,10 +27,12 @@ extern QUEUE the_queue; extern volatile uint32_t _timectr; void work_queue(void); +uint8_t work_queue_minimal(void); void delayms_queue(uint32_t); +uint8_t delayms_queue_plus(uint32_t, uint8_t); void delayms_power(uint32_t); int push_queue(void (*qnew)(void)); -int magic(void *qnew); +int push_queue_plus(uint8_t (*qnew)(uint8_t)); // Note: // Our time implementation will fail after 497 days of continous uptime. diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 2b73995..6ff2c27 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -84,7 +84,7 @@ void mesh_sendloop(void){ // Update [T]ime packet MO_TIME_set(meshbuffer[0].pkt,getSeconds()); MO_GEN_set(meshbuffer[0].pkt,meshgen); - if(GLOBAL(provacy)==0) + if(GLOBAL(privacy)==0) uint32touint8p(GetUUID32(),MO_BODY(meshbuffer[0].pkt)); else uint32touint8p(0,MO_BODY(meshbuffer[0].pkt)); @@ -152,12 +152,12 @@ uint8_t mesh_recvqloop_work(void){ // Skip locked packet if(mpkt->flags&MF_LOCK) - return 1; + return 2; // only accept newer/better packets if(mpkt->flags==MF_USED) if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) - return 1; + return 2; if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C')) @@ -165,6 +165,7 @@ uint8_t mesh_recvqloop_work(void){ memcpy(mpkt->pkt,buf,MESHPKTSIZE); mpkt->flags=MF_USED; + return 1; }; void mesh_recvqloop_end(void){ @@ -187,12 +188,39 @@ void mesh_recvloop(void){ mesh_recvqloop_end(); }; +uint8_t mesh_recvloop_plus(uint8_t state){ + static int recvend=0; + static int pktctr=0; + + if (state==0){ + recvend=M_RECVTIM/SYSTICKSPEED+getTimer(); + pktctr=0; + + mesh_recvqloop_setup(); + state=1; + }; + if(state==1){ + if( mesh_recvqloop_work() ){ + pktctr++; + }else{ + delayms_power(10); + }; + if(getTimer()>recvend || pktctr>MESHBUFSIZE) + state=0xff; + }; + if(state==0xff){ + return 0xff; + }; + + return state; +}; + void mesh_systick(void){ static int rcvctr=0; static int sendctr=0; if(rcvctr--<0){ - push_queue(&mesh_recvloop); + push_queue_plus(&mesh_recvloop_plus); rcvctr=M_RECVINT/SYSTICKSPEED/2; rcvctr+=getRandom()%(rcvctr*2); }; diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index b0d95e9..7242605 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -78,3 +78,4 @@ nickfont setExtFont getFontHeight menuflags +delayms_queue_plus diff --git a/firmware/l0dable/nick_plain.c b/firmware/l0dable/nick_plain.c index 47821e2..5a24671 100644 --- a/firmware/l0dable/nick_plain.c +++ b/firmware/l0dable/nick_plain.c @@ -22,11 +22,12 @@ void ram(void) { dy=(RESY-getFontHeight())/2; lcdClear(); + lcdSetPixel(1,1,1); DoString(dx,dy,GLOBAL(nickname)); lcdRefresh(); while(getInputRaw()==BTN_NONE){ - work_queue(); + delayms_queue_plus(10,0); }; return; } From ccc8ce1395286031bc79f56e1e5c5379a2b0019d Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 20:11:12 +0200 Subject: [PATCH 18/35] more queue handling in invaders --- firmware/l0dable/invaders.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/firmware/l0dable/invaders.c b/firmware/l0dable/invaders.c index 8fef54c..9a08d01 100644 --- a/firmware/l0dable/invaders.c +++ b/firmware/l0dable/invaders.c @@ -136,13 +136,12 @@ void screen_gameover() { while(key==0) { lcdFill(0); font = &Font_7x8; - DoString (12,32, "GAME OVER"); + DoString (14,32, "GAME OVER"); DoInt (0,0, game.score); if (highscore_set(game.score, GLOBAL(nickname))) DoString (0,9,"HIGHSCORE!"); lcdDisplay(); - delayms_queue(50); - key=getInput(); + key=getInputWaitTimeout(5); } } @@ -153,7 +152,7 @@ void screen_level() { int dx = DoString(20,32, "Level "); DoInt(dx,32,game.level); lcdDisplay(); - delayms(500); + delayms_queue(500); } bool highscore_set(uint32_t score, char nick[]) { @@ -163,7 +162,6 @@ bool highscore_set(uint32_t score, char nick[]) { MO_TIME_set(mpkt->pkt,score); strcpy((char*)MO_BODY(mpkt->pkt),nick); - return true; } @@ -474,7 +472,7 @@ void draw_score() { void check_end() { if (game.killed) { game.rokets--; - delayms(500); + delayms_queue(500); game.player = POS_PLAYER_X; for(int col=0; col Date: Thu, 4 Aug 2011 20:23:14 +0200 Subject: [PATCH 19/35] fix time packet display --- firmware/applications/final/mesh.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c index dceaffb..20593fd 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -210,6 +210,7 @@ void m_choose(){ lcdPrint("."); lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS)); lcdNl(); + MO_BODY(meshbuffer[j].pkt)[0]=0; }; }; char *foo=(char *)MO_BODY(meshbuffer[j].pkt); From c8310c23d5e985a1f75d5b10ee4062356c19441d Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 20:24:45 +0200 Subject: [PATCH 20/35] use new queue stuff to run smoother --- firmware/l0dable/nick_life.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/l0dable/nick_life.c b/firmware/l0dable/nick_life.c index 9b042b3..b4d1382 100644 --- a/firmware/l0dable/nick_life.c +++ b/firmware/l0dable/nick_life.c @@ -67,7 +67,7 @@ void ram(void) { lcdShift(1,-2,1); if(getInputRaw()) return; - delayms_queue(10); + delayms_queue_plus(10,0); calc_area(); } return; From b844a2b1a10b799d0318eb19c9b3d441097b5f38 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 20:37:02 +0200 Subject: [PATCH 21/35] invaders can exit, size reduction with static fkts --- firmware/l0dable/EXPORTS | 1 + firmware/l0dable/invaders.c | 106 ++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index 7242605..bb474bb 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -79,3 +79,4 @@ setExtFont getFontHeight menuflags delayms_queue_plus +getInputWaitTimeout diff --git a/firmware/l0dable/invaders.c b/firmware/l0dable/invaders.c index 9a08d01..c2f6062 100644 --- a/firmware/l0dable/invaders.c +++ b/firmware/l0dable/invaders.c @@ -52,33 +52,33 @@ struct gamestate { uint8_t bunker[BUNKERS][BUNKER_WIDTH]; } game; char key; -bool highscore_set(uint32_t score, char nick[]); -uint32_t highscore_get(char nick[]); -void init_game(); -void init_enemy(); -void check_end(); -void move_ufo(); -void move_shot(); -void move_shots(); -void move_player(); -void move_enemy(); -void draw_score(); -void draw_bunker(); -void draw_player(); -void draw_enemy(); -void draw_shots(); -void draw_sprite(char type, char x, char y); -void draw_ufo(); -void screen_intro(); -void screen_gameover(); -void screen_level(); -bool check_bunker(char xpos, char ypos, int8_t shift); +static bool highscore_set(uint32_t score, char nick[]); +static uint32_t highscore_get(char nick[]); +static void init_game(); +static void init_enemy(); +static void check_end(); +static void move_ufo(); +static void move_shot(); +static void move_shots(); +static void move_player(); +static void move_enemy(); +static void draw_score(); +static void draw_bunker(); +static void draw_player(); +static void draw_enemy(); +static void draw_shots(); +static void draw_sprite(char type, char x, char y); +static void draw_ufo(); +static bool screen_intro(); +static bool screen_gameover(); +static void screen_level(); +static bool check_bunker(char xpos, char ypos, int8_t shift); void ram(void) { - //gpioSetValue (RB_LED1, CFG_LED_OFF); - //backlightInit(); - while(1) { + while(1) { + if (!screen_intro()) + return; screen_intro(); game.rokets = 3; game.level = 1; @@ -104,19 +104,20 @@ void ram(void) { lcdDisplay(); delayms(12); } - screen_gameover(); + if (!screen_gameover()) + return; } - return; } -void screen_intro() { +static bool screen_intro() { uint32_t highscore; char highnick[20]; char key=0; + bool step = false; while(key==0) { lcdFill(0); font = &Font_Invaders; - DoString(28,25,"ABC"); + DoString(28,25,step?"ABC":"abc"); font = &Font_7x8; DoString (28,40,"SPACE"); DoString (18,50,"INVADERS"); @@ -125,13 +126,13 @@ void screen_intro() { DoInt(0, 0, highscore); DoString (0, 9, highnick); lcdDisplay(); - - delayms_queue(50); - key=getInput(); + step = !step; + key=getInputWaitTimeout(1); } + return !(key==BTN_LEFT); } -void screen_gameover() { +static bool screen_gameover() { char key =0; while(key==0) { lcdFill(0); @@ -143,9 +144,10 @@ void screen_gameover() { lcdDisplay(); key=getInputWaitTimeout(5); } + return !(key==BTN_LEFT); } -void screen_level() { +static void screen_level() { lcdFill(0); draw_score(); font = &Font_7x8; @@ -155,7 +157,7 @@ void screen_level() { delayms_queue(500); } -bool highscore_set(uint32_t score, char nick[]) { +static bool highscore_set(uint32_t score, char nick[]) { MPKT * mpkt= meshGetMessage('i'); if(MO_TIME(mpkt->pkt)>score) return false; @@ -165,7 +167,7 @@ bool highscore_set(uint32_t score, char nick[]) { return true; } -uint32_t highscore_get(char nick[]){ +static uint32_t highscore_get(char nick[]){ MPKT * mpkt= meshGetMessage('i'); strcpy(nick,(char*)MO_BODY(mpkt->pkt)); @@ -173,7 +175,7 @@ uint32_t highscore_get(char nick[]){ return MO_TIME(mpkt->pkt); } -void init_game(void) { +static void init_game(void) { game.player = POS_PLAYER_X; game.shot_x = DISABLED; game.shot_y = 0; @@ -212,7 +214,7 @@ void init_game(void) { } } -void init_enemy() { +static void init_enemy() { for (int row = 0; rowBUNKER_X[BUNKERS-1-b] && xpos 0 ){ game.player-=1; } @@ -352,7 +354,7 @@ void move_player() { } } -void move_enemy() { +static void move_enemy() { if(game.move > 0){ game.move-=game.level/5+1; return; @@ -390,16 +392,16 @@ void move_enemy() { game.move = game.alive*2-1; } -void draw_player() { +static void draw_player() { draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); } -void draw_ufo() { +static void draw_ufo() { if (game.ufo!=DISABLED) draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y); } -void draw_enemy() { +static void draw_enemy() { for (int row = 0; row Date: Thu, 4 Aug 2011 21:23:29 +0200 Subject: [PATCH 22/35] more functions --- firmware/l0dable/EXPORTS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index bb474bb..71606f6 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -80,3 +80,5 @@ getFontHeight menuflags delayms_queue_plus getInputWaitTimeout +readFile +writeFile From 8f002a719b43074fcfdd93860182313859f0cee2 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 21:38:48 +0200 Subject: [PATCH 23/35] 1boot improved --- firmware/l0dable/1boot.c | 62 +++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/firmware/l0dable/1boot.c b/firmware/l0dable/1boot.c index b45bc95..13ad373 100644 --- a/firmware/l0dable/1boot.c +++ b/firmware/l0dable/1boot.c @@ -6,13 +6,14 @@ #include "lcd/print.h" #include "usetable.h" -static void set_privacy(); +static void screen_intro(); +static void set_privacy(int level); static void privacy0(); static void privacy1(); static void privacy2(); - +static bool screen_overview(); static const char levels[][12] = {"0-trackable","1-mesh only","2-RF OFF"}; - +bool privacy_set; static const struct MENU submenu_privacy={ "Privacy?", { { levels[0], &privacy0}, { levels[1], &privacy1}, @@ -20,11 +21,24 @@ static const struct MENU submenu_privacy={ "Privacy?", { {NULL,NULL} }}; + + void ram(void){ - // check privacy + bool again = true; menuflags|=MENU_JUSTONCE; - handleMenu(&submenu_privacy); + screen_intro(); + while (again) { + privacy_set = false; + while (!privacy_set) { + handleMenu(&submenu_privacy); + } + input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1); + getInputWaitRelease(); + again = screen_overview(); + } menuflags&= (~MENU_JUSTONCE); + writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); + saveConfig(); }; static void privacy0() { @@ -40,11 +54,39 @@ static void privacy2() { } static void set_privacy(int level) { - lcdClear(); - lcdPrintln("Privacy:"); - lcdPrintln(levels[level]); - lcdRefresh(); - getInput(); GLOBAL(privacy) = level; + privacy_set = true; +} + +static void screen_intro() { + lcdClear(); + lcdPrintln("Welcome to"); + lcdPrintln("r0ket"); + lcdRefresh(); + getInputWait(); + getInputWaitRelease(); +} + +static bool screen_overview() { + char key = 0; + while (key != BTN_ENTER) { + lcdClear(); + lcdPrintln("Privacy:"); + lcdPrintln(levels[GLOBAL(privacy)]); + lcdPrintln(""); + lcdPrintln("Nickname:"); + lcdPrintln(GLOBAL(nickname)); + lcdPrintln(""); + lcdPrintln("LEFT: cancel"); + lcdPrintln("ENTER: OK"); + lcdRefresh(); + key = getInputWait(); + if (key == BTN_LEFT) { + //getInputWaitRelease(); + return true; + } + } + + return false; } From 639fe12fb649ae0ea7ce0c9d1d3481acde5f3ceb Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 21:41:51 +0200 Subject: [PATCH 24/35] Double-space menu option for iggy --- firmware/basic/basic.h | 3 ++- firmware/basic/menu.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 8d0bcc1..ac0734a 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -179,8 +179,9 @@ struct MENU { struct MENU_DEF entries[]; }; -#define MENU_TIMEOUT (1<<0) +#define MENU_TIMEOUT (1<<0) #define MENU_JUSTONCE (1<<1) +#define MENU_BIG (1<<2) extern uint8_t menuflags; diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 3b9a76a..b4824f0 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -22,6 +22,10 @@ void handleMenu(const struct MENU *the_menu) { for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++); visible_lines = lcdGetVisibleLines()-1; // subtract title line + + if(menuflags&MENU_BIG) + visible_lines/=2; + #ifdef SAFETY if (visible_lines < 2) return; #endif @@ -32,6 +36,8 @@ void handleMenu(const struct MENU *the_menu) { lcdPrintln(the_menu->title); for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { + if(menuflags&MENU_BIG) + lcdNl(); if (i == menuselection) { lcdPrint("*"); } From 8537ef4b3d86084941d2d62740e0624e4744094c Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 21:46:28 +0200 Subject: [PATCH 25/35] 1boot bigmenu --- firmware/l0dable/1boot.c | 4 ++-- firmware/l0dable/EXPORTS | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/firmware/l0dable/1boot.c b/firmware/l0dable/1boot.c index 13ad373..3b57a42 100644 --- a/firmware/l0dable/1boot.c +++ b/firmware/l0dable/1boot.c @@ -25,7 +25,7 @@ static const struct MENU submenu_privacy={ "Privacy?", { void ram(void){ bool again = true; - menuflags|=MENU_JUSTONCE; + menuflags|=(MENU_JUSTONCE|MENU_BIG); screen_intro(); while (again) { privacy_set = false; @@ -36,7 +36,7 @@ void ram(void){ getInputWaitRelease(); again = screen_overview(); } - menuflags&= (~MENU_JUSTONCE); + menuflags&= (~(MENU_JUSTONCE|MENU_BIG)); writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); saveConfig(); }; diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index 71606f6..b3a3e8d 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -82,3 +82,5 @@ delayms_queue_plus getInputWaitTimeout readFile writeFile +input +saveConfig From a875cd62ff0638897c05ef0aefd6718ebca6e4a1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 21:49:33 +0200 Subject: [PATCH 26/35] add pwgen from mazzoo --- firmware/l0dable/pwgen.c | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 firmware/l0dable/pwgen.c diff --git a/firmware/l0dable/pwgen.c b/firmware/l0dable/pwgen.c new file mode 100644 index 0000000..81575ef --- /dev/null +++ b/firmware/l0dable/pwgen.c @@ -0,0 +1,55 @@ +#include "basic/basic.h" + +#include "usetable.h" + +#define PW_LEN 8 + +void ram(void) +{ + char pw[PW_LEN+1]; + uint16_t k[8]; + int button; + memset(k, 0, 16); + while(1){ + lcdClear(); + lcdNl(); + lcdPrintln(" password"); + lcdPrintln(" generator"); + lcdNl(); + lcdNl(); + pw_set(pw,&k); + pw_cleanup(pw); + lcdPrint(" "); + lcdPrintln(pw); + lcdRefresh(); + delayms(23); + while((button=getInputRaw())==BTN_NONE) + delayms(23); + if(button==BTN_LEFT) return; + } +} + +void pw_cleanup(char * pw) +{ + int i; + for(i=0;i0x7a)pw[i]-=0x10; + if((pw[i]>'Z')&&(pw[i]<'a')) + pw[i]-=0x10; + } +} + +void pw_set(char * pw, uint16_t * k) +{ + int i; + memset(pw,0,PW_LEN); /* wipe old PW */ + for(i=0;i<4;i++) + k[1]=getRandom(); + xxtea_encode_words(pw,PW_LEN/4,k); + pw[PW_LEN]=0; +} + From 728132920601f14e956ff32eaf442c002071b1d6 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 21:58:33 +0200 Subject: [PATCH 27/35] Fix pointer bug. Shouldn't 've worked before --- firmware/l0dable/pwgen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firmware/l0dable/pwgen.c b/firmware/l0dable/pwgen.c index 81575ef..329f6c5 100644 --- a/firmware/l0dable/pwgen.c +++ b/firmware/l0dable/pwgen.c @@ -4,6 +4,9 @@ #define PW_LEN 8 +void pw_cleanup(char * pw); +void pw_set(char * pw, uint16_t * k); + void ram(void) { char pw[PW_LEN+1]; @@ -17,7 +20,7 @@ void ram(void) lcdPrintln(" generator"); lcdNl(); lcdNl(); - pw_set(pw,&k); + pw_set(pw,k); pw_cleanup(pw); lcdPrint(" "); lcdPrintln(pw); From efed5bb6f4eaa4caa1a5d97adeb2f2d1652b6e20 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 22:52:44 +0200 Subject: [PATCH 28/35] boot screen --- tools/image/r0ket96x68.gif | Bin 0 -> 362 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tools/image/r0ket96x68.gif diff --git a/tools/image/r0ket96x68.gif b/tools/image/r0ket96x68.gif new file mode 100644 index 0000000000000000000000000000000000000000..0b043a98bfeb8ca047e19a1ded22d8b9a47fbdf8 GIT binary patch literal 362 zcmV-w0hRtoNk%w1VPF760HFW?00030|Nj6000000A^8LW3IGBCEC2ui0AK(_00091 zjE||y?GK}zwAzca-n={Dg(3ui<%p)Gd8Tf+2JuT@D`?#H9^JUC;|UeMUvY@c`3}dV zuxM;LY0#*2s=5M~*sQkNMQIV^u%-!B2F)C96~|?7g74N^j-l7>GrVoK$JgR#p|_{@ zLr4J_D5zK{7^wDG!Pq!SIbkWem8rS;hUh6_SSLD4Qku3kh}z(0%9`l9fCeTzOPjFD zTc(S6x4ZgVd&^`@OoWWvmn=LC9PE5N96DWGy?hKf9(|#oV4!Ul8j~J|c0|WLWh%kmPSG^RfGRQEEJ% literal 0 HcmV?d00001 From 23eb8775013fffca0791538656d4920b4a2e0636 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 22:58:36 +0200 Subject: [PATCH 29/35] Simple image converter and sample image --- tools/image/img2lcd.pl | 72 ++++++++++++++++++++++++++++++++++++++++ tools/image/src/i42.gif | Bin 0 -> 340 bytes 2 files changed, 72 insertions(+) create mode 100755 tools/image/img2lcd.pl create mode 100755 tools/image/src/i42.gif diff --git a/tools/image/img2lcd.pl b/tools/image/img2lcd.pl new file mode 100755 index 0000000..5f9fee1 --- /dev/null +++ b/tools/image/img2lcd.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# img2lcd.pl - by 05/2011, BSD Licence +# +# This script converts an image to .lcd format for the r0ket + +use strict; +use warnings; +use Getopt::Long; +use Module::Load; + +$|=1; + +### +### Runtime Options +### + +my ($verbose); + +GetOptions ( + "verbose" => \$verbose, # flag + "help" => sub { + print <new($in); + + +my $w=$image->width; +my $h=$image->height; + +my @img; +for my $y (0..$h){ + for my $x (0..$w){ + my $px= $image->getPixel($x,$y); + $img[$x][$y/8]|=$px<<(7-$y%8); + if($verbose){ + $px=~y/01/ */; print STDERR $px; + }; + }; + if ($verbose){ + print STDERR "<\n"; + }; +}; + +open(F,">",$out)||die "open: $!"; + +my $hb=int($h/8); +for my $y (0..$hb){ + for my $x (0..$w){ + printf F "%c",$img[$w-$x][$hb-$y]; + }; +}; + +close(F); diff --git a/tools/image/src/i42.gif b/tools/image/src/i42.gif new file mode 100755 index 0000000000000000000000000000000000000000..acd34eeb0000209667a9c3400465c9502307d4bd GIT binary patch literal 340 zcmV-a0jvH;Nk%v~VPF760Du4h|Ns90001li0001B07L))0{(=LsmtvTqnxzbi?iOm z`wxcVNS5Y_rs~SJVF0`G0>@^J*Rz3_`QMZ2M!;flbp!z!KjiS0gG5tLWi^r{WjkA} z?e?_>FkLY*T)9HgT=m5Lfp6qqwx>L|Q|KE0j;F`rmk=m2Xn{vlxHiW4c6hgV0Xd}t zDUnEc+140$n0eM2De3?kDn{C{>6zLm3HW--iWw`**{X<3RVx*{YIaMjyF0u$WYo0t zn~U6Bd9tkOJiX+@TUvBLogG@NWmjz&ondP2-TgOCe(mU@o_8+JuKG+L-!5omKl85L ztWZuKt4`JGvFHa2ATnhL0l?wLuc4f9LgwvbmaIjsT|V&Ye7a`uqtrsL-KAiy9SL002AVRHM@X literal 0 HcmV?d00001 From 30c566fa9819ef6b73887cdec32c62ba2562222d Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 23:04:44 +0200 Subject: [PATCH 30/35] oops, wrong dir --- tools/image/src/r0ket96x68.gif | Bin 0 -> 362 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tools/image/src/r0ket96x68.gif diff --git a/tools/image/src/r0ket96x68.gif b/tools/image/src/r0ket96x68.gif new file mode 100644 index 0000000000000000000000000000000000000000..0b043a98bfeb8ca047e19a1ded22d8b9a47fbdf8 GIT binary patch literal 362 zcmV-w0hRtoNk%w1VPF760HFW?00030|Nj6000000A^8LW3IGBCEC2ui0AK(_00091 zjE||y?GK}zwAzca-n={Dg(3ui<%p)Gd8Tf+2JuT@D`?#H9^JUC;|UeMUvY@c`3}dV zuxM;LY0#*2s=5M~*sQkNMQIV^u%-!B2F)C96~|?7g74N^j-l7>GrVoK$JgR#p|_{@ zLr4J_D5zK{7^wDG!Pq!SIbkWem8rS;hUh6_SSLD4Qku3kh}z(0%9`l9fCeTzOPjFD zTc(S6x4ZgVd&^`@OoWWvmn=LC9PE5N96DWGy?hKf9(|#oV4!Ul8j~J|c0|WLWh%kmPSG^RfGRQEEJ% literal 0 HcmV?d00001 From 566c38f945ff64fc191dd02b37910973a3bf51d4 Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 23:23:28 +0200 Subject: [PATCH 31/35] more file movement --- tools/image/{r0ket96x68.gif => src/r0ket.gif} | Bin tools/image/src/r0ket96x68.gif | Bin 362 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) rename tools/image/{r0ket96x68.gif => src/r0ket.gif} (100%) delete mode 100644 tools/image/src/r0ket96x68.gif diff --git a/tools/image/r0ket96x68.gif b/tools/image/src/r0ket.gif similarity index 100% rename from tools/image/r0ket96x68.gif rename to tools/image/src/r0ket.gif diff --git a/tools/image/src/r0ket96x68.gif b/tools/image/src/r0ket96x68.gif deleted file mode 100644 index 0b043a98bfeb8ca047e19a1ded22d8b9a47fbdf8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 362 zcmV-w0hRtoNk%w1VPF760HFW?00030|Nj6000000A^8LW3IGBCEC2ui0AK(_00091 zjE||y?GK}zwAzca-n={Dg(3ui<%p)Gd8Tf+2JuT@D`?#H9^JUC;|UeMUvY@c`3}dV zuxM;LY0#*2s=5M~*sQkNMQIV^u%-!B2F)C96~|?7g74N^j-l7>GrVoK$JgR#p|_{@ zLr4J_D5zK{7^wDG!Pq!SIbkWem8rS;hUh6_SSLD4Qku3kh}z(0%9`l9fCeTzOPjFD zTc(S6x4ZgVd&^`@OoWWvmn=LC9PE5N96DWGy?hKf9(|#oV4!Ul8j~J|c0|WLWh%kmPSG^RfGRQEEJ% From 6f05476b9a8fec29e7a48b16810b2e2f0e7ccd1e Mon Sep 17 00:00:00 2001 From: iggy Date: Thu, 4 Aug 2011 23:25:53 +0200 Subject: [PATCH 32/35] more .lcds --- tools/image/lcd/i42.lcd | Bin 0 -> 873 bytes tools/image/lcd/r0ket.lcd | Bin 0 -> 873 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tools/image/lcd/i42.lcd create mode 100644 tools/image/lcd/r0ket.lcd diff --git a/tools/image/lcd/i42.lcd b/tools/image/lcd/i42.lcd new file mode 100644 index 0000000000000000000000000000000000000000..f65a1da7fb63c37bd474572a62ae999d108dff0c GIT binary patch literal 873 zcmcgpF%E+;3{0BATk-(}-{^qKS9n6l4oIZp0sT^>4s3k`KPV$ZgllLJi6TlTZi#(& ziDR3wBT#k(V~p0?FQ>IJlMs-;;Tx07#B9WH&V>*FkC(N>t+M00eKrl}?2d?$dnI~{ z1@JZh8EJB7!ns{RAPDakbveN?-H0`K>P|?1-TlkdCp9{wMJ&_|DJ7jiM4g?st55;G ztp-Zh4^^Rp*_dIZ{sUK(s2T?ov5e8|Y!dLaoB;E5{}~n+pk$ilXNNpVQ>kECOz`NE Ol-KH#1&dmgBhC*=aZzLd literal 0 HcmV?d00001 diff --git a/tools/image/lcd/r0ket.lcd b/tools/image/lcd/r0ket.lcd new file mode 100644 index 0000000000000000000000000000000000000000..7ee229fb6d8301b16195e043e43270dc87c7e89b GIT binary patch literal 873 zcmcJLu?@r^3`LEQLI)#c5hPa0Cb5*o*dQyg!8u)u2%kf)Ib`W*?iZl{W!?vX{w(0% z3dXvSy15jbHK7X?J5T_Rwmr=vzL&IbpHxA9M*{^+2qjLoA&IH&c8Ud%zG0dhDd5$c zM#V-X#O91&HDZ?y6$md=^!BL%FxE%Pl6El7j?8cYuyb583iB4`CC>6?MI(0EPyzEr h1?A?($#G}oC0OX{P`Vu~XoqV(>3AJ<)~ds_^bHWJ+_3-v literal 0 HcmV?d00001 From f504eb3e60a516199df985c4638253f4e71d1583 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 23:39:16 +0200 Subject: [PATCH 33/35] Fir images. Converter was off-by-one --- tools/image/img2lcd.pl | 15 ++++++++++----- tools/image/lcd/i42.lcd | Bin 873 -> 864 bytes tools/image/lcd/r0ket.lcd | Bin 873 -> 864 bytes 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/image/img2lcd.pl b/tools/image/img2lcd.pl index 5f9fee1..d6738c6 100755 --- a/tools/image/img2lcd.pl +++ b/tools/image/img2lcd.pl @@ -46,9 +46,13 @@ my $image = GD::Image->new($in); my $w=$image->width; my $h=$image->height; +if($verbose){ + print STDERR "$in: ${w}x$h\n\n"; +}; + my @img; -for my $y (0..$h){ - for my $x (0..$w){ +for my $y (0..$h-1){ + for my $x (0..$w-1){ my $px= $image->getPixel($x,$y); $img[$x][$y/8]|=$px<<(7-$y%8); if($verbose){ @@ -62,10 +66,11 @@ for my $y (0..$h){ open(F,">",$out)||die "open: $!"; -my $hb=int($h/8); +$|=1; +my $hb=int(($h-1)/8); for my $y (0..$hb){ - for my $x (0..$w){ - printf F "%c",$img[$w-$x][$hb-$y]; + for my $x (0..$w-1){ + printf F "%c",$img[$w-$x-1][$hb-$y]; }; }; diff --git a/tools/image/lcd/i42.lcd b/tools/image/lcd/i42.lcd index f65a1da7fb63c37bd474572a62ae999d108dff0c..4fbf52446919c0b2d59ce756c92a86d8cb891244 100644 GIT binary patch delta 32 ncmaFK_JD0d%EYvkiKkO08!#qJo(ROB7!xOlFeOdi&a@E#>d6hg delta 36 rcmaFB_L6P#2d1=%DJc_=r%u*pOq|>e#IG5XCi^fYPhQ8giID*SCk+mg diff --git a/tools/image/lcd/r0ket.lcd b/tools/image/lcd/r0ket.lcd index 7ee229fb6d8301b16195e043e43270dc87c7e89b..b191e88ff8513eda299467e708ff8cb284147cce 100644 GIT binary patch delta 89 zcmaFK_JED?!$ijT$w`b#6I<*i2QW)c+`u{UDU`)E*`3iABFH^?C8G_D$;AX_PEKHQ ThY0abKF4GQVG2z)VKxN-hu Date: Thu, 4 Aug 2011 23:45:52 +0200 Subject: [PATCH 34/35] Another offset by 4 --- tools/image/img2lcd.pl | 2 +- tools/image/lcd/i42.lcd | Bin 864 -> 864 bytes tools/image/lcd/r0ket.lcd | Bin 864 -> 864 bytes 3 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/image/img2lcd.pl b/tools/image/img2lcd.pl index d6738c6..44e3014 100755 --- a/tools/image/img2lcd.pl +++ b/tools/image/img2lcd.pl @@ -54,7 +54,7 @@ my @img; for my $y (0..$h-1){ for my $x (0..$w-1){ my $px= $image->getPixel($x,$y); - $img[$x][$y/8]|=$px<<(7-$y%8); + $img[$x][($y+4)/8]|=$px<<(7-($y+4)%8); if($verbose){ $px=~y/01/ */; print STDERR $px; }; diff --git a/tools/image/lcd/i42.lcd b/tools/image/lcd/i42.lcd index 4fbf52446919c0b2d59ce756c92a86d8cb891244..f8b96a32a9ed170490fd8ac402e39fc2f2e9c2c6 100644 GIT binary patch literal 864 zcmcIhF%H8Z3F{53Qu4w1FGw$QWX@1EbR>l`|R^sX6*kM zr)g62ycpwMP5?0ir0k4YW;Ll=a?b*ky3W0VJqNigT1p|LRPTAtIUj=Em$d(c7=|`= z9u-8*&*_c18G`pTn2?`{k4#7@(Mt)!{Zs)FPq_mTA=jYy-ean0MaQ5-Eb$<;B>qV zUEnq688T^k8a~ejh&RHG!hw8} zD_tAmIU04_iCR696RRl&CcTK7!y&}4jxfh_k}F+Lc2HrhbiXq5+G|x~1&+^B;6v~9 WOtgau26iI$|FW+i%^0tYtVG{MxreL( literal 864 zcmcJL%?*Sg5QS$liQJ$B8X=(-J8=>lqXS!@gB@=k4DN_~!h;(&`wp1*eDm=m@?Ra# za!AI-rWc(dbWPZ0;nKWBuR6{pF7qetA~r+9ki$TgD2LQ94Iu+d)9kd9#R}yL6z1yC zPMy4VOmRtqrE3=eBpW1Y+7>%~1|T2C#ELw{X$)T9D|hnlW4mP5bEDB;2K64CWxv;c POG?>feXX*U@;&GcxrN-Z From f6ec40de2f2bb0619ba6cff403b86bd3b316488c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 4 Aug 2011 23:50:44 +0200 Subject: [PATCH 35/35] Add image helper functions --- firmware/lcd/Makefile | 1 + firmware/lcd/image.c | 46 +++++++++++++++++++++++++++++++++++++++++++ firmware/lcd/image.h | 8 ++++++++ 3 files changed, 55 insertions(+) create mode 100644 firmware/lcd/image.c create mode 100644 firmware/lcd/image.h diff --git a/firmware/lcd/Makefile b/firmware/lcd/Makefile index fe639a3..e9b8d76 100644 --- a/firmware/lcd/Makefile +++ b/firmware/lcd/Makefile @@ -9,6 +9,7 @@ OBJS += render.o OBJS += decoder.o OBJS += backlight.o OBJS += print.o +OBJS += image.o FONTS = $(basename $(wildcard fonts/*.c)) diff --git a/firmware/lcd/image.c b/firmware/lcd/image.c new file mode 100644 index 0000000..6d6b90a --- /dev/null +++ b/firmware/lcd/image.c @@ -0,0 +1,46 @@ +#include + +#include "basic/basic.h" +#include "lcd/lcd.h" +#include "lcd/display.h" +#include "filesystem/ff.h" + +int lcdLoadImage(char *file) { + return readFile(file,(char *)lcdBuffer,RESX*RESY_B); +} + +int lcdSaveImage(char *file) { + return writeFile(file,(char *)lcdBuffer,RESX*RESY_B); +} + +uint8_t lcdShowAnim(char *fname, uint32_t framems) { + FIL file; /* File object */ + int res; + UINT readbytes; + uint8_t state=0; + + res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ); + if(res) + return 1; + + getInputWaitRelease(); + while(!getInputRaw()){ + lcdFill(0x55); + res = f_read(&file, (char *)lcdBuffer, RESX*RESY_B, &readbytes); + if(res) + return -1; + if(readbytes