From 21be4195ebef312f6efdb4af9fdace6ecc3779dc Mon Sep 17 00:00:00 2001 From: kiu Date: Mon, 1 Aug 2011 23:34:13 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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;