From aa821fca3f570f17dacce3f20ddd5a10cea3b038 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 31 Jul 2011 22:13:06 +0200 Subject: [PATCH 01/48] Fix a few things. --- firmware/applications/default.c | 20 ++++++++++++++------ firmware/applications/mesh/util.c | 14 +++++++++++++- firmware/applications/tester/util.c | 14 +++++++++++++- firmware/basic/basic.c | 3 +++ firmware/basic/basic.h | 14 ++++++++------ firmware/basic/config.c | 10 ++++++---- firmware/basic/night.c | 16 ++++++++-------- firmware/funk/mesh.c | 2 +- firmware/lcd/display.h | 1 + 9 files changed, 67 insertions(+), 27 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index d4f0b00..ed9aa8b 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -5,6 +5,7 @@ #include "lcd/fonts/smallfonts.h" #include "lcd/print.h" #include "filesystem/ff.h" +#include "usb/usbmsc.h" #include "basic/random.h" /**************************************************************************/ @@ -12,12 +13,18 @@ void main_default(void) { systickInit(SYSTICKSPEED); - if(getInputRaw()==BTN_ENTER){ - ISPandReset(); + switch(getInputRaw()){ + case BTN_ENTER: + ISPandReset(); + break; + case BTN_DOWN: + usbMSCInit(); + while(1) + delayms_power(100); + break; }; readConfig(); - applyConfig(); randomInit(); return; @@ -41,12 +48,13 @@ void tick_default(void) { if(ctr>100/SYSTICKSPEED){ if(isNight()){ backlightSetBrightness(GLOBAL(lcdbacklight)); - if(GLOBAL(nightinvert)) - lcdSetInvert(0); + lcdSetInvert(0); } else { backlightSetBrightness(0); - if(GLOBAL(nightinvert)) + if(GLOBAL(dayinvert)) lcdSetInvert(1); + else + lcdSetInvert(0); } } diff --git a/firmware/applications/mesh/util.c b/firmware/applications/mesh/util.c index 721cacd..8359628 100644 --- a/firmware/applications/mesh/util.c +++ b/firmware/applications/mesh/util.c @@ -29,6 +29,18 @@ void show_ticks(void) { }; +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; void adc_light(void) { int dx=0; int dy=8; @@ -37,7 +49,7 @@ void adc_light(void) { while ((getInputRaw())==BTN_NONE){ DoInt(dx,dy,GetLight()); DoInt(dx,dy+16,isNight()); - DoInt(dx,dy+8,GLOBAL(nighttrigger)); + DoInt(dx,dy+8,GLOBAL(daytrig)); lcdDisplay(); }; dy+=8; diff --git a/firmware/applications/tester/util.c b/firmware/applications/tester/util.c index 721cacd..8359628 100644 --- a/firmware/applications/tester/util.c +++ b/firmware/applications/tester/util.c @@ -29,6 +29,18 @@ void show_ticks(void) { }; +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; void adc_light(void) { int dx=0; int dy=8; @@ -37,7 +49,7 @@ void adc_light(void) { while ((getInputRaw())==BTN_NONE){ DoInt(dx,dy,GetLight()); DoInt(dx,dy+16,isNight()); - DoInt(dx,dy+8,GLOBAL(nighttrigger)); + DoInt(dx,dy+8,GLOBAL(daytrig)); lcdDisplay(); }; dy+=8; diff --git a/firmware/basic/basic.c b/firmware/basic/basic.c index 819de91..749547b 100644 --- a/firmware/basic/basic.c +++ b/firmware/basic/basic.c @@ -34,6 +34,9 @@ void rbInit() { gpioSetDir(RB_BTN4, gpioDirection_Input); gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp); + // prepate chrg_stat + gpioSetDir(RB_PWR_CHRG, gpioDirection_Input); + gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp); // prepare LEDs IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK; diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 41ed5c7..6da1410 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -81,6 +81,7 @@ #define RB_PWR_GOOD 1,8 #define RB_PWR_CHRG 2,3 +#define RB_PWR_CHRG_IO IOCON_PIO2_3 #define RB_PWR_LCDBL 0,0 #define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_0 @@ -203,12 +204,13 @@ extern struct CDESC the_config[]; #define GLOBALversion (the_config[0].value) #define GLOBALprivacy (the_config[1].value) -#define GLOBALnighttrigger (the_config[2].value) -#define GLOBALnightinvert (the_config[3].value) -#define GLOBALlcdbacklight (the_config[4].value) -#define GLOBALlcdmirror (the_config[5].value) -#define GLOBALlcdinvert (the_config[6].value) -#define GLOBALlcdcontrast (the_config[7].value) +#define GLOBALdaytrig (the_config[2].value) +#define GLOBALdaytrighyst (the_config[3].value) +#define GLOBALdayinvert (the_config[4].value) +#define GLOBALlcdbacklight (the_config[5].value) +#define GLOBALlcdmirror (the_config[6].value) +#define GLOBALlcdinvert (the_config[7].value) +#define GLOBALlcdcontrast (the_config[8].value) #define GLOBAL(x) GLOBAL ## x diff --git a/firmware/basic/config.c b/firmware/basic/config.c index d4a0b5a..a307853 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -10,12 +10,13 @@ struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, {"privacy", 3, 0, 2 }, - {"nighttrigger", 310/2, 0, 255}, - {"nightinvert", 1, 0, 1 }, + {"daytrig", 310/2, 0, 255}, + {"daytrighyst", 10, 0, 50 }, + {"dayinvert", 1, 0, 1 }, {"lcdbacklight", 50, 0, 100}, {"lcdmirror", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 }, - {"lcdcontrast", 3, 1, 6 }, + {"lcdcontrast", 0, 1, 6 }, { NULL, 0, 0, 0 }, }; @@ -25,7 +26,8 @@ struct CDESC the_config[]= { /**************************************************************************/ void applyConfig(){ - lcdSetContrast(GLOBAL(lcdcontrast)); + if(GLOBAL(lcdcontrast)>0) + lcdSetContrast(GLOBAL(lcdcontrast)); return 0; }; diff --git a/firmware/basic/night.c b/firmware/basic/night.c index ae62db1..8adc84c 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -2,12 +2,12 @@ #include "basic/basic.h" -#define RANGE (10) -#define HYST (4) -uint32_t light=300*HYST; +#define SAMPCT (4) +uint32_t light=300*SAMPCT; char _isnight=1; -#define threshold GLOBAL(nighttrigger) +#define threshold GLOBAL(daytrig) +#define RANGE GLOBAL(daytrighyst) void LightCheck(void){ int iocon; @@ -21,7 +21,7 @@ void LightCheck(void){ gpioSetDir(RB_LED3, gpioDirection_Input); IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG; - light-=light/HYST; + light-=light/SAMPCT; light += (adcRead(7)/2); gpioSetDir(RB_LED3, iodir); @@ -31,15 +31,15 @@ void LightCheck(void){ threshold=320; }; - if(_isnight && light/HYST>(threshold+RANGE)) + if(_isnight && light/SAMPCT>(threshold+RANGE)) _isnight=0; - if(!_isnight && light/HYST_timet) // Do not live in the past. _timet = toff; continue; diff --git a/firmware/lcd/display.h b/firmware/lcd/display.h index 79f671e..d39ccd3 100644 --- a/firmware/lcd/display.h +++ b/firmware/lcd/display.h @@ -30,4 +30,5 @@ void lcdSafeSetPixel(char x, char y, bool f); bool lcdGetPixel(char x, char y); void lcdShift(int x, int y, bool wrap); void lcdSetContrast(int c); +void lcdSetInvert(); #endif From 1ccda41467b2740ccf90e79ae5ffe59da6b8e29c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 31 Jul 2011 22:46:24 +0200 Subject: [PATCH 02/48] Sign error. Whoops. --- firmware/funk/mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 24a8e21..0bffc34 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -76,7 +76,7 @@ void mesh_recvloop(void){ }; if(MO_TYPE(buf)=='T'){ - time_t toff=MO_TIME(buf)-((getTimer()-(1000/SYSTICKSPEED))/(1000/SYSTICKSPEED)); + time_t toff=MO_TIME(buf)-((getTimer()+(300/SYSTICKSPEED))/(1000/SYSTICKSPEED)); if (toff>_timet) // Do not live in the past. _timet = toff; continue; From 621bca40b300109367b4b2f1c2d635d9f52cf8ba Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:08:05 +0200 Subject: [PATCH 03/48] improve application Makfile --- firmware/applications/Makefile | 9 +++++---- firmware/applications/{mktester => mkfirmware} | 5 ++++- firmware/applications/tester.c | 6 ------ 3 files changed, 9 insertions(+), 11 deletions(-) rename firmware/applications/{mktester => mkfirmware} (95%) diff --git a/firmware/applications/Makefile b/firmware/applications/Makefile index 86a45db..dacc19e 100644 --- a/firmware/applications/Makefile +++ b/firmware/applications/Makefile @@ -33,6 +33,7 @@ endif WRAP=wrapper LIBNAME=app + ########################################################################## # GNU GCC compiler flags ########################################################################## @@ -66,21 +67,21 @@ $(LOBJ): OBJS += $(LOBJ) endif -ifeq "$(APP)" "tester" +ifeq "$(wildcard $(APP))" "$(APP)" ifndef TYPE TYPE=$(APP) endif TSRCS = $(wildcard $(TYPE)/*.c) TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod))) -TWRAP=tester.gen +TWRAP=$(APP).gen .PHONY: $(TWRAP) $(APP).o: $(TWRAP) $(TWRAP): - ./mktester $(TSRCS) > $@ + ./mkfirmware $(APP) $(TSRCS) > $@ OBJS += $(TOBJS) endif @@ -93,7 +94,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ) $(CC) $(CFLAGS) -o $@ $< clean: - rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o + rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o *.gen %.c: @echo diff --git a/firmware/applications/mktester b/firmware/applications/mkfirmware similarity index 95% rename from firmware/applications/mktester rename to firmware/applications/mkfirmware index 661351d..fdf7f2d 100755 --- a/firmware/applications/mktester +++ b/firmware/applications/mkfirmware @@ -1,5 +1,8 @@ #!/bin/sh +APP=$1 +shift + for f in $* ; do grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do echo "void $a(void);" @@ -58,7 +61,7 @@ done echo "NULL" echo "};" -echo "inline void generated_tick(void){" +echo "inline void tick_${APP}(void){" for f in $* ; do grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do echo "$a();" diff --git a/firmware/applications/tester.c b/firmware/applications/tester.c index 50a3542..667b335 100644 --- a/firmware/applications/tester.c +++ b/firmware/applications/tester.c @@ -16,9 +16,3 @@ void main_tester(void) { handleMenu(&mainmenu); gotoISP(); }; - -void tick_tester(void){ - generated_tick(); -}; - - From 5d0887be714265fd57df3a819dc26217b19369ad Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:12:21 +0200 Subject: [PATCH 04/48] Move config stuff into own include. Iggy said its better :-) --- firmware/applications/mesh/config.c | 1 + firmware/applications/mesh/util.c | 1 + firmware/basic/basic.h | 35 ++++------------------------- firmware/basic/config.c | 6 ++++- firmware/basic/night.c | 1 + firmware/filesystem/ff.h | 1 + firmware/lcd/display.c | 1 + 7 files changed, 14 insertions(+), 32 deletions(-) diff --git a/firmware/applications/mesh/config.c b/firmware/applications/mesh/config.c index 4343198..94a20f9 100644 --- a/firmware/applications/mesh/config.c +++ b/firmware/applications/mesh/config.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/print.h" #include "lcd/display.h" diff --git a/firmware/applications/mesh/util.c b/firmware/applications/mesh/util.c index 8359628..a208a13 100644 --- a/firmware/applications/mesh/util.c +++ b/firmware/applications/mesh/util.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/print.h" diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index 6da1410..ed67c74 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -186,37 +186,6 @@ void handleMenu(const struct MENU *the_menu); #include "basic/idle.h" -// config.c - -int readConfig(void); -int saveConfig(void); -void applyConfig(void); - - -struct CDESC { - char *name; - char value; - char min; - char max; -}; - -extern struct CDESC the_config[]; - -#define GLOBALversion (the_config[0].value) -#define GLOBALprivacy (the_config[1].value) -#define GLOBALdaytrig (the_config[2].value) -#define GLOBALdaytrighyst (the_config[3].value) -#define GLOBALdayinvert (the_config[4].value) -#define GLOBALlcdbacklight (the_config[5].value) -#define GLOBALlcdmirror (the_config[6].value) -#define GLOBALlcdinvert (the_config[7].value) -#define GLOBALlcdcontrast (the_config[8].value) - -#define GLOBAL(x) GLOBAL ## x - - -#define SYSTICKSPEED 10 - // itoa.c #define F_ZEROS (1<<0) #define F_LONG (1<<1) @@ -229,4 +198,8 @@ const char* IntToStr(int num, unsigned int mxlen, char flag); #include "basic/simpletime.h" +// global +#define SYSTICKSPEED 10 + + #endif diff --git a/firmware/basic/config.c b/firmware/basic/config.c index a307853..313d46e 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -4,8 +4,9 @@ #include "lcd/print.h" #include "filesystem/ff.h" #include "basic/random.h" +#include "basic/config.h" -#define CFGVER 23 +#define CFGVER 24 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, @@ -20,6 +21,9 @@ struct CDESC the_config[]= { { NULL, 0, 0, 0 }, }; +char nickname[MAXNICK]="anonymous"; +char nickfont[FILENAMELEN]; + #define CONFFILE "r0ket.cfg" #define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++) diff --git a/firmware/basic/night.c b/firmware/basic/night.c index 8adc84c..f944246 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #define SAMPCT (4) uint32_t light=300*SAMPCT; diff --git a/firmware/filesystem/ff.h b/firmware/filesystem/ff.h index 07eb8ad..352ed5c 100644 --- a/firmware/filesystem/ff.h +++ b/firmware/filesystem/ff.h @@ -329,6 +329,7 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ #endif /* Utility functions */ +#define FILENAMELEN 13 // 8+1+3+1 const char* f_get_rc_string (FRESULT rc); void fsInit(); diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 3ffd916..bdb1d4f 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -6,6 +6,7 @@ #include "core/ssp/ssp.h" #include "gpio/gpio.h" #include "basic/basic.h" +#include "basic/config.h" #include "usb/usbmsc.h" /**************************************************************************/ From 62992863489a42a21a5af965a7b9923ac7ef0941 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:12:58 +0200 Subject: [PATCH 05/48] Two utility functions to read/write small files --- firmware/filesystem/ff.h | 2 ++ firmware/filesystem/util.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/firmware/filesystem/ff.h b/firmware/filesystem/ff.h index 352ed5c..611a703 100644 --- a/firmware/filesystem/ff.h +++ b/firmware/filesystem/ff.h @@ -332,6 +332,8 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ #define FILENAMELEN 13 // 8+1+3+1 const char* f_get_rc_string (FRESULT rc); void fsInit(); +int readFile(char * filename, char * data, int len); +int writeFile(char * filename, char * data, int len); #ifdef __cplusplus } diff --git a/firmware/filesystem/util.c b/firmware/filesystem/util.c index 7e635ad..d5cc5d0 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -22,3 +22,41 @@ const char* f_get_rc_string (FRESULT rc) { void fsInit(){ f_mount(0, &FatFs); }; + +int readFile(char * filename, char * data, int len){ + FIL file; + UINT readbytes; + int res; + + res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ); + if(res){ + return -1; + }; + + res = f_read(&file, data, len-1, &readbytes); + if(res){ + return -1; + }; + + data[readbytes]=0; + return readbytes; +}; + +int writeFile(char * filename, char * data, int len){ + FIL file; + UINT writebytes; + int res; + + res=f_open(&file, filename, FA_OPEN_ALWAYS|FA_WRITE); + if(res){ + return -1; + }; + + res = f_write(&file, data, len, &writebytes); + if(res){ + return -1; + }; + + return writebytes; +}; + From 29df9b9e1fed7f3f046a1ca6354cd2c68fe0e7a1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:34:11 +0200 Subject: [PATCH 06/48] Add missing config.h --- firmware/applications/default.c | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index ed9aa8b..1cc168e 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -1,5 +1,6 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/fonts/smallfonts.h" From f2c5d53cb92e6a7dc28290a9ed09027947a876de Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 01:55:04 +0200 Subject: [PATCH 07/48] Oops. We need to close the files, too. --- firmware/filesystem/util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/filesystem/util.c b/firmware/filesystem/util.c index d5cc5d0..0f3c939 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -38,6 +38,8 @@ int readFile(char * filename, char * data, int len){ return -1; }; + f_close(&file); + data[readbytes]=0; return readbytes; }; @@ -56,6 +58,7 @@ int writeFile(char * filename, char * data, int len){ if(res){ return -1; }; + f_close(&file); return writebytes; }; From 91ed6e7ba2c129509cb05d9bd0a8d200dba00656 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 04:23:50 +0200 Subject: [PATCH 08/48] Unhate Sec by following the new global config framework --- simulat0r/gui/qsimulat0r.cc | 10 +++++----- simulat0r/tui/simulat0r.c | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/simulat0r/gui/qsimulat0r.cc b/simulat0r/gui/qsimulat0r.cc index c2146d2..4798a1f 100644 --- a/simulat0r/gui/qsimulat0r.cc +++ b/simulat0r/gui/qsimulat0r.cc @@ -92,15 +92,15 @@ public: pixmap.setPixel(1,1,(QColor(backlight,backlight,backlight).rgb())); pixmap.fill(pixmap.pixel(1,1)); + const int pixelOn=GLOBAL(lcdinvert)?colorInvertedPixelOn:colorPixelOn; + const int pixelOff=GLOBAL(lcdinvert)?colorInvertedPixelOff:colorPixelOff; + // draw lcd array for (int x = 0; x < dimx; ++x) { for(int y=0; y Date: Mon, 1 Aug 2011 04:44:42 +0200 Subject: [PATCH 09/48] Added some more bridge files to bring new r0ket sources into simulat0r --- simulat0r/firmware/applications/inputtest.c | 2 ++ simulat0r/firmware/basic/simpletime.c | 2 ++ simulat0r/firmware/basic/simpletime.h | 2 ++ simulat0r/firmware/basic/stringin.c | 2 ++ simulat0r/firmware/funk/mesh.c | 2 ++ simulat0r/firmware/funk/mesh.h | 2 ++ 6 files changed, 12 insertions(+) create mode 100644 simulat0r/firmware/applications/inputtest.c create mode 100644 simulat0r/firmware/basic/simpletime.c create mode 100644 simulat0r/firmware/basic/simpletime.h create mode 100644 simulat0r/firmware/basic/stringin.c create mode 100644 simulat0r/firmware/funk/mesh.c create mode 100644 simulat0r/firmware/funk/mesh.h diff --git a/simulat0r/firmware/applications/inputtest.c b/simulat0r/firmware/applications/inputtest.c new file mode 100644 index 0000000..9a04a36 --- /dev/null +++ b/simulat0r/firmware/applications/inputtest.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/applications/inputtest.c" diff --git a/simulat0r/firmware/basic/simpletime.c b/simulat0r/firmware/basic/simpletime.c new file mode 100644 index 0000000..ab04cd5 --- /dev/null +++ b/simulat0r/firmware/basic/simpletime.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/simpletime.c" diff --git a/simulat0r/firmware/basic/simpletime.h b/simulat0r/firmware/basic/simpletime.h new file mode 100644 index 0000000..118da21 --- /dev/null +++ b/simulat0r/firmware/basic/simpletime.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/simpletime.h" diff --git a/simulat0r/firmware/basic/stringin.c b/simulat0r/firmware/basic/stringin.c new file mode 100644 index 0000000..34cb6e3 --- /dev/null +++ b/simulat0r/firmware/basic/stringin.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/stringin.c" diff --git a/simulat0r/firmware/funk/mesh.c b/simulat0r/firmware/funk/mesh.c new file mode 100644 index 0000000..29a9352 --- /dev/null +++ b/simulat0r/firmware/funk/mesh.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/funk/mesh.c" diff --git a/simulat0r/firmware/funk/mesh.h b/simulat0r/firmware/funk/mesh.h new file mode 100644 index 0000000..a5fe83f --- /dev/null +++ b/simulat0r/firmware/funk/mesh.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/funk/mesh.h" From f41d900e0d54088f5d9c530aac7eea34c31ec797 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:06:20 +0200 Subject: [PATCH 10/48] Adjust startup value --- firmware/basic/night.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/basic/night.c b/firmware/basic/night.c index f944246..9423ffd 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -4,7 +4,7 @@ #include "basic/config.h" #define SAMPCT (4) -uint32_t light=300*SAMPCT; +uint32_t light=150*SAMPCT; char _isnight=1; #define threshold GLOBAL(daytrig) From 34869e2973d130e734517a102721f0d2e9b0a3c0 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:10:37 +0200 Subject: [PATCH 11/48] modernize menu.c --- firmware/basic/menu.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 4758d65..811e356 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -2,7 +2,6 @@ #include "basic/basic.h" -#include "lcd/fonts.h" #include "lcd/render.h" #include "lcd/print.h" @@ -21,27 +20,24 @@ void handleMenu(const struct MENU *the_menu) { for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); - visible_lines = (RESY/font->u8Height)-1; // subtract title line + visible_lines = (RESY/getFontHeight())-1; // subtract title line #ifdef SAFETY if (visible_lines < 2) return; #endif while (!back) { - uint8_t line = 0; - // Display current menu page - lcdFill(0); - DoString(0, line, the_menu->title); - line += font->u8Height; + lcdClear(); + lcdPrintln(the_menu->title); for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { - DoString(14, line, the_menu->entries[i]->text); if (i == menuselection) { - DoString(0, line, "* "); + lcdPrint("*"); } - line += font->u8Height; + lcdSetCrsrX(14); + lcdPrintln(the_menu->entries[i]->text); } - lcdDisplay(); + lcdRefresh(); switch (getInputWait()) { case BTN_UP: From 6bd703f006e249500ec701cb147fdd846388cf3a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:11:04 +0200 Subject: [PATCH 12/48] fix new font setting for internal fonts --- firmware/lcd/render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/lcd/render.c b/firmware/lcd/render.c index 62339df..2a2f692 100644 --- a/firmware/lcd/render.c +++ b/firmware/lcd/render.c @@ -18,10 +18,10 @@ FIL file; /* current font file */ /* Exported Functions */ -void setIntFont(const struct FONT_DEF * font){ - memcpy(&efont.def,font,sizeof(struct FONT_DEF)); +void setIntFont(const struct FONT_DEF * newfont){ + memcpy(&efont.def,newfont,sizeof(struct FONT_DEF)); efont.type=FONT_INTERNAL; - font=NULL; + font=&efont.def; }; void setExtFont(const char *fname){ From 61c12936110fcb45c4c26d2f76f17ffd20954cee Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:11:56 +0200 Subject: [PATCH 13/48] Add Timestamp support for filesystem. This took me 3h to debug :-/ --- firmware/filesystem/at45db041d.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/firmware/filesystem/at45db041d.c b/firmware/filesystem/at45db041d.c index 0c6fe37..99b1ff9 100644 --- a/firmware/filesystem/at45db041d.c +++ b/firmware/filesystem/at45db041d.c @@ -236,9 +236,13 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) { } #endif /* _USE_IOCTL != 0 */ - - DWORD get_fattime () { - // ToDo! - return 0; + struct tm* tm=mygmtime(getSeconds()); + DWORD t= (((tm->tm_year+YEAR0-1980)<<9)| + ((tm->tm_mon+1)<<5)| + (tm->tm_mday))<<16 | + ((tm->tm_hour<<11)| + (tm->tm_min<<5)| + (tm->tm_sec>>1)); + return t; } From cccb8694232bbde59e2981445c6bbddec839b3a9 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:22:24 +0200 Subject: [PATCH 14/48] Fix a few warnings --- firmware/basic/config.c | 3 ++- firmware/basic/night.c | 6 ------ firmware/basic/random.c | 1 + firmware/funk/filetransfer.c | 2 +- firmware/funk/rftransfer.c | 1 + firmware/main.c | 1 + 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 0e3b35f..396e500 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "lcd/display.h" #include "lcd/print.h" #include "filesystem/ff.h" #include "basic/random.h" @@ -32,7 +33,7 @@ char nickfont[FILENAMELEN]; void applyConfig(){ if(GLOBAL(lcdcontrast)>0) lcdSetContrast(GLOBAL(lcdcontrast)); - return 0; + return; }; int saveConfig(void){ diff --git a/firmware/basic/night.c b/firmware/basic/night.c index 9423ffd..5efe7c4 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -14,8 +14,6 @@ void LightCheck(void){ int iocon; char iodir; - int value; - iocon=IOCON_PIO1_11; // iodir=gpioGetDir(RB_LED3); iodir= (GPIO_GPIO1DIR & (1 << (RB_LED3) ))?1:0; @@ -28,10 +26,6 @@ void LightCheck(void){ gpioSetDir(RB_LED3, iodir); IOCON_PIO1_11=iocon; - if(threshold==0){ // uninitialized? - threshold=320; - }; - if(_isnight && light/SAMPCT>(threshold+RANGE)) _isnight=0; diff --git a/firmware/basic/random.c b/firmware/basic/random.c index 06500ca..08b5a05 100644 --- a/firmware/basic/random.c +++ b/firmware/basic/random.c @@ -1,6 +1,7 @@ #include #include "random.h" #include "xxtea.h" +#include "core/adc/adc.h" #define STATE_SIZE 8 uint32_t state[STATE_SIZE]; diff --git a/firmware/funk/filetransfer.c b/firmware/funk/filetransfer.c index ffa4b94..375d4cd 100644 --- a/firmware/funk/filetransfer.c +++ b/firmware/funk/filetransfer.c @@ -108,7 +108,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) } lcdRefresh(); if( fres < 0 ) - return; + return 1; //nrf_set_rx_mac(0, 32, 5, macbuf); xxtea_decode_words((uint32_t *)buf, wordcount, k); diff --git a/firmware/funk/rftransfer.c b/firmware/funk/rftransfer.c index b392152..cda2e50 100644 --- a/firmware/funk/rftransfer.c +++ b/firmware/funk/rftransfer.c @@ -1,6 +1,7 @@ #include "rftransfer.h" #include "nrf24l01p.h" #include +#include #include #include diff --git a/firmware/main.c b/firmware/main.c index bcef02d..e24f7db 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -5,6 +5,7 @@ #include "basic/basic.h" #include "lcd/render.h" +#include "filesystem/ff.h" /**************************************************************************/ From 26515e271750fb542c720b8faf849b4f5249208d Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:23:14 +0200 Subject: [PATCH 15/48] I forgot this new .h file a few commits ago. --- firmware/basic/config.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 firmware/basic/config.h diff --git a/firmware/basic/config.h b/firmware/basic/config.h new file mode 100644 index 0000000..c4419c5 --- /dev/null +++ b/firmware/basic/config.h @@ -0,0 +1,35 @@ +#ifndef __BASICCONFIG_H_ +#define __BASICCONFIG_H_ + +int readConfig(void); +int saveConfig(void); +void applyConfig(void); + + +struct CDESC { + char *name; + char value; + char min; + char max; +}; + +#define MAXNICK 20 +extern struct CDESC the_config[]; +extern char nickname[MAXNICK]; +extern char nickfont[]; + +#define GLOBALversion (the_config[0].value) +#define GLOBALprivacy (the_config[1].value) +#define GLOBALdaytrig (the_config[2].value) +#define GLOBALdaytrighyst (the_config[3].value) +#define GLOBALdayinvert (the_config[4].value) +#define GLOBALlcdbacklight (the_config[5].value) +#define GLOBALlcdmirror (the_config[6].value) +#define GLOBALlcdinvert (the_config[7].value) +#define GLOBALlcdcontrast (the_config[8].value) +#define GLOBALnickname (nickname) +#define GLOBALnickfont (nickfont) + +#define GLOBAL(x) GLOBAL ## x + +#endif From d4c48f66c23fe3d7a44a75871ffe0cd3f2739274 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 05:31:47 +0200 Subject: [PATCH 16/48] Disable nrf on lowpower-off --- firmware/basic/voltage.c | 1 + firmware/funk/nrf24l01p.c | 7 +++++++ firmware/funk/nrf24l01p.h | 1 + 3 files changed, 9 insertions(+) diff --git a/firmware/basic/voltage.c b/firmware/basic/voltage.c index 1ed2d69..624cbf8 100644 --- a/firmware/basic/voltage.c +++ b/firmware/basic/voltage.c @@ -11,6 +11,7 @@ void VoltageCheck(void){ results /= 1024; if( results < 3500 ){ + nrf_off(); gpioSetValue (RB_PWR_GOOD, 0); gpioSetValue (RB_LCD_BL, 0); SCB_SCR |= SCB_SCR_SLEEPDEEP; diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index bffaa34..8c3c464 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -395,3 +395,10 @@ void nrf_init() { nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3); }; +void nrf_off() { + nrf_write_reg(R_CONFIG, + R_CONFIG_MASK_RX_DR| + R_CONFIG_MASK_TX_DS| + R_CONFIG_MASK_MAX_RT + ); // Most important: no R_CONFIG_PWR_UP +}; diff --git a/firmware/funk/nrf24l01p.h b/firmware/funk/nrf24l01p.h index ace6122..252d747 100644 --- a/firmware/funk/nrf24l01p.h +++ b/firmware/funk/nrf24l01p.h @@ -138,6 +138,7 @@ int nrf_rcv_pkt_time_encr(int maxtime, int maxsize, uint8_t * pkt, uint32_t cons char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const k[4]); void nrf_init() ; +void nrf_off() ; void nrf_cmd(uint8_t cmd); uint8_t nrf_cmd_status(uint8_t cmd); From 377d614c385f4416b0ee1b027580992f93551cbd Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Sun, 31 Jul 2011 21:52:28 +0200 Subject: [PATCH 17/48] Fix build on Mac OS X The header stdio.h on Mac OS X includes some defines to do buffer overflow checks if using _FORTIFY_SOURCE > 2, which is the default. Defining _FORTIFY_SOURCE=0 disables this behavior. The Mac OS X linker ld64 has problem with common symbols in static archives. The workaround here is to run 'ranlib -c' on the static archive. --- firmware/Makefile.inc | 2 ++ firmware/Makefile.util | 1 + simulat0r/firmware/Makefile.inc | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 7085dd9..855d011 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld SIZE = $(CROSS_COMPILE)size +AR = $(CROSS_COMPILE)ar +RANLIB = $(CROSS_COMPILE)ranlib OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump OUTFILE = firmware diff --git a/firmware/Makefile.util b/firmware/Makefile.util index 5e7916b..735c919 100644 --- a/firmware/Makefile.util +++ b/firmware/Makefile.util @@ -6,6 +6,7 @@ all: $(LIBFILE) $(LIBFILE): $(OBJS) $(AR) rcs $@ $(OBJS) + $(RANLIB) $(RANLIBFLAGS) $@ %.o : %.c $(CC) $(CFLAGS) -o $@ $< diff --git a/simulat0r/firmware/Makefile.inc b/simulat0r/firmware/Makefile.inc index cfa0f0a..98a0713 100644 --- a/simulat0r/firmware/Makefile.inc +++ b/simulat0r/firmware/Makefile.inc @@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld SIZE = $(CROSS_COMPILE)size +AR = $(CROSS_COMPILE)ar +RANLIB = $(CROSS_COMPILE)ranlib OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump OUTFILE = firmware @@ -44,6 +46,12 @@ endif CFLAGS = -std=c99 -c -g -O0 $(INCLUDE_PATHS) -Wall -funsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -DRAMCODE=$(RAMCODE) -fno-builtin -DSIMULATOR -I$(ROOT_PATH)/../simcore -include libc-unc0llide.h $(CONFIG_GCC_SHOWCOLUMN) #LDFLAGS = -nostartfiles +ifeq ($(shell uname), Darwin) +# Mac OS X provides a stdio.h with unwanted defines +CFLAGS += -D_FORTIFY_SOURCE=0 +# ld64 has problems with common symbols , apply a workaround +RANLIBFLAGS = -c +endif CONFIG_MAKE_PRINTDIRECTORY = --no-print-directory CONFIG_GCC_SHOWCOLUMN = From f43feaeda3f3e6a1523f275305b134641636c2ab Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 05:51:42 +0200 Subject: [PATCH 18/48] Added test script to build all applications as firmware and simulat0r --- simulat0r/bin/test-all.sh | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 simulat0r/bin/test-all.sh diff --git a/simulat0r/bin/test-all.sh b/simulat0r/bin/test-all.sh new file mode 100755 index 0000000..815f9e3 --- /dev/null +++ b/simulat0r/bin/test-all.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# +# test-all.sh +# Build all applications as firmware and simulat0r +# Results are saved as /tmp/firmware-appname.bin-buildtag or /tmp/qsimulat0r-... +# Call prefixed with BUILD="-myowntag" to replace default timestamp based build tag +# Setting BUILD empty suppresses the build tag +# Use TARGET=firmware or TARGET=simulat0r to limit compilation +# When building both targets and the firmware build failed the simulat0r build is skipped +# + +if test ! -v BUILD; then + BUILD=-`date --iso-8601=seconds` + echo Setting BUILD to $BUILD +fi + +if test ! -v TARGET; then + BUILDFIRMWARE=1 + BUILDSIM=1 +else + case $TARGET in + both |all ) BUILDFIRMWARE=1; BUILDSIM=1;; + firmware | firm ) BUILDFIRMWARE=1; BUILDSIM=0;; + simulat0r | simulator | sim ) BUILDFIRMWARE=0; BUILDSIM=1;; + *) echo "Cannot build unknow target \"$TARGET\""; exit 1;; + esac +fi + +echo -n "Building " +if test $BUILDFIRMWARE -eq 1; then + echo -n "firmware " +fi +if test $BUILDSIM -eq 1; then + echo -n "simulat0r " +fi +echo + +function doTest() +{ + APP=$1 + FIRMWARESUCCESS=1 + + if test $BUILDFIRMWARE -eq 1; then + if make -C firmware APP=$APP 2>/dev/null >/dev/null + then + TMPFILE=/tmp/firmware-$APP.bin$BUILD + echo OK $APP as $TMPFILE + cp firmware/firmware.bin $TMPFILE + else + echo FIRMWARE BUILD FAILED $APP + FIRMWARESUCCESS=0 + fi + fi + + if test $FIRMWARESUCCESS -eq 1 -a $BUILDSIM -eq 1; then + if make -C simulat0r APP=$APP 2>/dev/null >/dev/null + then + TMPFILE=/tmp/qsimulat0r-$APP$BUILD + echo OK $APP as $TMPFILE + cp simulat0r/gui/build/qsimulat0r $TMPFILE + else + echo SIMULAT0R BUILD FAILED $APP + fi + fi +} + +echo "Testing all applications..." + +for i in `find firmware/applications/ -iname \*.c | sort` +do + if grep -q main_ $i + then + APP=`basename $i | sed "s/\..*//"` + doTest $APP + fi +done From 86381283d1d3ffcc1bb394391fdf2b16181231a9 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 05:54:40 +0200 Subject: [PATCH 19/48] Added some more bridge files to bring new r0ket sources into simulat0r --- simulat0r/firmware/applications/mesh/config.c | 2 ++ simulat0r/firmware/applications/mesh/mesh.c | 2 ++ simulat0r/firmware/applications/mesh/util.c | 2 ++ simulat0r/firmware/applications/mesh/uuid.c | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 simulat0r/firmware/applications/mesh/config.c create mode 100644 simulat0r/firmware/applications/mesh/mesh.c create mode 100644 simulat0r/firmware/applications/mesh/util.c create mode 100644 simulat0r/firmware/applications/mesh/uuid.c diff --git a/simulat0r/firmware/applications/mesh/config.c b/simulat0r/firmware/applications/mesh/config.c new file mode 100644 index 0000000..b3ae6be --- /dev/null +++ b/simulat0r/firmware/applications/mesh/config.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/config.c" diff --git a/simulat0r/firmware/applications/mesh/mesh.c b/simulat0r/firmware/applications/mesh/mesh.c new file mode 100644 index 0000000..f733699 --- /dev/null +++ b/simulat0r/firmware/applications/mesh/mesh.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/mesh.c" diff --git a/simulat0r/firmware/applications/mesh/util.c b/simulat0r/firmware/applications/mesh/util.c new file mode 100644 index 0000000..54bf787 --- /dev/null +++ b/simulat0r/firmware/applications/mesh/util.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/util.c" diff --git a/simulat0r/firmware/applications/mesh/uuid.c b/simulat0r/firmware/applications/mesh/uuid.c new file mode 100644 index 0000000..86ea43c --- /dev/null +++ b/simulat0r/firmware/applications/mesh/uuid.c @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../../firmware/applications/mesh/uuid.c" From aa95549b2fadeb181958aa68d5564c62868c1e73 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 05:59:45 +0200 Subject: [PATCH 20/48] Yet another bridge file --- simulat0r/firmware/basic/config.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 simulat0r/firmware/basic/config.h diff --git a/simulat0r/firmware/basic/config.h b/simulat0r/firmware/basic/config.h new file mode 100644 index 0000000..fe5bbda --- /dev/null +++ b/simulat0r/firmware/basic/config.h @@ -0,0 +1,2 @@ +/* AUTOGENERATED SOURCE FILE */ +#include "../../../firmware/basic/config.h" From 174e7ee9e572292380ec2626beaa8b5cfcb781a1 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 06:10:22 +0200 Subject: [PATCH 21/48] The calls to nrf_off on lowpower-off require a -lfunk at the end --- firmware/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/Makefile b/firmware/Makefile index 0f54761..9f1b1f7 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -42,6 +42,7 @@ LDLIBS += -Llcd -llcd LDLIBS += -Lcore -lcore LDLIBS += -Lusb -lusb LDLIBS += -lbasic +LDLIBS += -lfunk OCFLAGS = --strip-unneeded SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib))) From cf92a1c00b837f4fcbbeddfdd4b7d2017676626a Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 06:13:29 +0200 Subject: [PATCH 22/48] use the new config include in simulat0r --- simulat0r/gui/qsimulat0r.cc | 1 + simulat0r/tui/simulat0r.c | 1 + 2 files changed, 2 insertions(+) diff --git a/simulat0r/gui/qsimulat0r.cc b/simulat0r/gui/qsimulat0r.cc index 4798a1f..21d57b2 100644 --- a/simulat0r/gui/qsimulat0r.cc +++ b/simulat0r/gui/qsimulat0r.cc @@ -19,6 +19,7 @@ using namespace std; extern "C" { #include "basic/basic.h" +#include "basic/config.h" #include "lcd/backlight.h" #define lcdGetPixel __hideaway_lcdGetPixel diff --git a/simulat0r/tui/simulat0r.c b/simulat0r/tui/simulat0r.c index f0d3afa..8c4fbf1 100644 --- a/simulat0r/tui/simulat0r.c +++ b/simulat0r/tui/simulat0r.c @@ -1,5 +1,6 @@ #include "simulator.h" #include "../firmware/basic/basic.h" +#include "../firmware/basic/config.h" #include "../firmware/lcd/display.h" #include From 49c49e328f03e5314915c7e5da479b031e6d42a7 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 06:15:44 +0200 Subject: [PATCH 23/48] Disable too flashy backlight cycling in life --- firmware/applications/life.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/applications/life.c b/firmware/applications/life.c index 7cb5b0e..2802cff 100644 --- a/firmware/applications/life.c +++ b/firmware/applications/life.c @@ -159,6 +159,7 @@ void nextledcycle() { uchar stepmode=0; uchar randdensity=0; +//uint8_t bl=0; void main_life(void) { backlightInit(); @@ -198,9 +199,12 @@ void main_life(void) { stepmode=1; break; } + // bl=(bl+1)%101; + // backlightSetBrightness(bl); draw_area(); // xor life pattern over display content lcdDisplay(); draw_area(); // xor life pattern again to restore original display content + lcdShift(1,-2,1); delayms(10); calc_area(); } From bd047cbe5a26a3bd40467566ed380256d1475d70 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 14:32:22 +0200 Subject: [PATCH 24/48] Add simple lcdRefresh() speedtest --- firmware/applications/tester/font.c | 41 +++++++++++++++++++++++++++++ firmware/applications/tester/util.c | 1 + 2 files changed, 42 insertions(+) diff --git a/firmware/applications/tester/font.c b/firmware/applications/tester/font.c index 09dba37..b49dc65 100644 --- a/firmware/applications/tester/font.c +++ b/firmware/applications/tester/font.c @@ -127,3 +127,44 @@ void f_font(void){ while(!getInputRaw())delayms(10); }; + +void f_speedtest(void){ + lcdClear(); + lcdPrintln("Speedtest"); + lcdNl(); + lcdNl(); + lcdPrintln("running..."); + + int start=getTimer(); + int ctr=0; + while(ctr++<1000){ + lcdRefresh(); + }; + start=getTimer()-start; + lcdPrint("Ticks:"); + lcdPrintln(IntToStr(start,6,0)); + lcdPrint("Tickspd:"); + lcdPrintln(IntToStr(SYSTICKSPEED,3,0)); + lcdRefresh(); + getInputWait(); + getInputWaitRelease(); +}; + +void f_speedtest2(void){ + lcdClear(); + lcdPrintln("Speedtest"); + lcdNl(); + lcdNl(); + lcdPrintln("running..."); + + int start=getTimer(); + int ctr=0; + int tm; + while(!getInputRaw()){ + ctr++; + tm=((getTimer()-start)*SYSTICKSPEED)*1000/ctr; + DoInt(0,32,tm); + lcdRefresh(); + }; + getInputWaitRelease(); +}; diff --git a/firmware/applications/tester/util.c b/firmware/applications/tester/util.c index 8359628..a208a13 100644 --- a/firmware/applications/tester/util.c +++ b/firmware/applications/tester/util.c @@ -1,6 +1,7 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/lcd.h" #include "lcd/print.h" From 5b7a675e1f5201526ad48202cfdf6679867e50f2 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 16:09:04 +0200 Subject: [PATCH 25/48] Whoops. Make systick called again in APP=tester --- firmware/applications/tester.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/applications/tester.c b/firmware/applications/tester.c index 667b335..d494e42 100644 --- a/firmware/applications/tester.c +++ b/firmware/applications/tester.c @@ -16,3 +16,5 @@ void main_tester(void) { handleMenu(&mainmenu); gotoISP(); }; + +void tick_tester(void); From 8c4ceb16aae47dc3773334a9d5c1ba0896596e50 Mon Sep 17 00:00:00 2001 From: bernd Date: Mon, 1 Aug 2011 16:51:14 +0200 Subject: [PATCH 26/48] Whoops... removed accidental Y-mirror in simulat0r --- simulat0r/gui/qsimulat0r.cc | 2 +- simulat0r/tui/simulat0r.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/simulat0r/gui/qsimulat0r.cc b/simulat0r/gui/qsimulat0r.cc index 21d57b2..e8bbb5c 100644 --- a/simulat0r/gui/qsimulat0r.cc +++ b/simulat0r/gui/qsimulat0r.cc @@ -100,7 +100,7 @@ public: for (int x = 0; x < dimx; ++x) { for(int y=0; y Date: Mon, 1 Aug 2011 17:33:48 +0200 Subject: [PATCH 27/48] Some Makefile fixes --- simulat0r/tui/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/simulat0r/tui/Makefile b/simulat0r/tui/Makefile index 6d798d8..a66ec02 100644 --- a/simulat0r/tui/Makefile +++ b/simulat0r/tui/Makefile @@ -9,11 +9,8 @@ CFLAGS += -I../simcore OBJS+= ../firmware/basic/*.o OBJS+= ../firmware/core/*.o OBJS+= ../firmware/core/*/*.o -LDFLAGS+= -L../firmware/applications LIBS+= ../firmware/applications/libapp.a -LDFLAGS+= -L../firmware/lcd LIBS+= ../firmware/lcd/liblcd.a -LDFLAGS+= -L../firmware/usb LIBS+= ../firmware/usb/libusb.a #LIBS += -lm @@ -27,10 +24,13 @@ LIBS += ../firmware/basic/libbasic.a OBJS+=../simcore/simcore.o ../simcore/misc.o ../simcore/timecounter.o +OBJS += simulat0r.o + .PHONY : all all : simulat0r -simulat0r : simulat0r.o $(OBJS) $(LIBS) +simulat0r : $(OBJS) $(LIBS) + $(LD) $(OBJS) $(LIBS) -lc -o $@ clean: $(RM) simulat0r.o From f82cb8382af4440660bb7470ad4f49ce4bf2ffca Mon Sep 17 00:00:00 2001 From: iggy Date: Mon, 1 Aug 2011 18:29:50 +0200 Subject: [PATCH 28/48] spaceinvaders improved --- firmware/applications/spaceinvaders.c | 155 +++++++++++++++++++------- firmware/lcd/fonts/invaders.c | 11 +- 2 files changed, 122 insertions(+), 44 deletions(-) diff --git a/firmware/applications/spaceinvaders.c b/firmware/applications/spaceinvaders.c index c774fd4..b6fc4c7 100644 --- a/firmware/applications/spaceinvaders.c +++ b/firmware/applications/spaceinvaders.c @@ -16,28 +16,43 @@ void delayms(uint32_t ms); #define ENEMY_COLUMNS 6 #define DISABLED 255 +#define TYPE_PLAYER 1 +#define TYPE_ENEMY_A 2 +#define TYPE_ENEMY_B 3 +#define TYPE_ENEMY_C 4 +static const ENEMY_WIDTHS[] = {10,11,8}; + struct gamestate { char player; char shot_x, shot_y; + char shots_x[ENEMY_COLUMNS]; + char shots_y[ENEMY_COLUMNS]; char alive; char move, direction, lastcol; - bool killed; + bool killed, step; + uint32_t score; + char level; + char rokets; char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; char enemy_row_y[ENEMY_ROWS]; -} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false}; +} game; char key; - -void checkISP(void) { - if(gpioGetValue(RB_BTN2)==0){ - gpioSetValue (RB_LED1, CFG_LED_ON); - delayms(200); - gpioSetValue (RB_LED1, CFG_LED_OFF); - while(gpioGetValue(RB_BTN0)==0); - EnableWatchdog(1000*5); - ReinvokeISP(); - } +void init_game(void) { + game.player = RESY/2-4; + game.shot_x = DISABLED; + game.shot_y = 0; + game.alive = ENEMY_ROWS*ENEMY_COLUMNS; + game.move = 0; + game.direction = -1; + game.lastcol = ENEMY_COLUMNS-1; + game.killed = false; + game.step = false; + init_enemy(); + for (char col=0; col= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) { + if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) { game.enemy_x[row][col]=DISABLED; game.shot_x = DISABLED; game.alive--; + game.score++; return; } } } } - game.shot_y -= 3; + game.shot_y -= 2; } +void move_shots() { + for (char col = 0; col= RESY) { + game.shots_x[col] = DISABLED; + return; + } + + //check for collision with player + game.shots_y[col] += 1; + } +} + + void move_player() { if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){ game.player-=1; @@ -99,6 +142,7 @@ void move_enemy() { return; } + game.step = !game.step; for (int col = 0; col < ENEMY_COLUMNS; col++) { for (int row = 0; row < ENEMY_ROWS; row++) { char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; @@ -109,10 +153,10 @@ void move_enemy() { } if((pos <=0 && game.direction != 1) || - (pos >=RESX-8-1 && game.direction == 1)){ + (pos >=RESX-11-1 && game.direction == 1)){ game.direction = (game.direction==1)?-1:1; for (char r = 0; r Date: Mon, 1 Aug 2011 20:03:12 +0200 Subject: [PATCH 29/48] Fix invader font --- firmware/lcd/fonts/invaders.c | 12 ++++++------ tools/font/bdf/invaders.xbdf | 16 ++++++++-------- tools/font/binary/invaders.f0n | Bin 112 -> 111 bytes 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/firmware/lcd/fonts/invaders.c b/firmware/lcd/fonts/invaders.c index a9f12f6..687f8a8 100644 --- a/firmware/lcd/fonts/invaders.c +++ b/firmware/lcd/fonts/invaders.c @@ -49,7 +49,7 @@ const uint8_t InvadersBitmaps[] = { 0x58, /* * ** */ - /* Char 80 is 7px wide @ 32 */ + /* Char 80 is 7px wide @ 31 */ 0xc0, /* ** */ 0xec, /* *** ** */ 0x7e, /* ****** */ @@ -59,7 +59,7 @@ const uint8_t InvadersBitmaps[] = { 0xc0, /* ** */ - /* Char 85 is 16px wide @ 39 */ + /* Char 85 is 16px wide @ 38 */ 0x20, /* * */ 0x30, /* ** */ 0x78, /* **** */ @@ -78,7 +78,7 @@ const uint8_t InvadersBitmaps[] = { 0x20, /* * */ - /* Char 97 is 11px wide @ 55 */ + /* Char 97 is 11px wide @ 54 */ 0x9e, /* * **** */ 0x38, /* *** */ 0x7d, /* ***** * */ @@ -92,7 +92,7 @@ const uint8_t InvadersBitmaps[] = { 0x9e, /* * **** */ - /* Char 98 is 12px wide @ 66 */ + /* Char 98 is 12px wide @ 65 */ 0x1c, /* *** */ 0x5e, /* * **** */ 0xfe, /* ******* */ @@ -107,7 +107,7 @@ const uint8_t InvadersBitmaps[] = { 0x1c, /* *** */ - /* Char 99 is 8px wide @ 78 */ + /* Char 99 is 8px wide @ 77 */ 0x98, /* * ** */ 0x5c, /* * *** */ 0xb6, /* * ** ** */ @@ -149,5 +149,5 @@ const struct FONT_DEF Font_Invaders = { * Name: Invaders * Height: 8 px (1 bytes) * Maximum width: 16 px - * Storage size: 94 bytes (uncompressed) + * Storage size: 93 bytes (uncompressed) */ diff --git a/tools/font/bdf/invaders.xbdf b/tools/font/bdf/invaders.xbdf index 5acd038..db97f72 100644 --- a/tools/font/bdf/invaders.xbdf +++ b/tools/font/bdf/invaders.xbdf @@ -41,14 +41,14 @@ ENDCHAR STARTCHAR alien3-1 ENCODING 67 XBITMAP -...xx.... -..xxxx... -.xxxxxx.. -xx.xx.xx. -xxxxxxxx. -.x.xxx.x. -x.......x -.x.....x. +...xx... +..xxxx.. +.xxxxxx. +xx.xx.xx +xxxxxxxx +.x.xx.x. +x......x +.x....x. ENDCHAR STARTCHAR alien1-2 diff --git a/tools/font/binary/invaders.f0n b/tools/font/binary/invaders.f0n index 9f5b2844f429e998ab0130b6b1f20c73aac75d65..11ece67d8565e9c6faebcac853dcda38b61a0030 100644 GIT binary patch delta 16 XcmXTOpCH1>F;P^JS!_?lL@P4@CQ1Z? delta 17 Ycmc~Vm>|N)IZ;%R#Y|?0!$eCn04dxAqW}N^ From cafdbed82f0448e2db9a6a842c990930d21d7314 Mon Sep 17 00:00:00 2001 From: iggy Date: Mon, 1 Aug 2011 21:44:48 +0200 Subject: [PATCH 30/48] bunkers in spaceinvaders --- firmware/applications/spaceinvaders.c | 96 ++++++++++++++++++--------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/firmware/applications/spaceinvaders.c b/firmware/applications/spaceinvaders.c index b6fc4c7..80e2edb 100644 --- a/firmware/applications/spaceinvaders.c +++ b/firmware/applications/spaceinvaders.c @@ -20,6 +20,10 @@ void delayms(uint32_t ms); #define TYPE_ENEMY_A 2 #define TYPE_ENEMY_B 3 #define TYPE_ENEMY_C 4 + +#define BUNKERS 2 +#define BUNKER_WIDTH 10 +static const BUNKER_X[] = {20,RESX-BUNKER_WIDTH-20}; static const ENEMY_WIDTHS[] = {10,11,8}; struct gamestate { @@ -29,13 +33,14 @@ struct gamestate { char shots_y[ENEMY_COLUMNS]; char alive; char move, direction, lastcol; - bool killed, step; + bool killed; + bool step; uint32_t score; char level; char rokets; char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; char enemy_row_y[ENEMY_ROWS]; - + uint8_t bunker[BUNKERS][BUNKER_WIDTH]; } game; char key; @@ -47,12 +52,19 @@ void init_game(void) { game.move = 0; game.direction = -1; game.lastcol = ENEMY_COLUMNS-1; - game.killed = false; + game.killed = 0; game.step = false; init_enemy(); + for (char col=0; colBUNKER_X[BUNKERS-1-b] && + game.shot_xRESY-16) { + int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]<<1; + game.shot_x=DISABLED; + } + } + } + //check for collision with enemy, kill enemy if for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { @@ -114,8 +140,29 @@ void move_shots() { game.shots_x[col] = DISABLED; return; } - + //check for collision with bunker + for (int b=0; bBUNKER_X[BUNKERS-1-b] && + game.shots_x[col]RESY-16) { + int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]>>1; + game.shots_x[col]=DISABLED; + } + } + } //check for collision with player + + if (game.shots_y[col] >= RESY-13 && + game.shots_x[col] > game.player+1 && + game.shots_x[col] < game.player+6) { + + game.killed = true; + } + + //move shots down game.shots_y[col] += 1; } } @@ -168,34 +215,6 @@ void move_enemy() { game.move = game.alive-1; } -void move_enemy2() { - if(game.move == 0) { - bool next = false; - for (int col = game.lastcol; col < ENEMY_COLUMNS || col <= 0; col+=game.direction) { - for (int row = 0; row < ENEMY_ROWS; row++) { - char pos = game.enemy_x[row][col]; - //There is an enemy on this row - if (pos != DISABLED) { - if((pos <=0 && game.direction== -1) || - (pos >=RESX-8 && game.direction == 1)){ - game.direction *= -1; - //TODOmove down - return; - } - game.enemy_x[row][col] += game.direction; - next = true; - } - } - if (next){ - game.lastcol += game.direction; - return; - } - } - game.move = game.alive; - return; - } - game.move--; -} void draw_player() { //draw_sprite(50, 20); draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); @@ -211,6 +230,12 @@ void draw_enemy() { } } +void draw_bunker() { + for (int b=0; b Date: Mon, 1 Aug 2011 23:34:13 +0200 Subject: [PATCH 31/48] added config options for menu --- firmware/applications/flame.c | 40 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/firmware/applications/flame.c b/firmware/applications/flame.c index 0b6ed48..387bae3 100644 --- a/firmware/applications/flame.c +++ b/firmware/applications/flame.c @@ -37,10 +37,20 @@ void ReinvokeISP(void); /**************************************************************************/ +//TODO SEC move to config +uint8_t flameBrightnessMax = 0xff; +uint8_t flameBrightnessMin = 0x00; +uint8_t flameSpeedUp = 0x01; +uint8_t flameSpeedDown = 0x01; +uint8_t flameWaitUp = 0xff; +uint8_t flameWaitDown = 0x8f; +//TODO SEC move to config + + uint8_t flameEnabled = 0; uint8_t flameMode = FLAME_OFF; uint8_t flameI2Cpwm = 0; -uint16_t flameTicks = 0; +uint8_t flameTicks = 0; uint32_t flameSetI2C(uint8_t cr, uint8_t value) { I2CMasterBuffer[0] = FLAME_I2C_WRITE; @@ -55,9 +65,17 @@ void setFlamePWM() { flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm } + void tick_flame(void) { // every 10ms flameTicks++; + if (flameI2Cpwm > flameBrightnessMax) { + flameI2Cpwm = flameBrightnessMax; + } + if (flameI2Cpwm < flameBrightnessMin) { + flameI2Cpwm = flameBrightnessMin; + } + if (flameMode == FLAME_OFF) { if (isNight() && flameEnabled) { flameTicks = 0; @@ -66,31 +84,39 @@ void tick_flame(void) { // every 10ms } if (flameMode == FLAME_UP) { - flameI2Cpwm++; + if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) { + flameI2Cpwm += flameSpeedUp; + } else { + flameI2Cpwm = 0xFF; + } push_queue(&setFlamePWM); - if (flameI2Cpwm == 0xFF) { + if (flameI2Cpwm == flameBrightnessMax) { flameMode = FLAME_UP_WAIT; flameTicks = 0; } } if (flameMode == FLAME_UP_WAIT) { - if (flameTicks > 0xFF) { + if (flameTicks >= flameWaitUp) { flameMode = FLAME_DOWN; } } if (flameMode == FLAME_DOWN) { - flameI2Cpwm--; + if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) { + flameI2Cpwm -= flameSpeedDown; + } else { + flameI2Cpwm = 0x00; + } push_queue(&setFlamePWM); - if (flameI2Cpwm == 0x00) { + if (flameI2Cpwm == flameBrightnessMin) { flameMode = FLAME_DOWN_WAIT; flameTicks = 0; } } if (flameMode == FLAME_DOWN_WAIT) { - if (flameTicks > 0x8F) { + if (flameTicks >= flameWaitDown) { flameMode = FLAME_OFF; } } From 5a6be961a0fcfadc2eadafd1e355470e6809816a Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 23:49:41 +0200 Subject: [PATCH 32/48] Fix the default background stuff properly. --- firmware/applications/default.c | 49 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 1cc168e..831adfb 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -31,41 +31,49 @@ void main_default(void) { return; }; + + +void queue_setinvert(void){ + lcdSetInvert(1); +}; +void queue_unsetinvert(void){ + lcdSetInvert(0); +}; + +#define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0) + // every 10 ms void tick_default(void) { static int ctr; ctr++; incTimer(); - if(ctr>1000/SYSTICKSPEED){ + + EVERY(1000,0){ if(!adcMutex){ VoltageCheck(); LightCheck(); - ctr=0; }else{ ctr--; }; }; - if(ctr>100/SYSTICKSPEED){ - if(isNight()){ - backlightSetBrightness(GLOBAL(lcdbacklight)); - lcdSetInvert(0); - } else { - backlightSetBrightness(0); - if(GLOBAL(dayinvert)) - lcdSetInvert(1); - else - lcdSetInvert(0); - } - } + static char night=0; + EVERY(100,2){ + if(night!=isNight()){ + night=isNight(); + if(night){ + backlightSetBrightness(GLOBAL(lcdbacklight)); + push_queue(queue_setinvert); + }else{ + backlightSetBrightness(0); + push_queue(queue_unsetinvert); + }; + }; + }; - if(ctr%(50/SYSTICKSPEED)==0){ - if(GetVoltage()<3600 -#ifdef SAFE - || GetVoltage() > 10000 // pin not connected -#endif - ){ + EVERY(50,0){ + if(GetVoltage()<3600){ IOCON_PIO1_11 = 0x0; gpioSetDir(RB_LED3, gpioDirection_Output); if( (ctr/(50/SYSTICKSPEED))%10 == 1 ) @@ -74,6 +82,5 @@ void tick_default(void) { gpioSetValue (RB_LED3, 0); }; }; - return; }; From 42fd4f116cc09eafead48038f2a2ac7040aa358f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 23:50:58 +0200 Subject: [PATCH 33/48] cleanup a bit --- firmware/applications/font.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/firmware/applications/font.c b/firmware/applications/font.c index a79b055..9e6b045 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -27,18 +27,6 @@ void f_init(void){ UINT readbytes; int res; - nrf_init(); - - struct NRF_CFG config = { - .channel= 81, - .txmac= "REMOT", - .nrmacs=1, - .mac0= "REMOT", - .maclen ="\x10", - }; - - nrf_config_set(&config); - res=f_open(&file[0], "nick.cfg", FA_OPEN_EXISTING|FA_READ); lcdPrint("open:"); lcdPrintln(f_get_rc_string(res)); @@ -79,7 +67,6 @@ void f_init(void){ char fontname[15]; void f_nick(void){ - static char ctr=0; char key; static signed char x=10; static signed char y=10; @@ -97,6 +84,7 @@ void f_nick(void){ lcdPrint("x"); lcdPrintInt(y); + lcdDisplay(); delayms(40); @@ -117,7 +105,6 @@ void f_nick(void){ lcdClear(); lcdPrintln("Done."); lcdDisplay(); - ctr++; break; }; }; From 4ed86ed5bc010725290f97661b228a8ef465c064 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 23:51:08 +0200 Subject: [PATCH 34/48] Fix fileselect0r (no files, down-scroll) --- firmware/filesystem/select.c | 90 ++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/firmware/filesystem/select.c b/firmware/filesystem/select.c index 74b4773..4f755ea 100644 --- a/firmware/filesystem/select.c +++ b/firmware/filesystem/select.c @@ -13,29 +13,30 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext) DIR dir; /* Directory object */ FILINFO Finfo; FRESULT res; - int ctr; int pos = 0; + int extlen = strlen(ext); res = f_opendir(&dir, "0:"); if(res){ //lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh(); return 0; }; - ctr=0; - while(1){ - res = f_readdir(&dir, &Finfo); - if ((res != FR_OK) || !Finfo.fname[0]) - break; - + while(f_readdir(&dir, &Finfo) == FR_OK && Finfo.fname[0]){ int len=strlen(Finfo.fname); - int extlen = strlen(ext); + + if(len0 ){ + skip--; continue; + }; + strcpy(files[pos++],Finfo.fname); if( pos == count ) break; @@ -43,6 +44,7 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext) return pos; } +#define PERPAGE 7 int selectFile(char *filename, char *extension) { int skip = 0; @@ -50,13 +52,29 @@ int selectFile(char *filename, char *extension) int selected = 0; font=&Font_7x8; while(1){ - char files[7][FLEN]; - int count = getFiles(files, 7, skip, extension); + char files[PERPAGE][FLEN]; + int count = getFiles(files, PERPAGE, skip, extension); + if(!count){ + lcdPrintln("No Files?"); + lcdRefresh(); + getInputWait(); + getInputWaitRelease(); + return -1; + }; + + if(count 0 ){ - selected--; - goto redraw; - }else{ - if( skip > 0 ){ - skip--; + switch(key){ + case BTN_DOWN: + if( selected < count-1 ){ + selected++; + goto redraw; + }else{ + skip++; } - } - }else if( key==BTN_LEFT ){ - return 1; - }else if( key==BTN_RIGHT ){ - strcpy(filename, files[selected]); - return 0; + break; + case BTN_UP: + if( selected > 0 ){ + selected--; + goto redraw; + }else{ + if( skip > 0 ){ + skip--; + } + } + break; + case BTN_LEFT: + return -1; + case BTN_ENTER: + case BTN_RIGHT: + strcpy(filename, files[selected]); + return 0; } } } From 60e31bbfafff13e766df5336af03589292c4195b Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 23:51:41 +0200 Subject: [PATCH 35/48] Add ReInit to be used after msc mode --- firmware/filesystem/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/firmware/filesystem/util.c b/firmware/filesystem/util.c index 0f3c939..2965656 100644 --- a/firmware/filesystem/util.c +++ b/firmware/filesystem/util.c @@ -1,3 +1,4 @@ +#include #include FATFS FatFs; /* File system object for logical drive */ @@ -23,6 +24,11 @@ void fsInit(){ f_mount(0, &FatFs); }; +void fsReInit(){ + f_mount(0, NULL); + f_mount(0, &FatFs); +}; + int readFile(char * filename, char * data, int len){ FIL file; UINT readbytes; From 162fd9775c6c4ffb92f5361f40037f542e87474d Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Mon, 1 Aug 2011 23:53:09 +0200 Subject: [PATCH 36/48] Whoops. Remove debugging info :) --- firmware/filesystem/select.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/firmware/filesystem/select.c b/firmware/filesystem/select.c index 4f755ea..6ca3c47 100644 --- a/firmware/filesystem/select.c +++ b/firmware/filesystem/select.c @@ -69,12 +69,7 @@ int selectFile(char *filename, char *extension) redraw: lcdClear(); - lcdPrint("Select file:"); - lcdSetCrsrX(40); - lcdPrint(IntToStr(skip,1,0)); - lcdPrint("/"); - lcdPrint(IntToStr(selected,1,0)); - lcdNl(); + lcdPrintln("Select file:"); for(int i=0; i Date: Tue, 2 Aug 2011 00:03:37 +0200 Subject: [PATCH 37/48] Saner code. --- firmware/basic/menu.c | 7 +++---- firmware/lcd/print.c | 11 +++++++++++ firmware/lcd/print.h | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 811e356..2216dd2 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -2,7 +2,6 @@ #include "basic/basic.h" -#include "lcd/render.h" #include "lcd/print.h" /**************************************************************************/ @@ -16,11 +15,11 @@ void handleMenu(const struct MENU *the_menu) { if (the_menu == NULL) return; -// font = &Font_7x8; // Font needs to be set externally? + setSystemFont(); for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); - visible_lines = (RESY/getFontHeight())-1; // subtract title line + visible_lines = lcdGetVisibleLines()-1; // subtract title line #ifdef SAFETY if (visible_lines < 2) return; #endif @@ -75,7 +74,7 @@ void handleMenu(const struct MENU *the_menu) { getInputWaitRelease(); if (the_menu->entries[menuselection]->callback!=NULL) the_menu->entries[menuselection]->callback(); - lcdDisplay(); + lcdRefresh(); getInputWait(); break; diff --git a/firmware/lcd/print.c b/firmware/lcd/print.c index 8466283..6f6ac75 100644 --- a/firmware/lcd/print.c +++ b/firmware/lcd/print.c @@ -2,6 +2,7 @@ #include #include #include +#include int x=0; int y=0; @@ -69,3 +70,13 @@ void lcdSetCrsr(int dx,int dy){ void lcdSetCrsrX(int dx){ x=dx; }; + +void setSystemFont(void){ + setIntFont(&Font_7x8); +}; + + +int lcdGetVisibleLines(void){ + return (RESY/getFontHeight()); // subtract title line +}; + diff --git a/firmware/lcd/print.h b/firmware/lcd/print.h index d1d8de5..dca2850 100644 --- a/firmware/lcd/print.h +++ b/firmware/lcd/print.h @@ -10,4 +10,5 @@ void lcdRefresh(); void lcdMoveCrsr(signed int dx,signed int dy); void lcdSetCrsr(int dx,int dy); void lcdSetCrsrX(int dx); - +void setSystemFont(void); +int lcdGetVisibleLines(void); From bad31c466aa01a15e7d9ce641f49f0a8aebc3be0 Mon Sep 17 00:00:00 2001 From: iggy Date: Tue, 2 Aug 2011 01:12:52 +0200 Subject: [PATCH 38/48] spacinvaders stuff --- firmware/applications/spaceinvaders.c | 338 -------------------------- firmware/loadable/spaceinvaders.c | 324 +++++++++++++++++++----- 2 files changed, 258 insertions(+), 404 deletions(-) delete mode 100644 firmware/applications/spaceinvaders.c diff --git a/firmware/applications/spaceinvaders.c b/firmware/applications/spaceinvaders.c deleted file mode 100644 index 80e2edb..0000000 --- a/firmware/applications/spaceinvaders.c +++ /dev/null @@ -1,338 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/render.h" -#include "lcd/display.h" -#include "lcd/allfonts.h" - -void ReinvokeISP(void); -void EnableWatchdog(uint32_t ms); -void delayms(uint32_t ms); - -/**************************************************************************/ -#define POS_PLAYER_Y 60 -#define ENEMY_ROWS 3 -#define ENEMY_COLUMNS 6 -#define DISABLED 255 - -#define TYPE_PLAYER 1 -#define TYPE_ENEMY_A 2 -#define TYPE_ENEMY_B 3 -#define TYPE_ENEMY_C 4 - -#define BUNKERS 2 -#define BUNKER_WIDTH 10 -static const BUNKER_X[] = {20,RESX-BUNKER_WIDTH-20}; -static const ENEMY_WIDTHS[] = {10,11,8}; - -struct gamestate { - char player; - char shot_x, shot_y; - char shots_x[ENEMY_COLUMNS]; - char shots_y[ENEMY_COLUMNS]; - char alive; - char move, direction, lastcol; - bool killed; - bool step; - uint32_t score; - char level; - char rokets; - char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; - char enemy_row_y[ENEMY_ROWS]; - uint8_t bunker[BUNKERS][BUNKER_WIDTH]; -} game; -char key; - -void init_game(void) { - game.player = RESY/2-4; - game.shot_x = DISABLED; - game.shot_y = 0; - game.alive = ENEMY_ROWS*ENEMY_COLUMNS; - game.move = 0; - game.direction = -1; - game.lastcol = ENEMY_COLUMNS-1; - game.killed = 0; - game.step = false; - init_enemy(); - - for (char col=0; colBUNKER_X[BUNKERS-1-b] && - game.shot_xRESY-16) { - int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); - if (game.bunker[b][offset]!=0) { - game.bunker[b][offset]&=game.bunker[b][offset]<<1; - game.shot_x=DISABLED; - } - } - } - - //check for collision with enemy, kill enemy if - for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { - for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) { - game.enemy_x[row][col]=DISABLED; - game.shot_x = DISABLED; - game.alive--; - game.score++; - return; - } - } - } - } - - game.shot_y -= 2; -} - -void move_shots() { - for (char col = 0; col= RESY) { - game.shots_x[col] = DISABLED; - return; - } - //check for collision with bunker - for (int b=0; bBUNKER_X[BUNKERS-1-b] && - game.shots_x[col]RESY-16) { - int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b]); - if (game.bunker[b][offset]!=0) { - game.bunker[b][offset]&=game.bunker[b][offset]>>1; - game.shots_x[col]=DISABLED; - } - } - } - //check for collision with player - - if (game.shots_y[col] >= RESY-13 && - game.shots_x[col] > game.player+1 && - game.shots_x[col] < game.player+6) { - - game.killed = true; - } - - //move shots down - game.shots_y[col] += 1; - } -} - - -void move_player() { - if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){ - game.player-=1; - } - - if(gpioGetValue(RB_BTN1)==0 && game.player < RESX-8){ - game.player+=1; - } - - if(gpioGetValue(RB_BTN4)==0 && game.shot_x == 255){ - game.shot_x = game.player+4; - game.shot_y = POS_PLAYER_Y; - } -} - -void move_enemy() { - if(game.move > 0){ - game.move--; - return; - } - - game.step = !game.step; - for (int col = 0; col < ENEMY_COLUMNS; col++) { - for (int row = 0; row < ENEMY_ROWS; row++) { - char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; - if (pos != DISABLED) { - //Check collision with player - if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){ - game.killed = true; - } - - if((pos <=0 && game.direction != 1) || - (pos >=RESX-11-1 && game.direction == 1)){ - game.direction = (game.direction==1)?-1:1; - for (char r = 0; rBUNKER_X[BUNKERS-1-b] && + game.shot_xRESY-16) { + int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]<<1; + game.shot_x=DISABLED; + } + } + } + //check for collision with enemy, kill enemy if for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) { + if(game.shot_x >= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) { game.enemy_x[row][col]=DISABLED; game.shot_x = DISABLED; game.alive--; + game.score++; return; } } } } - - game.shot_y -= 3; + //check for collision with ufo + if (game.ufo != DISABLED && + game.shot_x>game.ufo && + game.shot_x= RESY) { + game.shots_x[col] = DISABLED; + return; + } + //check for collision with bunker + for (int b=0; bBUNKER_X[BUNKERS-1-b] && + game.shots_x[col]RESY-16) { + int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]>>1; + game.shots_x[col]=DISABLED; + } + } + } + //check for collision with player + + if (game.shots_y[col] >= RESY-13 && + game.shots_x[col] > game.player+1 && + game.shots_x[col] < game.player+6) { + + game.killed = true; + } + + //move shots down + game.shots_y[col] += 1; + } +} + +void move_ufo() { + if (game.ufo == DISABLED) { + if ((getRandom()%UFO_PROB)==0) { + game.ufo = 0; + } + return; + } + if (game.ufo >= RESX){ + game.ufo = DISABLED; + return; + } + game.ufo++; } void move_player() { @@ -117,6 +267,7 @@ void move_enemy() { return; } + game.step = !game.step; for (int col = 0; col < ENEMY_COLUMNS; col++) { for (int row = 0; row < ENEMY_ROWS; row++) { char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; @@ -125,12 +276,27 @@ void move_enemy() { if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){ game.killed = true; } - + + //check for collision with bunker, dirty + for (int b=0; b=BUNKER_X[BUNKERS-1-b] && + pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && + game.enemy_row_y[row]+8RESY-16) { + int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]>>2; + } + } + } + + + //Are we at the beginning or end? Direction change if((pos <=0 && game.direction != 1) || - (pos >=RESX-8-1 && game.direction == 1)){ + (pos >=RESX-11-1 && game.direction == 1)){ game.direction = (game.direction==1)?-1:1; for (char r = 0; r=RESX-8 && game.direction == 1)){ - game.direction *= -1; - //TODOmove down - return; - } - game.enemy_x[row][col] += game.direction; - next = true; - } - } - if (next){ - game.lastcol += game.direction; - return; - } - } - game.move = game.alive; - return; - } - game.move--; -} void draw_player() { //draw_sprite(50, 20); - draw_sprite(TYPE_PLAYER,game.player, POS_PLAYER_Y); + draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); +} + +void draw_ufo() { + if (game.ufo!=DISABLED) + draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y); } void draw_enemy() { for (int row = 0; row Date: Tue, 2 Aug 2011 01:40:44 +0200 Subject: [PATCH 39/48] Mesh now supports non-timestamp but increasing messages. --- firmware/funk/mesh.c | 77 +++++++++++++++++++++++++------------------- firmware/funk/mesh.h | 2 ++ 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index 0bffc34..8e001e6 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -25,8 +25,26 @@ void initMesh(void){ meshbuffer[0].flags=MF_USED; }; -inline void blink(char a, char b){ - gpioSetValue (a,b, 1-gpioGetValue(a,b)); +MPKT * meshGetMessage(uint8_t type){ + int free=-1; + for(int i=0;iSECS_DAY) - meshbuffer[i].flags=MF_FREE; + if (MO_TYPE(meshbuffer[i].pkt)>='a' && + MO_TYPE(meshbuffer[i].pkt)<='z'){ + ; + }else{ + if (MO_TIME(meshbuffer[i].pkt)SECS_DAY) + meshbuffer[i].flags=MF_FREE; + }; }; }; }; @@ -83,37 +106,22 @@ void mesh_recvloop(void){ }; // Safety: Truncate ascii packets by 0-ing the CRC - if (MO_TYPE(buf) >='A' && MO_TYPE(buf) <='Z'){ - buf[MESHPKTSIZE-2]=0; - }; + buf[MESHPKTSIZE-2]=0; - // Store packet in a free slot - int free=-1; - for(int i=0;i - MO_TIME(meshbuffer[i].pkt)){ - free=i; - break; - }else{ - free=-2; - break; - }; - }; - }; + // Store packet in a same/free slot + MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); - if(free==-1){ // Buffer full. Ah well. Kill a random packet - free=1; // XXX: GetRandom()? - }; - - if(free<0) + // Skip locked packet + if(mpkt->flags&MF_LOCK) continue; - memcpy(meshbuffer[free].pkt,buf,MESHPKTSIZE); - meshbuffer[free].flags=MF_USED; + // only accept newer/better packets + if(mpkt->flags==MF_USED) + if(MO_TIME(buf)pkt)) + continue; + + memcpy(mpkt->pkt,buf,MESHPKTSIZE); + mpkt->flags=MF_USED; }while(getTimer()MESHBUFSIZE); @@ -137,6 +145,8 @@ void mesh_sendloop(void){ for (int i=0;i Date: Tue, 2 Aug 2011 02:09:37 +0200 Subject: [PATCH 40/48] Config variables for flame --- firmware/basic/config.c | 6 ++++++ firmware/basic/config.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 396e500..4393798 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -11,6 +11,7 @@ struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, + // dflt min max {"privacy", 3, 0, 2 }, {"daytrig", 310/2, 0, 255}, {"daytrighyst", 10, 0, 50 }, @@ -19,6 +20,11 @@ struct CDESC the_config[]= { {"lcdmirror", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 }, {"lcdcontrast", 3, 0, 31 }, + {"flamemax", 255, 0, 255}, + {"flamemin", 0, 0, 255}, + {"flamespeed", 1, 1, 100}, + {"flamemaxw", 255, 1, 255}, + {"flameminw", 0x8f, 1, 255}, { NULL, 0, 0, 0 }, }; diff --git a/firmware/basic/config.h b/firmware/basic/config.h index c4419c5..66365f9 100644 --- a/firmware/basic/config.h +++ b/firmware/basic/config.h @@ -27,6 +27,11 @@ extern char nickfont[]; #define GLOBALlcdmirror (the_config[6].value) #define GLOBALlcdinvert (the_config[7].value) #define GLOBALlcdcontrast (the_config[8].value) +#define GLOBALflamemax (the_config[9].value) +#define GLOBALflamemin (the_config[10].value) +#define GLOBALflamespeed (the_config[11].value) +#define GLOBALflamemaxw (the_config[12].value) +#define GLOBALflameminw (the_config[13].value) #define GLOBALnickname (nickname) #define GLOBALnickfont (nickfont) From 0824a2cd25edbe71a8b02ed936bb6f24a817da34 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 02:10:15 +0200 Subject: [PATCH 41/48] Some stuff we probably want in the final firmware. --- firmware/applications/final.c | 37 ++++ firmware/applications/final/config.c | 126 +++++++++++ firmware/applications/final/flame.c | 137 ++++++++++++ firmware/applications/final/mesh.c | 286 +++++++++++++++++++++++++ firmware/applications/final/nickname.c | 83 +++++++ firmware/applications/final/util.c | 129 +++++++++++ firmware/applications/final/uuid.c | 26 +++ 7 files changed, 824 insertions(+) create mode 100644 firmware/applications/final.c create mode 100644 firmware/applications/final/config.c create mode 100644 firmware/applications/final/flame.c create mode 100644 firmware/applications/final/mesh.c create mode 100644 firmware/applications/final/nickname.c create mode 100644 firmware/applications/final/util.c create mode 100644 firmware/applications/final/uuid.c diff --git a/firmware/applications/final.c b/firmware/applications/final.c new file mode 100644 index 0000000..16525d0 --- /dev/null +++ b/firmware/applications/final.c @@ -0,0 +1,37 @@ +#include + +#include "basic/basic.h" + +#include "lcd/print.h" + +#include + +/**************************************************************************/ + +#include "final.gen" + +static const struct MENU mainmenu = {"Menu", mentry}; + +void initNick(); +void fancyNickname(); + +void main_final(void) { + //checkFirstBoot(); + + initNick(); + while(1){ +#ifndef FINAL + if(getInputRaw()==BTN_LEFT) + ISPandReset(); +#endif + if(getInput()){ + handleMenu(&mainmenu); + getInputWaitRelease(); + initNick(); + }; + fancyNickname(); + delayms_queue(100); + }; +}; + +void tick_final(void); diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c new file mode 100644 index 0000000..1451483 --- /dev/null +++ b/firmware/applications/final/config.c @@ -0,0 +1,126 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/print.h" +#include "lcd/render.h" +#include "lcd/display.h" + +#include "filesystem/ff.h" + +#include + +/**************************************************************************/ + +void readcfg(void) { + readConfig(); +}; + +void savecfg(void){ + saveConfig(); +}; + +void applycfg(void){ + applyConfig(); +}; + +void changer(void){ + uint8_t numentries = 0; + signed char menuselection = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + for (int i=0;the_config[i].name!=NULL;i++){ + numentries++; + }; + + visible_lines = ((RESY/getFontHeight())-1)/2; + + while (1) { + // Display current menu page + lcdClear(); + lcdPrint("Config"); + + lcdSetCrsrX(60); + lcdPrint("["); + lcdPrint(IntToStr(current_offset/visible_lines,1,0)); + lcdPrint("/"); + lcdPrint(IntToStr(numentries/visible_lines,1,0)); + lcdPrint("]"); + lcdNl(); + + lcdNl(); + + for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { + if(i==0){ + lcdPrintln("Save changes:"); + if (i == menuselection) + lcdPrint("*"); + lcdSetCrsrX(14); + if (i == menuselection) + lcdPrintln("YES"); + else + lcdPrintln("no"); + }else{ + lcdPrintln(the_config[i].name); + if (i == menuselection) + lcdPrint("*"); + lcdSetCrsrX(14); + lcdPrint("<"); + lcdPrint(IntToStr(the_config[i].value,3,F_LONG)); + lcdPrintln(">"); + }; + } + lcdRefresh(); + + switch (getInputWait()) { + case BTN_UP: + menuselection--; + if (menuselection < current_offset) { + if (menuselection < 0) { + menuselection = numentries-1; + current_offset = ((numentries-1)/visible_lines) * visible_lines; + } else { + current_offset -= visible_lines; + } + } + break; + case BTN_DOWN: + menuselection++; + if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + if(the_config[menuselection].value > + the_config[menuselection].min) + the_config[menuselection].value--; + if(the_config[menuselection].value > the_config[menuselection].max) + the_config[menuselection].value= + the_config[menuselection].max; + applyConfig(); + break; + case BTN_RIGHT: + if(the_config[menuselection].value < + the_config[menuselection].max) + the_config[menuselection].value++; + if(the_config[menuselection].value < the_config[menuselection].min) + the_config[menuselection].value= + the_config[menuselection].min; + applyConfig(); + break; + case BTN_ENTER: + if(menuselection==0) + saveConfig(); + return; + } + getInputWaitRelease(); + } + /* NOTREACHED */ +} diff --git a/firmware/applications/final/flame.c b/firmware/applications/final/flame.c new file mode 100644 index 0000000..a67175c --- /dev/null +++ b/firmware/applications/final/flame.c @@ -0,0 +1,137 @@ +/* + + flame m0dul - https://github.com/kiu/flame + +*/ + +#include "basic/basic.h" +#include "core/i2c/i2c.h" +#include "basic/config.h" + +#define FLAME_I2C_WRITE 0xC4 +#define FLAME_I2C_READ 0xC5 + +#define FLAME_I2C_CR_INPUT 0x00 +#define FLAME_I2C_CR_PSC0 0x01 +#define FLAME_I2C_CR_PWM0 0x02 +#define FLAME_I2C_CR_PSC1 0x03 +#define FLAME_I2C_CR_PWM1 0x04 +#define FLAME_I2C_CR_LS0 0x05 + +#define FLAME_I2C_LS0_OFF 0x00 +#define FLAME_I2C_LS0_ON 0x01 +#define FLAME_I2C_LS0_PWM0 0x02 +#define FLAME_I2C_LS0_PWM1 0x03 + +#define FLAME_I2C_LS0_LED0 0x00 +#define FLAME_I2C_LS0_LED1 0x02 +#define FLAME_I2C_LS0_LED2 0x04 +#define FLAME_I2C_LS0_LED3 0x06 + +#define FLAME_OFF 0x00 +#define FLAME_UP 0x01 +#define FLAME_UP_WAIT 0x02 +#define FLAME_DOWN 0x03 +#define FLAME_DOWN_WAIT 0x04 + +/**************************************************************************/ + +#define flameBrightnessMax GLOBAL(flamemax) +#define flameBrightnessMin GLOBAL(flamemin) +#define flameSpeedUp GLOBAL(flamespeed) +#define flameSpeedDown GLOBAL(flamespeed) +#define flameWaitUp GLOBAL(flamemaxw) +#define flameWaitDown GLOBAL(flameminw) + +uint8_t flameEnabled = 0; +uint8_t flameMode = FLAME_OFF; +uint8_t flameI2Cpwm = 0; +uint8_t flameTicks = 0; + +uint32_t flameSetI2C(uint8_t cr, uint8_t value) { + I2CMasterBuffer[0] = FLAME_I2C_WRITE; + I2CMasterBuffer[1] = cr; + I2CMasterBuffer[2] = value; + I2CWriteLength = 3; + I2CReadLength = 0; + return i2cEngine(); +} + +void setFlamePWM() { + flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm +} + + +void tick_flame(void) { // every 10ms + flameTicks++; + + if (flameI2Cpwm > flameBrightnessMax) { + flameI2Cpwm = flameBrightnessMax; + } + if (flameI2Cpwm < flameBrightnessMin) { + flameI2Cpwm = flameBrightnessMin; + } + + if (flameMode == FLAME_OFF) { + if (isNight() && flameEnabled) { + flameTicks = 0; + flameMode = FLAME_UP; + } + } + + if (flameMode == FLAME_UP) { + if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) { + flameI2Cpwm += flameSpeedUp; + } else { + flameI2Cpwm = 0xFF; + } + push_queue(&setFlamePWM); + if (flameI2Cpwm == flameBrightnessMax) { + flameMode = FLAME_UP_WAIT; + flameTicks = 0; + } + } + + if (flameMode == FLAME_UP_WAIT) { + if (flameTicks >= flameWaitUp) { + flameMode = FLAME_DOWN; + } + } + + if (flameMode == FLAME_DOWN) { + if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) { + flameI2Cpwm -= flameSpeedDown; + } else { + flameI2Cpwm = 0x00; + } + push_queue(&setFlamePWM); + if (flameI2Cpwm == flameBrightnessMin) { + flameMode = FLAME_DOWN_WAIT; + flameTicks = 0; + } + } + + if (flameMode == FLAME_DOWN_WAIT) { + if (flameTicks >= flameWaitDown) { + flameMode = FLAME_OFF; + } + } +} + +void flameInit(void) { + + i2cInit(I2CMASTER); // Init I2C + + flameEnabled = (flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0) == I2CSTATE_ACK); // probe i2c + + if (flameEnabled) { + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0); // set led0 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED1); // set led1 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED2); // set led2 off + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED3); // set led3 off + + flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler + flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm + flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm + } +} diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c new file mode 100644 index 0000000..c6d1f63 --- /dev/null +++ b/firmware/applications/final/mesh.c @@ -0,0 +1,286 @@ +#include +#include +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include "funk/mesh.h" + +#include + +/**************************************************************************/ + +void m_init(void){ + nrf_init(); + + struct NRF_CFG config = { + .channel= MESH_CHANNEL, + .txmac= MESH_MAC, + .nrmacs=1, + .mac0= MESH_MAC, + .maclen ="\x20", // XXX: MESHPKTSIZE + }; + + nrf_config_set(&config); + + initMesh(); +}; + +void m_tset(void){ + _timet=1311961112; +}; + +void m_time(void){ + struct tm* tm; + char c[2]={0,0}; + getInputWaitRelease(); + delayms(100); + do{ + lcdClear(); + tm= mygmtime(getSeconds()); + lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); + lcdNl(); + lcdPrint(IntToStr(tm->tm_mday,2,F_LONG)); + lcdPrint("."); + lcdPrint(IntToStr(tm->tm_mon+1,2,0)); + lcdPrint("."); + lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS)); + lcdNl(); + + lcdNl(); + lcdPrint("<"); + + for(int i=0;i"); + + lcdPrint("Gen:"); + lcdPrintInt(meshgen); + lcdNl(); + lcdRefresh(); + delayms_queue(50); + }while ((getInputRaw())==BTN_NONE); +}; + + +inline void blink(char a, char b){ + gpioSetValue (a,b, 1-gpioGetValue(a,b)); +}; + + +int choose(char * texts, int8_t menuselection){ + uint8_t numentries = 0; + uint8_t visible_lines = 0; + uint8_t current_offset = 0; + + char*p=texts; + + do{ + lcdPrintln(p); + while(*p)p++; + numentries++;p++; + }while(*p); + numentries--; + + visible_lines = (RESY/getFontHeight())-1; // subtract title line + + while (1) { + // Display current menu page + lcdClear(); + lcdPrintln(texts); + p=texts; + while(*p++); + for(int i=0;i (current_offset + visible_lines-1) || menuselection >= numentries) { + if (menuselection >= numentries) { + menuselection = 0; + current_offset = 0; + } else { + current_offset += visible_lines; + } + } + break; + case BTN_LEFT: + return -1; + case BTN_RIGHT: + case BTN_ENTER: + return menuselection; + } + getInputWaitRelease(); + } + /* NOTREACHED */ +} + + + +/***********************************************************************/ + +char *meshmsgs(void){ + static char msgtypes[MESHBUFSIZE+1]; + memset(msgtypes,'_',MESHBUFSIZE); + msgtypes[MESHBUFSIZE]=0; + uint8_t lo=0; + uint8_t hi; + + for(int o=0;olo) + if(MO_TYPE(meshbuffer[i].pkt)='a' && tmm[i]<='z'){ + lcdPrintln(IntToStr(MO_TIME(meshbuffer[j].pkt),10,0)); + }else{ + struct tm *tm= mygmtime(MO_TIME(meshbuffer[j].pkt)); + lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS)); + lcdPrint(":"); + lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); + lcdNl(); + }; + char *foo=(char *)MO_BODY(meshbuffer[j].pkt); + while(strlen(foo)>13){ + int q; + for(q=0;q<13;q++){ + if(foo[q]==' ') + break; + }; + foo[q]=0; + lcdPrintln(foo); + foo[q]=' '; + foo+=q+1; + }; + lcdPrintln(foo); + lcdRefresh(); + getInputWaitRelease(); + }; +}; + + +void tick_mesh(void){ + mesh_systick(); +}; + diff --git a/firmware/applications/final/nickname.c b/firmware/applications/final/nickname.c new file mode 100644 index 0000000..9eb46c7 --- /dev/null +++ b/firmware/applications/final/nickname.c @@ -0,0 +1,83 @@ +#include +#include +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "filesystem/ff.h" +#include "filesystem/select.h" + +#include + +/**************************************************************************/ + +void fancyNickname(void) { + int dx=0; + int dy=0; + static uint32_t ctr=0; + ctr++; + + + lcdClear(); + setExtFont(GLOBAL(nickfont)); + DoString(dx,dy,GLOBAL(nickname)); + lcdRefresh(); + + return; +} + +/**************************************************************************/ + +void initNick(void){ + readFile("nick.cfg",GLOBAL(nickname),MAXNICK); +// readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN); +}; + +void doNick(void){ + input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1); + writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); + getInputWait(); +}; + +void doFont(void){ + getInputWaitRelease(); + if( selectFile(GLOBAL(nickfont),"F0N") != 0){ + lcdPrintln("No file selected."); + return; + }; + + lcdClear(); + lcdPrintln(GLOBAL(nickfont)); + setExtFont(GLOBAL(nickfont)); + lcdPrintln("PUabc€"); + setIntFont(&Font_7x8); + lcdPrintln("done."); + lcdDisplay(); + while(!getInputRaw())delayms(10); +}; + + +#if 0 + void f_font(void){ + + if( selectFile(fontname,"F0N") != 0){ + lcdPrintln("No file selected."); + return; + }; + + lcdClear(); + lcdPrintln(fontname); + setExtFont(fontname); + lcdPrintln("PUabc€"); + setIntFont(&Font_7x8); + lcdPrintln("done."); + lcdDisplay(); + while(!getInputRaw())delayms(10); +}; + +#endif diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c new file mode 100644 index 0000000..a648a81 --- /dev/null +++ b/firmware/applications/final/util.c @@ -0,0 +1,129 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "lcd/allfonts.h" + +#include "filesystem/ff.h" +#include "filesystem/select.h" +#include "funk/nrf24l01p.h" +#include "usb/usbmsc.h" + +#include + +/**************************************************************************/ + +void show_ticks(void) { + int dx=0; + int dy=8; + lcdClear(); + dx=DoString(0,dy,"Ticks:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(0,dy+8,_timectr); + lcdDisplay(); + }; + dy+=16; + dx=DoString(0,dy,"Done."); +}; + + +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; +void adc_light(void) { + int dx=0; + int dy=8; + dx=DoString(0,dy,"Light:"); + DoString(0,dy+16,"Night:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetLight()); + DoInt(dx,dy+16,isNight()); + DoInt(dx,dy+8,GLOBAL(daytrig)); + lcdDisplay(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +void uptime(void) { + int t; + int h; + char flag; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Uptime:"); + t=getTimer()/(1000/SYSTICKSPEED); + h=t/60/60; + flag=F_ZEROS; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("h"); + flag|=F_LONG; + }; + h=t/60%60; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("m"); + flag|=F_LONG; + }; + h=t%60; + if(h>0){ + lcdPrint(IntToStr(h,2,flag)); + lcdPrint("s"); + }; + lcdNl(); + lcdRefresh(); + delayms_queue(200); + }; + lcdPrintln("done."); +}; + +void gotoISP(void) { + DoString(0,0,"Enter ISP!"); + lcdDisplay(); + ISPandReset(); +} + +void lcd_mirror(void) { + lcdToggleFlag(LCD_MIRRORX); +}; + +void lcd_invert(void) { + lcdToggleFlag(LCD_INVERTED); +}; + +void adc_check(void) { + int dx=0; + int dy=8; + // Print Voltage + dx=DoString(0,dy,"Voltage:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetVoltage()); + lcdDisplay(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +void msc_menu(void){ + DoString(0,8,"MSC Enabled."); + lcdDisplay(); + usbMSCInit(); + getInputWaitRelease(); + getInputWait(); + DoString(0,16,"MSC Disabled."); + usbMSCOff(); + fsReInit(); +}; diff --git a/firmware/applications/final/uuid.c b/firmware/applications/final/uuid.c new file mode 100644 index 0000000..601a5f7 --- /dev/null +++ b/firmware/applications/final/uuid.c @@ -0,0 +1,26 @@ +#include + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include + +#include "funk/rftransfer.h" +#include "funk/openbeacon.h" + +#include "core/iap/iap.h" + +/**************************************************************************/ + +void f_uuid(void) { + IAP_return_t iap_return; + iap_return = iapReadSerialNumber(); + lcdPrintIntHex(iap_return.Result[0]); lcdNl(); + lcdPrintIntHex(iap_return.Result[1]); lcdNl(); + lcdPrintIntHex(iap_return.Result[2]); lcdNl(); + lcdPrintIntHex(iap_return.Result[3]); lcdNl(); +} From d357e6000fd1e6dfbb22376b00758dbe9dde7321 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 02:45:25 +0200 Subject: [PATCH 42/48] Clean up util.c --- firmware/applications/final/util.c | 113 ++++++++++------------------- firmware/applications/final/uuid.c | 26 ------- 2 files changed, 40 insertions(+), 99 deletions(-) delete mode 100644 firmware/applications/final/uuid.c diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index a648a81..9876ea4 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -1,48 +1,18 @@ #include +#include #include "basic/basic.h" #include "basic/config.h" -#include "lcd/lcd.h" #include "lcd/print.h" -#include "lcd/allfonts.h" -#include "filesystem/ff.h" -#include "filesystem/select.h" -#include "funk/nrf24l01p.h" #include "usb/usbmsc.h" -#include +#include "core/iap/iap.h" /**************************************************************************/ -void show_ticks(void) { - int dx=0; - int dy=8; - lcdClear(); - dx=DoString(0,dy,"Ticks:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(0,dy+8,_timectr); - lcdDisplay(); - }; - dy+=16; - dx=DoString(0,dy,"Done."); -}; - - -void chrg_stat(void) { - int stat; - while ((getInputRaw())==BTN_NONE){ - lcdClear(); - lcdPrintln("Chrg_stat:"); - stat=gpioGetValue(RB_PWR_CHRG); - lcdPrint(IntToStr(stat,3,0)); - lcdNl(); - lcdRefresh(); - }; - lcdPrintln("Done."); -}; -void adc_light(void) { +void ChkLight(void) { int dx=0; int dy=8; dx=DoString(0,dy,"Light:"); @@ -52,10 +22,27 @@ void adc_light(void) { DoInt(dx,dy+16,isNight()); DoInt(dx,dy+8,GLOBAL(daytrig)); lcdDisplay(); + delayms_queue(100); }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; + dx=DoString(0,dy+24,"Done."); +} + +void ChkBattery(void) { + do{ + lcdClear(); + lcdPrintln("Voltage:"); + lcdPrintln(IntToStr(GetVoltage(),5,0)); + lcdNl(); + lcdPrintln("Chrg_stat:"); + if(gpioGetValue(RB_PWR_CHRG)){ + lcdPrintln("1"); + }else{ + lcdPrintln("0"); + }; + lcdRefresh(); + delayms_queue(100); + } while ((getInputRaw())==BTN_NONE); +} void uptime(void) { int t; @@ -84,46 +71,26 @@ void uptime(void) { lcdPrint("s"); }; lcdNl(); + lcdNl(); + lcdPrintln("Ticks:"); + lcdPrint(IntToStr(_timectr,10,0)); lcdRefresh(); delayms_queue(200); }; lcdPrintln("done."); -}; - -void gotoISP(void) { - DoString(0,0,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); } -void lcd_mirror(void) { - lcdToggleFlag(LCD_MIRRORX); -}; - -void lcd_invert(void) { - lcdToggleFlag(LCD_INVERTED); -}; - -void adc_check(void) { - int dx=0; - int dy=8; - // Print Voltage - dx=DoString(0,dy,"Voltage:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetVoltage()); - lcdDisplay(); - }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; - -void msc_menu(void){ - DoString(0,8,"MSC Enabled."); - lcdDisplay(); - usbMSCInit(); - getInputWaitRelease(); - getInputWait(); - DoString(0,16,"MSC Disabled."); - usbMSCOff(); - fsReInit(); -}; +void uuid(void) { + IAP_return_t iap_return; + iap_return = iapReadSerialNumber(); + lcdClear(); + lcdPrintln("UUID:"); + lcdPrintIntHex(iap_return.Result[0]); lcdNl(); + lcdPrintIntHex(iap_return.Result[1]); lcdNl(); + lcdPrintIntHex(iap_return.Result[2]); lcdNl(); + lcdPrintIntHex(iap_return.Result[3]); lcdNl(); + lcdNl(); + lcdPrintln("Beacon ID:"); + lcdPrintln(IntToStrX(GetUUID32(),4)); + lcdRefresh(); +} diff --git a/firmware/applications/final/uuid.c b/firmware/applications/final/uuid.c deleted file mode 100644 index 601a5f7..0000000 --- a/firmware/applications/final/uuid.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/lcd.h" -#include "lcd/print.h" - -#include "funk/nrf24l01p.h" - -#include - -#include "funk/rftransfer.h" -#include "funk/openbeacon.h" - -#include "core/iap/iap.h" - -/**************************************************************************/ - -void f_uuid(void) { - IAP_return_t iap_return; - iap_return = iapReadSerialNumber(); - lcdPrintIntHex(iap_return.Result[0]); lcdNl(); - lcdPrintIntHex(iap_return.Result[1]); lcdNl(); - lcdPrintIntHex(iap_return.Result[2]); lcdNl(); - lcdPrintIntHex(iap_return.Result[3]); lcdNl(); -} From 942440ec0caa8b402c5254deb38ad16da74d0bd1 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:50:51 +0200 Subject: [PATCH 43/48] Whoops. Swapped day/night invert --- firmware/applications/default.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index 831adfb..eed6119 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -63,10 +63,10 @@ void tick_default(void) { night=isNight(); if(night){ backlightSetBrightness(GLOBAL(lcdbacklight)); - push_queue(queue_setinvert); + push_queue(queue_unsetinvert); }else{ backlightSetBrightness(0); - push_queue(queue_unsetinvert); + push_queue(queue_setinvert); }; }; }; From 999b3bd80998873a1a316ebceeade916355b2c8f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:51:34 +0200 Subject: [PATCH 44/48] Properly turn off flame when it's day. Also: skip everything if disabled. And: debugging display --- firmware/applications/final/flame.c | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/firmware/applications/final/flame.c b/firmware/applications/final/flame.c index a67175c..d010671 100644 --- a/firmware/applications/final/flame.c +++ b/firmware/applications/final/flame.c @@ -61,8 +61,21 @@ void setFlamePWM() { flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm } - void tick_flame(void) { // every 10ms + static char night=0; + + if(!flameEnabled) + return; + + if(night!=isNight()){ + night=isNight(); + if(!night){ + flameMode = FLAME_OFF; + flameI2Cpwm = 0; + push_queue(&setFlamePWM); + }; + }; + flameTicks++; if (flameI2Cpwm > flameBrightnessMax) { @@ -135,3 +148,24 @@ void flameInit(void) { flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm } } + +#include "lcd/print.h" + +void ChkFlame(void) { + do{ + lcdClear(); + lcdPrint("Enabled:"); + lcdPrintln(IntToStr(flameEnabled,1,0)); + + lcdPrint("State:"); + lcdPrintln(IntToStr(flameMode,1,0)); + + lcdPrint("PWMtarg:"); + lcdPrintln(IntToStr(flameI2Cpwm,3,0)); + + lcdPrint("FTicks:"); + lcdPrintln(IntToStr(flameTicks,3,0)); + + lcdRefresh(); + } while ((getInputRaw())==BTN_NONE); +} From 3c3d1032c5d87a44304826df005ac66f68568538 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:54:05 +0200 Subject: [PATCH 45/48] Correct default for contrast setting. Add alivecheck(systick blink) setting --- firmware/basic/config.c | 5 +++-- firmware/basic/config.h | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 4393798..84f6d5a 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 24 +#define CFGVER 1 struct CDESC the_config[]= { {"version", CFGVER, CFGVER, CFGVER}, @@ -19,7 +19,8 @@ struct CDESC the_config[]= { {"lcdbacklight", 50, 0, 100}, {"lcdmirror", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 }, - {"lcdcontrast", 3, 0, 31 }, + {"lcdcontrast", 14, 0, 31 }, + {"alivechk", 0, 0, 2 }, {"flamemax", 255, 0, 255}, {"flamemin", 0, 0, 255}, {"flamespeed", 1, 1, 100}, diff --git a/firmware/basic/config.h b/firmware/basic/config.h index 66365f9..bcd4f98 100644 --- a/firmware/basic/config.h +++ b/firmware/basic/config.h @@ -18,20 +18,21 @@ extern struct CDESC the_config[]; extern char nickname[MAXNICK]; extern char nickfont[]; -#define GLOBALversion (the_config[0].value) -#define GLOBALprivacy (the_config[1].value) -#define GLOBALdaytrig (the_config[2].value) -#define GLOBALdaytrighyst (the_config[3].value) -#define GLOBALdayinvert (the_config[4].value) -#define GLOBALlcdbacklight (the_config[5].value) -#define GLOBALlcdmirror (the_config[6].value) -#define GLOBALlcdinvert (the_config[7].value) -#define GLOBALlcdcontrast (the_config[8].value) -#define GLOBALflamemax (the_config[9].value) -#define GLOBALflamemin (the_config[10].value) -#define GLOBALflamespeed (the_config[11].value) -#define GLOBALflamemaxw (the_config[12].value) -#define GLOBALflameminw (the_config[13].value) +#define GLOBALversion (the_config[ 0].value) +#define GLOBALprivacy (the_config[ 1].value) +#define GLOBALdaytrig (the_config[ 2].value) +#define GLOBALdaytrighyst (the_config[ 3].value) +#define GLOBALdayinvert (the_config[ 4].value) +#define GLOBALlcdbacklight (the_config[ 5].value) +#define GLOBALlcdmirror (the_config[ 6].value) +#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 GLOBALnickname (nickname) #define GLOBALnickfont (nickfont) From 7eaa5f4e4b51454e2c4e7dd852b1d74fcde84f23 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 2 Aug 2011 10:55:01 +0200 Subject: [PATCH 46/48] more utility/debugging/info stuff --- firmware/applications/final/util.c | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index 9876ea4..401a3f5 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -4,6 +4,7 @@ #include "basic/basic.h" #include "basic/config.h" +#include "lcd/render.h" #include "lcd/print.h" #include "usb/usbmsc.h" @@ -40,7 +41,7 @@ void ChkBattery(void) { lcdPrintln("0"); }; lcdRefresh(); - delayms_queue(100); +// delayms_queue(100); } while ((getInputRaw())==BTN_NONE); } @@ -94,3 +95,40 @@ void uuid(void) { lcdPrintln(IntToStrX(GetUUID32(),4)); lcdRefresh(); } + +void Qstatus(void) { + int dx=0; + int dy=8; + lcdClear(); + dx=DoString(0,dy+16,"Qdepth:"); + while ((getInputRaw())!=BTN_ENTER){ + DoInt(dx,dy+16,(the_queue.qend-the_queue.qstart+MAXQENTRIES)%MAXQENTRIES); + lcdDisplay(); + if(getInputRaw()!=BTN_NONE) + work_queue(); + else + delayms(10); + }; + dy+=16; + dx=DoString(0,dy,"Done."); +}; + +void blink_led0(void){ + gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0)); +}; + +void tick_alive(void){ + static int foo=0; + + if(GLOBAL(alivechk)==0) + return; + + if(foo++>500/SYSTICKSPEED){ + foo=0; + if(GLOBAL(alivechk)==2) + push_queue(blink_led0); + else + blink_led0(); + }; + return; +}; From d5dd653fbe6d8f87b4c3ee7675c1cfee0290fe21 Mon Sep 17 00:00:00 2001 From: iggy Date: Tue, 2 Aug 2011 13:09:58 +0200 Subject: [PATCH 47/48] invaders stuff --- firmware/loadable/spaceinvaders.c | 232 ++++++++++++++++++++---------- 1 file changed, 154 insertions(+), 78 deletions(-) diff --git a/firmware/loadable/spaceinvaders.c b/firmware/loadable/spaceinvaders.c index a9814fb..7e482f6 100644 --- a/firmware/loadable/spaceinvaders.c +++ b/firmware/loadable/spaceinvaders.c @@ -17,7 +17,7 @@ void delayms(uint32_t ms); #define ENEMY_COLUMNS 6 #define DISABLED 255 -#define UFO_PROB 100 +#define UFO_PROB 1000 #define TYPE_PLAYER 1 #define TYPE_ENEMY_A 2 @@ -42,7 +42,7 @@ struct gamestate { bool step; uint32_t score; char level; - char rokets; + int8_t rokets; char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; char enemy_row_y[ENEMY_ROWS]; uint8_t bunker[BUNKERS][BUNKER_WIDTH]; @@ -61,34 +61,87 @@ void draw_player(); void draw_enemy(); void draw_shots(); void draw_ufo(); +void screen_intro(); +void screen_gameover(); +void screen_level(); +bool check_bunker(char xpos, char ypos, int8_t shift); void ram(void) { - gpioSetValue (RB_LED1, CFG_LED_OFF); - backlightInit(); - - init_game(); - game.rokets = 3; - while (1) { - ////checkISP(); - lcdFill(0); - check_end(); - move_ufo(); - move_shot(); - move_shots(); - move_player(); - move_enemy(); - draw_score(); - draw_ufo(); - draw_bunker(); - draw_player(); - draw_enemy(); - draw_shots(); -// draw_status(); - lcdDisplay(); - delayms(12); - } + //gpioSetValue (RB_LED1, CFG_LED_OFF); + //backlightInit(); + while(1) { + screen_intro(); + game.rokets = 3; + game.level = 1; + init_game(); + screen_level(); + while (game.rokets>=0) { + ////checkISP(); + lcdFill(0); + check_end(); + move_ufo(); + move_shot(); + move_shots(); + move_player(); + move_enemy(); + draw_score(); + draw_ufo(); + draw_bunker(); + draw_player(); + draw_enemy(); + draw_shots(); + // draw_status(); + lcdDisplay(); + delayms(12); + } + screen_gameover(); + } return; } + +void screen_intro() { + char key=0; + while(key==0) { + lcdFill(0); + font = &Font_Invaders; + DoString(28,25,"ABC"); + font = &Font_7x8; + DoString (28,40,"SPACE"); + DoString (18,50,"INVADERS"); + //DoString (20,RESY-24, "Highscore"); + DoString (0, 0, "12345"); + DoString (0, 9, "iggy"); + lcdDisplay(); + + delayms_queue(50); + key=getInput(); + } +} + +void screen_gameover() { + char key =0; + while(key==0) { + lcdFill(0); + font = &Font_7x8; + DoString (12,32, "GAME OVER"); + DoInt (0,0, game.score); + DoString (0,9,"HIGHSCORE!"); + lcdDisplay(); + delayms_queue(50); + key=getInput(); + } +} + +void screen_level() { + lcdFill(0); + draw_score(); + font = &Font_7x8; + int dx = DoString(20,32, "Level "); + DoInt(dx,32,game.level); + lcdDisplay(); + delayms(500); +} + void init_game(void) { game.player = RESX/2-4; game.shot_x = DISABLED; @@ -132,6 +185,25 @@ void init_enemy() { } } +bool check_bunker(char xpos, char ypos, int8_t shift){ + for (int b=0; bBUNKER_X[BUNKERS-1-b] && + xposRESY-16) { + int offset = BUNKER_WIDTH - (xpos-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + if (shift>0) + game.bunker[b][offset]&=game.bunker[b][offset]<>-shift; + return true; + } + } + } + return false; +} + void move_shot() { //No shot, do nothing if(game.shot_x == DISABLED) { @@ -145,18 +217,20 @@ void move_shot() { } //check for collision with bunker - for (int b=0; bBUNKER_X[BUNKERS-1-b] && - game.shot_xRESY-16) { - int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); - if (game.bunker[b][offset]!=0) { - game.bunker[b][offset]&=game.bunker[b][offset]<<1; - game.shot_x=DISABLED; - } - } - } +// for (int b=0; bBUNKER_X[BUNKERS-1-b] && +// game.shot_xRESY-16) { +// int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); +// if (game.bunker[b][offset]!=0) { +// game.bunker[b][offset]&=game.bunker[b][offset]<<1; +// game.shot_x=DISABLED; +// } +// } +// } + if (check_bunker(game.shot_x,game.shot_y-5,1 )) + game.shot_x=DISABLED; //check for collision with enemy, kill enemy if for (int row=0; rowBUNKER_X[BUNKERS-1-b] && - game.shots_x[col]RESY-16) { - int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; - if (game.bunker[b][offset]!=0) { - game.bunker[b][offset]&=game.bunker[b][offset]>>1; - game.shots_x[col]=DISABLED; - } - } - } + if (check_bunker(game.shots_x[col],game.shots_y[col],-1)) + game.shots_x[col]=DISABLED; + +// for (int b=0; bBUNKER_X[BUNKERS-1-b] && +// game.shots_x[col]RESY-16) { +// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; +// if (game.bunker[b][offset]!=0) { +// game.bunker[b][offset]&=game.bunker[b][offset]>>1; +// game.shots_x[col]=DISABLED; +// } +// } +// } //check for collision with player if (game.shots_y[col] >= RESY-13 && @@ -273,22 +353,26 @@ void move_enemy() { char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; if (pos != DISABLED) { //Check collision with player - if(game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8){ - game.killed = true; - } - - //check for collision with bunker, dirty - for (int b=0; b=BUNKER_X[BUNKERS-1-b] && - pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && - game.enemy_row_y[row]+8RESY-16) { - int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); - if (game.bunker[b][offset]!=0) { - game.bunker[b][offset]&=game.bunker[b][offset]>>2; - } + if((game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8) || + game.enemy_row_y[row]+8 >= POS_PLAYER_Y+8) { + for(int row=0; row=BUNKER_X[BUNKERS-1-b] && + // pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && + // game.enemy_row_y[row]+8RESY-16) { + // int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); + // if (game.bunker[b][offset]!=0) { + // game.bunker[b][offset]&=game.bunker[b][offset]>>2; + // } + // } + // } //Are we at the beginning or end? Direction change @@ -393,24 +477,16 @@ void check_end() { game.rokets--; delayms(500); game.player = RESX/2+4; - for(int row=0; row Date: Tue, 2 Aug 2011 13:31:57 +0200 Subject: [PATCH 48/48] Some menu changes. Also: cleanup apps and make the rest build again --- firmware/applications/Makefile | 8 +- firmware/applications/adc.c | 3 - firmware/applications/exe.c | 26 +-- firmware/applications/executor.c | 181 ------------------ firmware/applications/final.c | 8 +- firmware/applications/final/config.c | 1 + firmware/applications/final/exe.c | 21 +++ firmware/applications/final/flame.c | 3 + firmware/applications/final/mesh.c | 15 +- firmware/applications/final/nickname.c | 25 +-- firmware/applications/final/util.c | 5 + firmware/applications/font.c | 36 ++-- firmware/applications/fs.c | 49 ++--- firmware/applications/funk.c | 251 ------------------------- firmware/applications/loadable.c | 29 +-- firmware/applications/menutest.c | 43 ++--- firmware/applications/mkfirmware | 73 ------- firmware/applications/mkfirmware.pl | 123 ++++++++++++ firmware/applications/remote.c | 197 ------------------- firmware/applications/tester.c | 2 - firmware/basic/basic.h | 4 +- firmware/basic/menu.c | 12 +- 22 files changed, 235 insertions(+), 880 deletions(-) delete mode 100644 firmware/applications/executor.c create mode 100644 firmware/applications/final/exe.c delete mode 100644 firmware/applications/funk.c delete mode 100755 firmware/applications/mkfirmware create mode 100755 firmware/applications/mkfirmware.pl delete mode 100644 firmware/applications/remote.c diff --git a/firmware/applications/Makefile b/firmware/applications/Makefile index dacc19e..82b69df 100644 --- a/firmware/applications/Makefile +++ b/firmware/applications/Makefile @@ -8,6 +8,10 @@ ifeq "$(APP)" "initial" NODEFAULT = y endif +ifeq "$(APP)" "tester" +DEBUG = -d +endif + ifndef NODEFAULT OBJS += default.o endif @@ -71,7 +75,7 @@ ifeq "$(wildcard $(APP))" "$(APP)" ifndef TYPE TYPE=$(APP) endif -TSRCS = $(wildcard $(TYPE)/*.c) +TSRCS = $(foreach type,$(TYPE),$(wildcard $(type)/*.c)) TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod))) TWRAP=$(APP).gen @@ -81,7 +85,7 @@ TWRAP=$(APP).gen $(APP).o: $(TWRAP) $(TWRAP): - ./mkfirmware $(APP) $(TSRCS) > $@ + ./mkfirmware.pl $(DEBUG) $(APP) $(TSRCS) > $@ OBJS += $(TOBJS) endif diff --git a/firmware/applications/adc.c b/firmware/applications/adc.c index 2d8b6c8..293fb44 100644 --- a/firmware/applications/adc.c +++ b/firmware/applications/adc.c @@ -15,9 +15,6 @@ void main_adc(void) { uint32_t brightness = 0; uint8_t c = 0; - font_direction = FONT_DIR_LTR; // LeftToRight is the default - font = &Font_7x8; - DoString(0, 0, "adc"); backlightInit(); diff --git a/firmware/applications/exe.c b/firmware/applications/exe.c index 44b2d2d..9ba0a1d 100644 --- a/firmware/applications/exe.c +++ b/firmware/applications/exe.c @@ -52,24 +52,16 @@ void adc_check(void) { /**************************************************************************/ -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_nop = {"---", NULL}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_exe = {"Exec", &execute_menu}; +static const struct MENU mainmenu = {"Mainmenu", { + {"MSC", &msc_menu}, + {"Exec", &execute_menu}, + {"---", NULL}, + {"Mirror", &lcd_mirror}, + {"Akku", &adc_check}, + {"Invoke ISP", &gotoISP}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_msc, - &menu_exe, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_exe(void) { diff --git a/firmware/applications/executor.c b/firmware/applications/executor.c deleted file mode 100644 index 3fdf65a..0000000 --- a/firmware/applications/executor.c +++ /dev/null @@ -1,181 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/render.h" -#include "lcd/allfonts.h" - -void backlightInit(void); - -extern void * __sram_top; - -void execute (const void *function, uint16_t length){ - void (*dst)(void); - - dst=(void (*)(void)) (__sram_top); - - DoString(0,8,"Enter RAM!"); - DoIntX(0,16,(uint32_t)function); - DoIntX(0,24,(uint32_t)dst); - lcdDisplay(); - - for(int i=0;itrigger){ - ctr=0; - if (gpioGetValue(RB_LED2) == CFG_LED_OFF){ - gpioSetValue (RB_LED2, CFG_LED_ON); - } else { - gpioSetValue (RB_LED2, CFG_LED_OFF); - }; - }; - - // Print Voltage - font = &Font_7x8; - dx=DoString(0,yctr+28,"Voltage:"); - DoInt(dx,yctr+28,GetVoltage()); - - } - return; -} - -void tick_executor(void){ - static int foo=0; - static int toggle=0; - if(foo++>50){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - - diff --git a/firmware/applications/final.c b/firmware/applications/final.c index 16525d0..c2f757e 100644 --- a/firmware/applications/final.c +++ b/firmware/applications/final.c @@ -10,15 +10,13 @@ #include "final.gen" -static const struct MENU mainmenu = {"Menu", mentry}; - -void initNick(); +void init_nick(); void fancyNickname(); void main_final(void) { //checkFirstBoot(); + init_final(); - initNick(); while(1){ #ifndef FINAL if(getInputRaw()==BTN_LEFT) @@ -27,7 +25,7 @@ void main_final(void) { if(getInput()){ handleMenu(&mainmenu); getInputWaitRelease(); - initNick(); + init_nick(); }; fancyNickname(); delayms_queue(100); diff --git a/firmware/applications/final/config.c b/firmware/applications/final/config.c index 1451483..943d31d 100644 --- a/firmware/applications/final/config.c +++ b/firmware/applications/final/config.c @@ -25,6 +25,7 @@ void applycfg(void){ applyConfig(); }; +//# MENU config void changer(void){ uint8_t numentries = 0; signed char menuselection = 0; diff --git a/firmware/applications/final/exe.c b/firmware/applications/final/exe.c new file mode 100644 index 0000000..bd7c7c1 --- /dev/null +++ b/firmware/applications/final/exe.c @@ -0,0 +1,21 @@ +#include +#include + +#include "basic/basic.h" +#include "lcd/lcd.h" +#include "lcd/allfonts.h" +#include "lcd/print.h" +#include "usb/usbmsc.h" +#include "filesystem/ff.h" +#include "filesystem/select.h" +#include "filesystem/execute.h" + +/**************************************************************************/ + +//# MENU execute +void execute_menu(void){ + while(getInput()!=BTN_NONE); + executeSelect("C0D"); + lcdRefresh(); +}; + diff --git a/firmware/applications/final/flame.c b/firmware/applications/final/flame.c index d010671..9775ad1 100644 --- a/firmware/applications/final/flame.c +++ b/firmware/applications/final/flame.c @@ -131,6 +131,7 @@ void tick_flame(void) { // every 10ms } } +//# MENU flame void flameInit(void) { i2cInit(I2CMASTER); // Init I2C @@ -151,6 +152,7 @@ void flameInit(void) { #include "lcd/print.h" +//# MENU debug ChkFlame void ChkFlame(void) { do{ lcdClear(); @@ -167,5 +169,6 @@ void ChkFlame(void) { lcdPrintln(IntToStr(flameTicks,3,0)); lcdRefresh(); + delayms_queue(10); } while ((getInputRaw())==BTN_NONE); } diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c index c6d1f63..1dc3d95 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -16,19 +16,8 @@ /**************************************************************************/ -void m_init(void){ +void init_mesh(void){ nrf_init(); - - struct NRF_CFG config = { - .channel= MESH_CHANNEL, - .txmac= MESH_MAC, - .nrmacs=1, - .mac0= MESH_MAC, - .maclen ="\x20", // XXX: MESHPKTSIZE - }; - - nrf_config_set(&config); - initMesh(); }; @@ -36,6 +25,7 @@ void m_tset(void){ _timet=1311961112; }; +//# MENU debug MeshInfo void m_time(void){ struct tm* tm; char c[2]={0,0}; @@ -185,6 +175,7 @@ char *meshmsgs(void){ extern MPKT meshbuffer[MESHBUFSIZE]; +//# MENU mesh Messages void m_choose(){ char list[99]; int i=0; diff --git a/firmware/applications/final/nickname.c b/firmware/applications/final/nickname.c index 9eb46c7..48dde5f 100644 --- a/firmware/applications/final/nickname.c +++ b/firmware/applications/final/nickname.c @@ -33,17 +33,19 @@ void fancyNickname(void) { /**************************************************************************/ -void initNick(void){ +void init_nick(void){ readFile("nick.cfg",GLOBAL(nickname),MAXNICK); // readFile("font.cfg",GLOBAL(nickfont),FILENAMELEN); }; +//# MENU nick editNick void doNick(void){ input("Nickname:", GLOBAL(nickname), 32, 127, MAXNICK-1); writeFile("nick.cfg",GLOBAL(nickname),strlen(GLOBAL(nickname))); getInputWait(); }; +//# MENU nick changeFont void doFont(void){ getInputWaitRelease(); if( selectFile(GLOBAL(nickfont),"F0N") != 0){ @@ -60,24 +62,3 @@ void doFont(void){ lcdDisplay(); while(!getInputRaw())delayms(10); }; - - -#if 0 - void f_font(void){ - - if( selectFile(fontname,"F0N") != 0){ - lcdPrintln("No file selected."); - return; - }; - - lcdClear(); - lcdPrintln(fontname); - setExtFont(fontname); - lcdPrintln("PUabc€"); - setIntFont(&Font_7x8); - lcdPrintln("done."); - lcdDisplay(); - while(!getInputRaw())delayms(10); -}; - -#endif diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index 401a3f5..fca9cdc 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -13,6 +13,7 @@ /**************************************************************************/ +//# MENU debug ChkLight void ChkLight(void) { int dx=0; int dy=8; @@ -28,6 +29,7 @@ void ChkLight(void) { dx=DoString(0,dy+24,"Done."); } +//# MENU debug ChkBattery void ChkBattery(void) { do{ lcdClear(); @@ -45,6 +47,7 @@ void ChkBattery(void) { } while ((getInputRaw())==BTN_NONE); } +//# MENU debug Uptime void uptime(void) { int t; int h; @@ -81,6 +84,7 @@ void uptime(void) { lcdPrintln("done."); } +//# MENU debug Uuid void uuid(void) { IAP_return_t iap_return; iap_return = iapReadSerialNumber(); @@ -96,6 +100,7 @@ void uuid(void) { lcdRefresh(); } +//# MENU debug Qstatus void Qstatus(void) { int dx=0; int dy=8; diff --git a/firmware/applications/font.c b/firmware/applications/font.c index 9e6b045..75115b1 100644 --- a/firmware/applications/font.c +++ b/firmware/applications/font.c @@ -167,31 +167,19 @@ void msc_menu(void){ /**************************************************************************/ -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_nick = {"F Nick", &f_nick}; -const struct MENU_DEF menu_font = {"F sel", &f_font}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_invert = {"Invert", &lcd_invert}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_nop = {"---", NULL}; -static menuentry menu[] = { - &menu_init, - &menu_nick, - &menu_font, - &menu_nop, - &menu_mirror, - &menu_invert, - &menu_volt, - &menu_msc, - &menu_nop, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; +static const struct MENU mainmenu = {"Mainmenu", { + {"Invoke ISP", &gotoISP}, + {"F Init", &f_init}, + {"F Nick", &f_nick}, + {"F sel", &f_font}, + {"Mirror", &lcd_mirror}, + {"Invert", &lcd_invert}, + {"Akku", &adc_check}, + {"MSC", &msc_menu}, + {"---", NULL}, + {NULL,NULL} +}}; void main_font(void) { diff --git a/firmware/applications/fs.c b/firmware/applications/fs.c index 89cf37b..d820c53 100644 --- a/firmware/applications/fs.c +++ b/firmware/applications/fs.c @@ -25,42 +25,25 @@ void fs_mount(void); /**************************************************************************/ -const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight}; -const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight}; -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_status = {"FS Status", &fs_status}; -const struct MENU_DEF menu_mount = {"FS Mount", &fs_mount}; -const struct MENU_DEF menu_list = {"FS List", &fs_list}; -const struct MENU_DEF menu_create = {"FS Create", &fs_create}; -const struct MENU_DEF menu_format = {"FS format", &fs_format}; -const struct MENU_DEF menu_read = {"FS read", &fs_read}; +static const struct MENU mainmenu = {"Mainmenu", { + {"FS Mount", &fs_mount}, + {"FS Status", &fs_status}, + {"FS List", &fs_list}, + {"FS Create", &fs_create}, + {"FS read", &fs_read}, + {"FS format", &fs_format}, + {"---", NULL}, #if CFG_USBMSC -const struct MENU_DEF menu_usb = {"USB mount", &usbMSCInit}; -const struct MENU_DEF menu_usboff = {"USB unmount", &usbMSCOff}; + {"USB mount", &usbMSCInit}, + {"USB unmount", &usbMSCOff}, + {"---", NULL}, #endif -const struct MENU_DEF menu_nop = {"---", NULL}; + {"Invoke ISP", &gotoISP}, + {"Backlight++", &incBacklight}, + {"Backlight--", &decBacklight}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_mount, - &menu_status, - &menu_list, - &menu_create, - &menu_read, - &menu_nop, - &menu_format, - &menu_nop, -#if CFG_USBMSC - &menu_usb, - &menu_usboff, -#endif - &menu_nop, - &menu_ISP, - &menu_incBL, - &menu_decBL, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_fs(void) { diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c deleted file mode 100644 index d592dbe..0000000 --- a/firmware/applications/funk.c +++ /dev/null @@ -1,251 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/lcd.h" -#include "lcd/print.h" - -#include "funk/nrf24l01p.h" - -#include - -#include "funk/rftransfer.h" -#include "funk/openbeacon.h" - -/**************************************************************************/ - -#define BEACON_CHANNEL 81 -#define BEACON_MAC "\x1\x2\x3\x2\1" - -uint32_t const testkey[4] = { - 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E -}; - -int enctoggle=0; - -void f_init(void){ - nrf_init(); - - struct NRF_CFG config = { - .channel= BEACON_CHANNEL, - .txmac= BEACON_MAC, - .nrmacs=1, - .mac0= BEACON_MAC, - .maclen ="\x10", - }; - - nrf_config_set(&config); - lcdPrintln("Done."); -}; - -void f_status(void){ - int dx=0; - int dy=8; - uint8_t buf[4]; - - buf[0]=C_R_REGISTER | R_CONFIG; - buf[1]=0; - buf[2]=0; - buf[3]=0; - dx=DoString(0,dy,"S:"); - dx=DoCharX(dx,dy,buf[0]); - dx=DoCharX(dx,dy,buf[1]); - dx=DoCharX(dx,dy,buf[2]); - dx=DoCharX(dx,dy,buf[3]); - dy+=8; - nrf_cmd_rw_long(buf,2); - dx=DoString(0,dy,"R:"); - dx=DoCharX(dx,dy,buf[0]); - dx=DoCharX(dx,dy,buf[1]); - dx=DoCharX(dx,dy,buf[2]); - dx=DoCharX(dx,dy,buf[3]); - dy+=8; - - int status=nrf_cmd_status(C_NOP); - dx=DoString(0,dy,"St:"); DoCharX(dx,dy,status);dy+=8; -}; - -void f_recv(void){ - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - - len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL); - - if(len==0){ - lcdPrintln("No pkt (Timeout)"); - }; - lcdPrint("Size:");lcdPrintInt(len);lcdNl(); - lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl(); - lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl(); - lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl(); - lcdPrint("4:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl(); - - len=crc16(buf,14); - lcdPrint("crc:");lcdPrintShortHex(len); lcdNl(); - -}; - -void f_cfg(void){ - struct NRF_CFG config; - - nrfconfig cfg=&config; - - nrf_config_get(cfg); - - lcdPrint("ch:");lcdPrintInt( cfg->channel ); lcdNl(); - lcdPrint("nr:");lcdPrintInt( cfg->nrmacs ); lcdNl(); - - lcdPrint("0:"); - lcdPrintCharHex(cfg->mac0[0]); - lcdPrintCharHex(cfg->mac0[1]); - lcdPrintCharHex(cfg->mac0[2]); - lcdPrintCharHex(cfg->mac0[3]); - lcdPrintCharHex(cfg->mac0[4]); - lcdNl(); - lcdPrint("1:"); - lcdPrintCharHex(cfg->mac1[0]); - lcdPrintCharHex(cfg->mac1[1]); - lcdPrintCharHex(cfg->mac1[2]); - lcdPrintCharHex(cfg->mac1[3]); - lcdPrintCharHex(cfg->mac1[4]); - lcdNl(); - lcdPrint("2345:"); - lcdPrintCharHex(cfg->mac2345[0]); - lcdPrintCharHex(cfg->mac2345[1]); - lcdPrintCharHex(cfg->mac2345[2]); - lcdPrintCharHex(cfg->mac2345[3]); - lcdNl(); - lcdPrint("tx:"); - lcdPrintCharHex(cfg->txmac[0]); - lcdPrintCharHex(cfg->txmac[1]); - lcdPrintCharHex(cfg->txmac[2]); - lcdPrintCharHex(cfg->txmac[3]); - lcdPrintCharHex(cfg->txmac[4]); - lcdNl(); - lcdPrint("len:"); - lcdPrintCharHex(cfg->maclen[0]); - lcdPrintCharHex(cfg->maclen[1]); - lcdPrintCharHex(cfg->maclen[2]); - lcdPrintCharHex(cfg->maclen[3]); - lcdPrintCharHex(cfg->maclen[4]); - lcdNl(); -}; - -void f_cfg_set(void){ - struct NRF_CFG config = { - .channel= 13, - .txmac= "R0KET", - .nrmacs=1, - .mac0= "R0KET", - .maclen ="\x10", - }; - - nrf_config_set(&config); -}; - -void f_enctog(void){ - enctoggle=1-enctoggle; - if(enctoggle) - lcdPrintln("Encrypt ON!"); - else - lcdPrintln("encrypt off!"); - -}; - -void f_send(void){ - uint8_t status; - - status = openbeaconSend(); - lcdPrint("Status:"); - lcdPrintCharHex(status); - lcdNl(); -}; - -void gotoISP(void) { - DoString(0,0,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); -} - -void lcd_mirror(void) { - lcdToggleFlag(LCD_MIRRORX); -}; - -void adc_check(void) { - int dx=0; - int dy=8; - // Print Voltage - dx=DoString(0,dy,"Voltage:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetVoltage()); - lcdDisplay(); - }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; - -void f_sendBlock(void) -{ - uint8_t data[] = "hallo welt, das hier ist ein langer string, der" - "per funk verschickt werden soll."; - rftransfer_send(strlen((char *)data), data); -} - -/**************************************************************************/ - -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_status = {"F Status", &f_status}; -const struct MENU_DEF menu_rcv = {"F Recv", &f_recv}; -const struct MENU_DEF menu_snd = {"F Send", &f_send}; -const struct MENU_DEF menu_cfg = {"F CfgGet", &f_cfg}; -const struct MENU_DEF menu_cfg2 = {"F CfgSet", &f_cfg_set}; -const struct MENU_DEF menu_enc = {"Toggle Encr", &f_enctog}; -const struct MENU_DEF menu_sndblock={"F Send block", &f_sendBlock}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_nop = {"---", NULL}; - -static menuentry menu[] = { - &menu_init, - &menu_status, - &menu_rcv, - &menu_snd, - &menu_enc, - &menu_cfg2, - &menu_cfg, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; - -void main_funk(void) { - backlightInit(); - font=&Font_7x8; - - openbeaconSetup(); - while (1) { - lcdFill(0); // clear display buffer - lcdDisplay(); - handleMenu(&mainmenu); - gotoISP(); - } -}; - -void tick_funk(void){ - static int foo=0; - static int toggle=0; - - if(foo++>50){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - diff --git a/firmware/applications/loadable.c b/firmware/applications/loadable.c index 63ec6cb..2457517 100644 --- a/firmware/applications/loadable.c +++ b/firmware/applications/loadable.c @@ -45,26 +45,17 @@ void msc_menu(void){ extern void (*ram)(void); -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_again = {"Run Loadable", &ram}; -const struct MENU_DEF menu_nop = {"---", NULL}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_invert = {"Invert", &lcd_invert}; +static const struct MENU mainmenu = {"Mainmenu", { + {"Run Loadable", &ram}, + {"Invoke ISP", &gotoISP}, + {"---", NULL}, + {"MSC", &msc_menu}, + {"Akku", &adc_check}, + {"Mirror", &lcd_mirror}, + {"Invert", &lcd_invert}, + {NULL,NULL} +}}; -static menuentry menu[] = { - &menu_again, - &menu_ISP, - &menu_nop, - &menu_msc, - &menu_mirror, - &menu_invert, - &menu_volt, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; /**************************************************************************/ diff --git a/firmware/applications/menutest.c b/firmware/applications/menutest.c index 7aa01b1..cc0fb4c 100644 --- a/firmware/applications/menutest.c +++ b/firmware/applications/menutest.c @@ -21,42 +21,25 @@ void gotoISP(void); /**************************************************************************/ +static const struct MENU mainmenu = {"Mainmenu", { + {"Backlight++", &incBacklight}, + {"Backlight--", &decBacklight}, + {"Invoke ISP", &gotoISP}, + {"p1e4", NULL}, + {"p1e5", NULL}, + {"p1e6", NULL}, + {"p1e7", NULL}, + {"p2e1", NULL}, + {"p2e2", NULL}, + {"p2e3", NULL}, + {NULL, NULL}, +}}; -const struct MENU_DEF menu_incBL = {"Backlight++", &incBacklight}; -const struct MENU_DEF menu_decBL = {"Backlight--", &decBacklight}; -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_Ep = {"p1e4", NULL}; -const struct MENU_DEF menu_Eq = {"p1e5", NULL}; -const struct MENU_DEF menu_Er = {"p1e6", NULL}; -const struct MENU_DEF menu_Es = {"p1e7", NULL}; -const struct MENU_DEF menu_Et = {"p2e1", NULL}; -const struct MENU_DEF menu_Eu = {"p2e2", NULL}; -const struct MENU_DEF menu_Ev = {"p2e3", NULL}; - -static menuentry menu[] = { - &menu_incBL, - &menu_decBL, - &menu_ISP, - &menu_Ep, - &menu_Eq, - &menu_Er, - &menu_Es, - &menu_Et, - &menu_Eu, - &menu_Ev, - &menu_Ev, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; void main_menutest(void) { backlightInit(); - font_direction = FONT_DIR_LTR; // LeftToRight is the default - while (1) { lcdDisplay(); delayms(10); diff --git a/firmware/applications/mkfirmware b/firmware/applications/mkfirmware deleted file mode 100755 index fdf7f2d..0000000 --- a/firmware/applications/mkfirmware +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh - -APP=$1 -shift - -for f in $* ; do - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "void $a(void);" - done -done - -for f in $* ; do - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "const struct MENU_DEF menu_$a = {\"$a\", &$a};" - done -done - -echo "const struct MENU_DEF menu_nop = {\"---\", NULL};" -echo - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "static menuentry mentry_$t[] = {" - grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "&menu_$a," - done - echo "NULL" - echo "};" -done - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "static const struct MENU m_$t = {\"$t\", mentry_$t};" -done - - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "void run_$t(void) {" - echo "handleMenu(&m_$t);" - echo "};" -done - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "const struct MENU_DEF menu_$t = {\"$t\", &run_$t};" -done - -echo "static menuentry mentry[] = {" - -for f in $* ; do - t=${f#*/} - t=${t%.c} - echo "&menu_$t," -done - -echo "NULL" -echo "};" - -echo "inline void tick_${APP}(void){" -for f in $* ; do - grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do - echo "$a();" - done -done -echo "return;" -echo "};" - - diff --git a/firmware/applications/mkfirmware.pl b/firmware/applications/mkfirmware.pl new file mode 100755 index 0000000..2c465b6 --- /dev/null +++ b/firmware/applications/mkfirmware.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl +# +# vim:set ts=4 sw=4: + +use strict; + +my $debug=0; +if($ARGV[0] eq "-d"){ + $debug=1; + shift; +}; + +my $app=shift; +my @files=@ARGV; +my %menu; +my (@ticks,@inits); + +$\="\n"; + +print "// Function definitions:"; +my $menudef; +for my $file (@files){ + open(F,"<",$file) || die "Can't open $file: $!"; + while(){ + chomp; + s/\r$//; # Dos line-end + + if(m!^\s*//#\s+(.*?)\s*$!){ # Menu definition + $menudef=$1; + next; + }; + next if(/^\s*$/); + next if(m!^\s*//!); + if(m!^\s*void\s+([^(]+)\(!){ # A suitable function + my $func=$1; + if($func=~/tick_/){ + push @ticks,$func; + print "void $func(void);"; + }; + if($func=~/init_/){ + push @inits,$func; + print "void $func(void);"; + }; + if($debug){ + my $f="debug"; + $file =~ m!([^/.]+)\.! && do {$f=$1}; + $menudef="MENU $f $func"; + }; + if(defined $menudef){ + my @words=split(/\s+/,$menudef); + if($words[0] ne "MENU"){ + warn "Not a menu definition?"; + }; + + if($#words==1){ + $menu{$words[1]}=$func; + }elsif($#words==2){ + $menu{$words[1]}{$words[2]}=$func; + }else{ + warn "Couldn't handle $menudef"; + }; + print "void $func(void);"; + }; + $menudef=undef; + }; + }; +}; + +print ""; +print "// Submenus:"; + +#use Data::Dumper; print Dumper \%menu; + +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + printf "static const struct MENU submenu_${_}={"; + print qq! "$_", {!; + for my $entry(sort keys %{$menu{$_}}){ + print qq!\t{ "$entry", &$menu{$_}{$entry}},!; + }; + print qq!\t{NULL,NULL}!; + print "}};"; + }; +}; + +print ""; + +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + print qq!void run_submenu_$_(void) {!; + print qq!\thandleMenu(&submenu_$_);!; + print qq!};!; + }; +}; + +print ""; +print "// Main menu:"; +printf "static const struct MENU mainmenu={"; +print qq! "Menu:", {!; +for (sort keys %menu){ + if(ref $menu{$_} eq "HASH"){ + print qq!\t{ "$_", &run_submenu_$_},!; + }else{ + print qq!\t{ "$_", &$menu{$_}},!; + }; +}; +print qq!\t\t{NULL,NULL}!; +print "}};"; + +print ""; +print "// Tick & init functions:"; +print qq!void tick_$app(void) {!; +for (sort @ticks){ + print qq!\t$_();!; +}; +print qq!};!; + +print qq!void init_$app(void) {!; +for (sort @inits){ + print qq!\t$_();!; +}; +print qq!};!; + diff --git a/firmware/applications/remote.c b/firmware/applications/remote.c deleted file mode 100644 index 4effc17..0000000 --- a/firmware/applications/remote.c +++ /dev/null @@ -1,197 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/lcd.h" -#include "lcd/print.h" - -#include "funk/nrf24l01p.h" -#include "usb/usbmsc.h" - -#include - -/**************************************************************************/ - -uint32_t const testkey[4] = { - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff -}; - -void f_init(void){ - nrf_init(); - - struct NRF_CFG config = { - .channel= 81, - .txmac= "REMOT", - .nrmacs=1, - .mac0= "REMOT", - .maclen ="\x10", - }; - - nrf_config_set(&config); - - lcdPrintln("Done."); -}; - -void f_recv(void){ - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - - while(1){ - len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,testkey); - - if(len==0){ - lcdPrintln("No pkt (Timeout)"); - return; - }; - - lcdClear(); - lcdPrint("Size:");lcdPrintInt(len);lcdNl(); - - lcdPrintCharHex(buf[0]); - lcdPrint(" "); - lcdPrintCharHex(buf[1]); - lcdPrint(" "); - lcdPrintCharHex(buf[2]); - lcdPrint(" "); - lcdPrintCharHex(buf[3]); - lcdNl(); - - lcdPrint("ct:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl(); - lcdPrint("id:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl(); - lcdPrint("xx:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl(); - lcdDisplay(); - }; -}; - - -void f_send(void){ - int ctr=1; - __attribute__ ((aligned (4))) uint8_t buf[32]; - int len; - int status; - - while(1){ - - buf[0]=0x10; // Length: 16 bytes - buf[1]='C'; // Proto - buf[2]=getInputRaw(); - buf[3]=0x00; // Unused - - ctr++; - *(int*)(buf+4)=ctr; - - /* - buf[4]=0x00; // ctr - buf[5]=0x00; // ctr - buf[6]=0x00; // ctr - buf[7]=ctr++; // ctr - */ - - buf[8]=0x0; // Object id - buf[9]=0x0; - buf[10]=0x05; - buf[11]=0xec; - - buf[12]=0xff; // salt (0xffff always?) - buf[13]=0xff; - - status=nrf_snd_pkt_crc_encr(16,buf,testkey); - lcdClear(); - lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl(); - lcdPrint("F-St:"); lcdPrintInt(status); - if(buf[2]==BTN_ENTER) - break; - lcdDisplay(); - len=nrf_rcv_pkt_time_encr(10,sizeof(buf),buf,testkey); - if(len>0){ - lcdPrint("Got!"); - }; - }; - - -}; - -void gotoISP(void) { - DoString(0,0,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); -} - -void lcd_mirror(void) { - lcdToggleFlag(LCD_MIRRORX); -}; - -void adc_check(void) { - int dx=0; - int dy=8; - // Print Voltage - dx=DoString(0,dy,"Voltage:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetVoltage()); - lcdDisplay(); - }; - dy+=8; - dx=DoString(0,dy,"Done."); -}; - -void msc_menu(void){ - DoString(0,8,"MSC Enabled."); - lcdDisplay(); - usbMSCInit(); - while(!getInputRaw())delayms(10); - DoString(0,16,"MSC Disabled."); - usbMSCOff(); -}; - -/**************************************************************************/ - -const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP}; -const struct MENU_DEF menu_init = {"F Init", &f_init}; -const struct MENU_DEF menu_rcv = {"F Recv", &f_recv}; -const struct MENU_DEF menu_snd = {"F Send", &f_send}; -//const struct MENU_DEF menu_cfg = {"F Cfg", &f_cfg}; -const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror}; -const struct MENU_DEF menu_volt = {"Akku", &adc_check}; -const struct MENU_DEF menu_msc = {"MSC", &msc_menu}; -const struct MENU_DEF menu_nop = {"---", NULL}; - -static menuentry menu[] = { - &menu_init, - &menu_rcv, - &menu_snd, -// &menu_cfg, - &menu_nop, - &menu_mirror, - &menu_volt, - &menu_msc, - &menu_nop, - &menu_ISP, - NULL, -}; - -static const struct MENU mainmenu = {"Mainmenu", menu}; - -void main_remote(void) { - - font=&Font_7x8; - - while (1) { - lcdFill(0); // clear display buffer - lcdDisplay(); - handleMenu(&mainmenu); - gotoISP(); - } -}; - -void tick_remote(void){ - static int foo=0; - static int toggle=0; - if(foo++>80){ - toggle=1-toggle; - foo=0; - gpioSetValue (RB_LED0, toggle); - }; - return; -}; - - diff --git a/firmware/applications/tester.c b/firmware/applications/tester.c index d494e42..c0dabab 100644 --- a/firmware/applications/tester.c +++ b/firmware/applications/tester.c @@ -10,8 +10,6 @@ #include "tester.gen" -static const struct MENU mainmenu = {"Mainmenu", mentry}; - void main_tester(void) { handleMenu(&mainmenu); gotoISP(); diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index ed67c74..df3f2c9 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -172,11 +172,9 @@ struct MENU_DEF { void (*callback)(void); }; -typedef const struct MENU_DEF * menuentry; - struct MENU { char *title; - menuentry *entries; + struct MENU_DEF entries[]; }; diff --git a/firmware/basic/menu.c b/firmware/basic/menu.c index 2216dd2..253bb55 100644 --- a/firmware/basic/menu.c +++ b/firmware/basic/menu.c @@ -17,7 +17,7 @@ void handleMenu(const struct MENU *the_menu) { setSystemFont(); - for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++); + for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++); visible_lines = lcdGetVisibleLines()-1; // subtract title line #ifdef SAFETY @@ -34,7 +34,7 @@ void handleMenu(const struct MENU *the_menu) { lcdPrint("*"); } lcdSetCrsrX(14); - lcdPrintln(the_menu->entries[i]->text); + lcdPrintln(the_menu->entries[i].text); } lcdRefresh(); @@ -64,16 +64,16 @@ void handleMenu(const struct MENU *the_menu) { case BTN_LEFT: return; case BTN_RIGHT: - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); + if (the_menu->entries[menuselection].callback!=NULL) + the_menu->entries[menuselection].callback(); break; case BTN_ENTER: lcdClear(); lcdPrintln("Called..."); lcdRefresh(); getInputWaitRelease(); - if (the_menu->entries[menuselection]->callback!=NULL) - the_menu->entries[menuselection]->callback(); + if (the_menu->entries[menuselection].callback!=NULL) + the_menu->entries[menuselection].callback(); lcdRefresh(); getInputWait();