2011-07-26 22:57:36 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
2011-08-01 03:22:24 +00:00
|
|
|
#include "lcd/display.h"
|
2011-07-26 22:57:36 +00:00
|
|
|
#include "lcd/print.h"
|
|
|
|
#include "filesystem/ff.h"
|
|
|
|
#include "basic/random.h"
|
2011-07-31 23:12:21 +00:00
|
|
|
#include "basic/config.h"
|
2011-07-26 22:57:36 +00:00
|
|
|
|
2011-08-04 14:57:18 +00:00
|
|
|
#define CFGVER 3
|
2011-07-31 16:15:44 +00:00
|
|
|
|
|
|
|
struct CDESC the_config[]= {
|
2011-08-04 12:33:39 +00:00
|
|
|
{"version", CFGVER, CFGVER, CFGVER, 0, 0},
|
2011-08-02 00:09:37 +00:00
|
|
|
// dflt min max
|
2011-08-04 12:33:39 +00:00
|
|
|
{"privacy", 3, 0, 2 , 0, 0},
|
|
|
|
{"daytrig", 310/2, 0, 255, 0, 0},
|
|
|
|
{"daytrighyst", 10, 0, 50 , 0, 0},
|
|
|
|
{"dayinvert", 1, 0, 1 , 0, 0},
|
2011-08-06 05:15:26 +00:00
|
|
|
{"lcdbacklight", 30, 0, 100, 0, 0},
|
2011-08-04 12:33:39 +00:00
|
|
|
{"lcdmirror", 0, 0, 1 , 0, 0},
|
|
|
|
{"lcdinvert", 0, 0, 1 , 0, 0},
|
|
|
|
{"lcdcontrast", 14, 0, 31 , 0, 0},
|
2011-08-04 13:02:51 +00:00
|
|
|
{"alivechk", 0, 0, 2 , 1, CFG_TYPE_DEVEL},
|
|
|
|
{"develmode", 0, 0, 1 , 1, CFG_TYPE_DEVEL},
|
2011-08-04 12:33:39 +00:00
|
|
|
{"flamemax", 255, 0, 255, 1, CFG_TYPE_FLAME},
|
|
|
|
{"flamemin", 0, 0, 255, 1, CFG_TYPE_FLAME},
|
|
|
|
{"flamespeed", 1, 1, 100, 1, CFG_TYPE_FLAME},
|
|
|
|
{"flamemaxw", 255, 1, 255, 1, CFG_TYPE_FLAME},
|
|
|
|
{"flameminw", 0x8f, 1, 255, 1, CFG_TYPE_FLAME},
|
2011-08-04 14:57:18 +00:00
|
|
|
{"l0nick", 0, 0, 1 , 0, 0},
|
2011-08-12 12:51:10 +00:00
|
|
|
{"chargeled", 0, 0, 1 , 0, 0},
|
2011-08-06 05:15:26 +00:00
|
|
|
{"positionleds", 0, 0, 1 , 0, 0},
|
2011-08-04 12:33:39 +00:00
|
|
|
{ NULL, 0, 0, 0 , 0, 0},
|
2011-07-31 16:15:44 +00:00
|
|
|
};
|
2011-07-26 22:57:36 +00:00
|
|
|
|
2011-07-31 23:12:21 +00:00
|
|
|
char nickname[MAXNICK]="anonymous";
|
|
|
|
char nickfont[FILENAMELEN];
|
2011-08-04 14:57:18 +00:00
|
|
|
char nickl0[FILENAMELEN];
|
2011-07-31 23:12:21 +00:00
|
|
|
|
2011-07-26 22:57:36 +00:00
|
|
|
#define CONFFILE "r0ket.cfg"
|
2011-07-31 16:15:44 +00:00
|
|
|
#define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++)
|
2011-07-26 22:57:36 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-07-31 16:15:44 +00:00
|
|
|
void applyConfig(){
|
2011-07-31 20:13:06 +00:00
|
|
|
if(GLOBAL(lcdcontrast)>0)
|
|
|
|
lcdSetContrast(GLOBAL(lcdcontrast));
|
2011-08-05 17:24:58 +00:00
|
|
|
if(GLOBAL(develmode))
|
|
|
|
enableConfig(CFG_TYPE_DEVEL,1);
|
|
|
|
if(isNight())
|
|
|
|
backlightSetBrightness(GLOBAL(lcdbacklight));
|
2011-07-31 16:15:44 +00:00
|
|
|
};
|
|
|
|
|
2011-07-26 22:57:36 +00:00
|
|
|
int saveConfig(void){
|
|
|
|
FIL file; /* File object */
|
|
|
|
UINT writebytes;
|
2011-07-31 16:15:44 +00:00
|
|
|
UINT allwrite=0;
|
2011-07-26 22:57:36 +00:00
|
|
|
int res;
|
|
|
|
|
2011-08-04 12:55:09 +00:00
|
|
|
lcdClear();
|
|
|
|
|
2011-07-26 22:57:36 +00:00
|
|
|
res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE);
|
|
|
|
lcdPrint("create:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2011-07-31 16:15:44 +00:00
|
|
|
CONF_ITER{
|
|
|
|
res = f_write(&file, &the_config[i].value, sizeof(uint8_t), &writebytes);
|
|
|
|
allwrite+=writebytes;
|
|
|
|
if(res){
|
|
|
|
lcdPrint("write:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
};
|
2011-07-26 22:57:36 +00:00
|
|
|
lcdPrint("write:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
2011-07-31 16:15:44 +00:00
|
|
|
lcdPrint(" (");
|
|
|
|
lcdPrintInt(allwrite);
|
|
|
|
lcdPrintln("b)");
|
2011-07-26 22:57:36 +00:00
|
|
|
|
|
|
|
res=f_close(&file);
|
|
|
|
lcdPrint("close:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
int readConfig(void){
|
|
|
|
FIL file; /* File object */
|
|
|
|
UINT readbytes;
|
2011-07-31 16:15:44 +00:00
|
|
|
UINT allread;
|
2011-07-26 22:57:36 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res=f_open(&file, CONFFILE, FA_OPEN_EXISTING|FA_READ);
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2011-07-31 16:15:44 +00:00
|
|
|
CONF_ITER{
|
|
|
|
res = f_read(&file, &the_config[i].value, sizeof(uint8_t), &readbytes);
|
|
|
|
allread+=readbytes;
|
|
|
|
if(GLOBAL(version) != CFGVER){
|
|
|
|
GLOBAL(version) =CFGVER;
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
if(res || GLOBAL(version) != CFGVER)
|
|
|
|
return 1;
|
2011-07-26 22:57:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
res=f_close(&file);
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
2011-07-31 16:15:44 +00:00
|
|
|
|
|
|
|
applyConfig();
|
2011-07-26 22:57:36 +00:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2011-08-04 12:33:39 +00:00
|
|
|
void enableConfig(char type,char enable){
|
|
|
|
CONF_ITER{
|
|
|
|
if(the_config[i].type == type){
|
|
|
|
the_config[i].disabled=!enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|