Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
iggy 2011-08-02 01:13:20 +02:00
commit 2957ee4f21
5 changed files with 124 additions and 76 deletions

View File

@ -31,41 +31,49 @@ void main_default(void) {
return; 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 // every 10 ms
void tick_default(void) { void tick_default(void) {
static int ctr; static int ctr;
ctr++; ctr++;
incTimer(); incTimer();
if(ctr>1000/SYSTICKSPEED){
EVERY(1000,0){
if(!adcMutex){ if(!adcMutex){
VoltageCheck(); VoltageCheck();
LightCheck(); LightCheck();
ctr=0;
}else{ }else{
ctr--; ctr--;
}; };
}; };
if(ctr>100/SYSTICKSPEED){ static char night=0;
if(isNight()){ EVERY(100,2){
if(night!=isNight()){
night=isNight();
if(night){
backlightSetBrightness(GLOBAL(lcdbacklight)); backlightSetBrightness(GLOBAL(lcdbacklight));
lcdSetInvert(0); push_queue(queue_setinvert);
} else { }else{
backlightSetBrightness(0); backlightSetBrightness(0);
if(GLOBAL(dayinvert)) push_queue(queue_unsetinvert);
lcdSetInvert(1); };
else };
lcdSetInvert(0); };
}
}
if(ctr%(50/SYSTICKSPEED)==0){
if(GetVoltage()<3600 EVERY(50,0){
#ifdef SAFE if(GetVoltage()<3600){
|| GetVoltage() > 10000 // pin not connected
#endif
){
IOCON_PIO1_11 = 0x0; IOCON_PIO1_11 = 0x0;
gpioSetDir(RB_LED3, gpioDirection_Output); gpioSetDir(RB_LED3, gpioDirection_Output);
if( (ctr/(50/SYSTICKSPEED))%10 == 1 ) if( (ctr/(50/SYSTICKSPEED))%10 == 1 )
@ -74,6 +82,5 @@ void tick_default(void) {
gpioSetValue (RB_LED3, 0); gpioSetValue (RB_LED3, 0);
}; };
}; };
return; return;
}; };

View File

@ -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 flameEnabled = 0;
uint8_t flameMode = FLAME_OFF; uint8_t flameMode = FLAME_OFF;
uint8_t flameI2Cpwm = 0; uint8_t flameI2Cpwm = 0;
uint16_t flameTicks = 0; uint8_t flameTicks = 0;
uint32_t flameSetI2C(uint8_t cr, uint8_t value) { uint32_t flameSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE; I2CMasterBuffer[0] = FLAME_I2C_WRITE;
@ -55,9 +65,17 @@ void setFlamePWM() {
flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
} }
void tick_flame(void) { // every 10ms void tick_flame(void) { // every 10ms
flameTicks++; flameTicks++;
if (flameI2Cpwm > flameBrightnessMax) {
flameI2Cpwm = flameBrightnessMax;
}
if (flameI2Cpwm < flameBrightnessMin) {
flameI2Cpwm = flameBrightnessMin;
}
if (flameMode == FLAME_OFF) { if (flameMode == FLAME_OFF) {
if (isNight() && flameEnabled) { if (isNight() && flameEnabled) {
flameTicks = 0; flameTicks = 0;
@ -66,31 +84,39 @@ void tick_flame(void) { // every 10ms
} }
if (flameMode == FLAME_UP) { if (flameMode == FLAME_UP) {
flameI2Cpwm++; if (flameI2Cpwm + flameSpeedUp > flameI2Cpwm ) {
flameI2Cpwm += flameSpeedUp;
} else {
flameI2Cpwm = 0xFF;
}
push_queue(&setFlamePWM); push_queue(&setFlamePWM);
if (flameI2Cpwm == 0xFF) { if (flameI2Cpwm == flameBrightnessMax) {
flameMode = FLAME_UP_WAIT; flameMode = FLAME_UP_WAIT;
flameTicks = 0; flameTicks = 0;
} }
} }
if (flameMode == FLAME_UP_WAIT) { if (flameMode == FLAME_UP_WAIT) {
if (flameTicks > 0xFF) { if (flameTicks >= flameWaitUp) {
flameMode = FLAME_DOWN; flameMode = FLAME_DOWN;
} }
} }
if (flameMode == FLAME_DOWN) { if (flameMode == FLAME_DOWN) {
flameI2Cpwm--; if (flameI2Cpwm - flameSpeedDown < flameI2Cpwm ) {
flameI2Cpwm -= flameSpeedDown;
} else {
flameI2Cpwm = 0x00;
}
push_queue(&setFlamePWM); push_queue(&setFlamePWM);
if (flameI2Cpwm == 0x00) { if (flameI2Cpwm == flameBrightnessMin) {
flameMode = FLAME_DOWN_WAIT; flameMode = FLAME_DOWN_WAIT;
flameTicks = 0; flameTicks = 0;
} }
} }
if (flameMode == FLAME_DOWN_WAIT) { if (flameMode == FLAME_DOWN_WAIT) {
if (flameTicks > 0x8F) { if (flameTicks >= flameWaitDown) {
flameMode = FLAME_OFF; flameMode = FLAME_OFF;
} }
} }

View File

@ -27,18 +27,6 @@ void f_init(void){
UINT readbytes; UINT readbytes;
int res; 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); res=f_open(&file[0], "nick.cfg", FA_OPEN_EXISTING|FA_READ);
lcdPrint("open:"); lcdPrint("open:");
lcdPrintln(f_get_rc_string(res)); lcdPrintln(f_get_rc_string(res));
@ -79,7 +67,6 @@ void f_init(void){
char fontname[15]; char fontname[15];
void f_nick(void){ void f_nick(void){
static char ctr=0;
char key; char key;
static signed char x=10; static signed char x=10;
static signed char y=10; static signed char y=10;
@ -97,6 +84,7 @@ void f_nick(void){
lcdPrint("x"); lcdPrint("x");
lcdPrintInt(y); lcdPrintInt(y);
lcdDisplay(); lcdDisplay();
delayms(40); delayms(40);
@ -117,7 +105,6 @@ void f_nick(void){
lcdClear(); lcdClear();
lcdPrintln("Done."); lcdPrintln("Done.");
lcdDisplay(); lcdDisplay();
ctr++;
break; break;
}; };
}; };

View File

@ -13,29 +13,30 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
DIR dir; /* Directory object */ DIR dir; /* Directory object */
FILINFO Finfo; FILINFO Finfo;
FRESULT res; FRESULT res;
int ctr;
int pos = 0; int pos = 0;
int extlen = strlen(ext);
res = f_opendir(&dir, "0:"); res = f_opendir(&dir, "0:");
if(res){ if(res){
//lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh(); //lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh();
return 0; return 0;
}; };
ctr=0; while(f_readdir(&dir, &Finfo) == FR_OK && Finfo.fname[0]){
while(1){
res = f_readdir(&dir, &Finfo);
if ((res != FR_OK) || !Finfo.fname[0])
break;
int len=strlen(Finfo.fname); int len=strlen(Finfo.fname);
int extlen = strlen(ext);
if(len<extlen)
continue;
if( strcmp(Finfo.fname+len-extlen, ext) != 0) if( strcmp(Finfo.fname+len-extlen, ext) != 0)
continue; continue;
if (Finfo.fattrib & AM_DIR) if (Finfo.fattrib & AM_DIR)
continue; continue;
if( ctr++ < skip ) if( skip>0 ){
skip--;
continue; continue;
};
strcpy(files[pos++],Finfo.fname); strcpy(files[pos++],Finfo.fname);
if( pos == count ) if( pos == count )
break; break;
@ -43,6 +44,7 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
return pos; return pos;
} }
#define PERPAGE 7
int selectFile(char *filename, char *extension) int selectFile(char *filename, char *extension)
{ {
int skip = 0; int skip = 0;
@ -50,13 +52,29 @@ int selectFile(char *filename, char *extension)
int selected = 0; int selected = 0;
font=&Font_7x8; font=&Font_7x8;
while(1){ while(1){
char files[7][FLEN]; char files[PERPAGE][FLEN];
int count = getFiles(files, 7, skip, extension); int count = getFiles(files, PERPAGE, skip, extension);
if(!count){
lcdPrintln("No Files?");
lcdRefresh();
getInputWait();
getInputWaitRelease();
return -1;
};
if(count<PERPAGE && selected==count){
skip--;
continue;
};
redraw: redraw:
if( count )
lcdClear(); lcdClear();
lcdPrintln("Select file:"); lcdPrint("Select file:");
lcdSetCrsrX(40);
lcdPrint(IntToStr(skip,1,0));
lcdPrint("/");
lcdPrint(IntToStr(selected,1,0));
lcdNl();
for(int i=0; i<count; i++){ for(int i=0; i<count; i++){
if( selected == i ) if( selected == i )
lcdPrint("*"); lcdPrint("*");
@ -67,14 +85,16 @@ int selectFile(char *filename, char *extension)
lcdRefresh(); lcdRefresh();
key=getInputWait(); key=getInputWait();
getInputWaitRelease(); getInputWaitRelease();
if( key==BTN_DOWN ){ switch(key){
case BTN_DOWN:
if( selected < count-1 ){ if( selected < count-1 ){
selected++; selected++;
goto redraw; goto redraw;
}else{ }else{
skip++; skip++;
} }
}else if( key==BTN_UP ){ break;
case BTN_UP:
if( selected > 0 ){ if( selected > 0 ){
selected--; selected--;
goto redraw; goto redraw;
@ -83,9 +103,11 @@ int selectFile(char *filename, char *extension)
skip--; skip--;
} }
} }
}else if( key==BTN_LEFT ){ break;
return 1; case BTN_LEFT:
}else if( key==BTN_RIGHT ){ return -1;
case BTN_ENTER:
case BTN_RIGHT:
strcpy(filename, files[selected]); strcpy(filename, files[selected]);
return 0; return 0;
} }

View File

@ -1,3 +1,4 @@
#include <sysdefs.h>
#include <ff.h> #include <ff.h>
FATFS FatFs; /* File system object for logical drive */ FATFS FatFs; /* File system object for logical drive */
@ -23,6 +24,11 @@ void fsInit(){
f_mount(0, &FatFs); f_mount(0, &FatFs);
}; };
void fsReInit(){
f_mount(0, NULL);
f_mount(0, &FatFs);
};
int readFile(char * filename, char * data, int len){ int readFile(char * filename, char * data, int len){
FIL file; FIL file;
UINT readbytes; UINT readbytes;