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;
};
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()){
static char night=0;
EVERY(100,2){
if(night!=isNight()){
night=isNight();
if(night){
backlightSetBrightness(GLOBAL(lcdbacklight));
lcdSetInvert(0);
} else {
push_queue(queue_setinvert);
}else{
backlightSetBrightness(0);
if(GLOBAL(dayinvert))
lcdSetInvert(1);
else
lcdSetInvert(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;
};

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 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;
}
}

View File

@ -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;
};
};

View File

@ -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(len<extlen)
continue;
if( strcmp(Finfo.fname+len-extlen, ext) != 0)
continue;
if (Finfo.fattrib & AM_DIR)
continue;
if( ctr++ < skip )
if( skip>0 ){
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<PERPAGE && selected==count){
skip--;
continue;
};
redraw:
if( count )
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++){
if( selected == i )
lcdPrint("*");
@ -67,14 +85,16 @@ int selectFile(char *filename, char *extension)
lcdRefresh();
key=getInputWait();
getInputWaitRelease();
if( key==BTN_DOWN ){
switch(key){
case BTN_DOWN:
if( selected < count-1 ){
selected++;
goto redraw;
}else{
skip++;
}
}else if( key==BTN_UP ){
break;
case BTN_UP:
if( selected > 0 ){
selected--;
goto redraw;
@ -83,9 +103,11 @@ int selectFile(char *filename, char *extension)
skip--;
}
}
}else if( key==BTN_LEFT ){
return 1;
}else if( key==BTN_RIGHT ){
break;
case BTN_LEFT:
return -1;
case BTN_ENTER:
case BTN_RIGHT:
strcpy(filename, files[selected]);
return 0;
}

View File

@ -1,3 +1,4 @@
#include <sysdefs.h>
#include <ff.h>
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;