2011-05-21 10:05:48 +00:00
|
|
|
#include <sysinit.h>
|
2011-06-13 21:39:21 +00:00
|
|
|
#include "basic/basic.h"
|
2011-05-21 10:05:48 +00:00
|
|
|
|
2011-07-17 00:00:02 +00:00
|
|
|
#include "lcd/lcd.h"
|
2011-07-18 16:19:22 +00:00
|
|
|
#include "lcd/fonts/smallfonts.h"
|
2011-07-17 00:00:02 +00:00
|
|
|
#include "lcd/print.h"
|
|
|
|
#include "filesystem/ff.h"
|
2011-07-23 21:47:42 +00:00
|
|
|
#include "basic/random.h"
|
2011-07-17 00:00:02 +00:00
|
|
|
|
2011-05-21 10:05:48 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-07-17 00:00:02 +00:00
|
|
|
FATFS FatFs[_VOLUMES]; /* File system object for logical drive */
|
|
|
|
|
|
|
|
#define CONFIGLEN 2
|
|
|
|
int lcdInitConfig(){
|
2011-07-17 19:02:37 +00:00
|
|
|
FIL file; /* File objects */
|
2011-07-17 00:00:02 +00:00
|
|
|
BYTE buf[CONFIGLEN];
|
|
|
|
UINT readbytes;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
lcdFill(0); // clear display buffer
|
|
|
|
res=f_mount(0, &FatFs[0]);
|
|
|
|
lcdPrint("mount:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2011-07-17 19:02:37 +00:00
|
|
|
res=f_open(&file, "r0ket.cfg", FA_OPEN_EXISTING|FA_READ);
|
2011-07-17 00:00:02 +00:00
|
|
|
lcdPrint("open:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
2011-07-17 00:09:48 +00:00
|
|
|
lcdPrintln("new r0ket.cfg...");
|
|
|
|
|
2011-07-17 19:02:37 +00:00
|
|
|
res=f_open(&file, "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE);
|
2011-07-17 00:09:48 +00:00
|
|
|
lcdPrint("create:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
buf[0]='0';
|
|
|
|
buf[1]='0';
|
2011-07-17 19:02:37 +00:00
|
|
|
res = f_write(&file, buf, 2, &readbytes);
|
2011-07-17 00:09:48 +00:00
|
|
|
lcdPrint("write:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
lcdPrint("wrote:");
|
|
|
|
lcdPrintInt(readbytes);
|
|
|
|
lcdPrintln("b");
|
|
|
|
|
2011-07-17 19:02:37 +00:00
|
|
|
res=f_close(&file);
|
2011-07-17 00:09:48 +00:00
|
|
|
lcdPrint("close:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
return 2; // created. Still show screen
|
2011-07-17 00:00:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for(int i=0;i<CONFIGLEN;i++)
|
|
|
|
buf[i]=0;
|
|
|
|
|
2011-07-17 19:02:37 +00:00
|
|
|
res = f_read(&file, buf, 2, &readbytes);
|
2011-07-17 00:00:02 +00:00
|
|
|
lcdPrint("read:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
lcdPrint("r: ");
|
|
|
|
lcdPrintCharHex(buf[0]);
|
|
|
|
lcdPrintCharHex(buf[1]);
|
|
|
|
lcdNl();
|
|
|
|
|
|
|
|
if(buf[0] == '1')
|
|
|
|
lcdToggleFlag(LCD_INVERTED);
|
|
|
|
if(buf[1] == '1')
|
|
|
|
lcdToggleFlag(LCD_MIRRORX);
|
|
|
|
|
2011-07-17 19:02:37 +00:00
|
|
|
res=f_close(&file);
|
2011-07-17 00:00:02 +00:00
|
|
|
lcdPrint("close:");
|
|
|
|
lcdPrintln(f_get_rc_string(res));
|
|
|
|
if(res){
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-20 21:33:42 +00:00
|
|
|
void main_default(void) {
|
2011-06-13 21:19:18 +00:00
|
|
|
systickInit(10);
|
2011-07-04 20:49:35 +00:00
|
|
|
|
|
|
|
if(getInputRaw()==BTN_ENTER){
|
2011-07-18 20:09:31 +00:00
|
|
|
ISPandReset();
|
2011-07-04 20:49:35 +00:00
|
|
|
};
|
|
|
|
|
2011-07-17 00:00:02 +00:00
|
|
|
font=&Font_7x8;
|
|
|
|
if(lcdInitConfig()){
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-17 00:00:02 +00:00
|
|
|
getInputWait();
|
|
|
|
}else{
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-17 00:00:02 +00:00
|
|
|
};
|
2011-07-24 14:03:19 +00:00
|
|
|
randomInit();
|
2011-07-17 00:00:02 +00:00
|
|
|
|
2011-05-21 10:05:48 +00:00
|
|
|
return;
|
2011-06-13 21:19:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// every 10 ms
|
|
|
|
void tick_default(void) {
|
|
|
|
static int ctr;
|
|
|
|
ctr++;
|
2011-07-24 13:44:35 +00:00
|
|
|
incTimer();
|
2011-06-13 21:19:18 +00:00
|
|
|
if(ctr>100){
|
2011-07-25 21:26:18 +00:00
|
|
|
if(!adcMutex){
|
|
|
|
VoltageCheck();
|
|
|
|
LightCheck();
|
2011-07-25 21:41:26 +00:00
|
|
|
ctr=0;
|
|
|
|
}else{
|
|
|
|
ctr--;
|
2011-07-25 21:26:18 +00:00
|
|
|
};
|
2011-06-13 21:19:18 +00:00
|
|
|
};
|
2011-07-23 23:51:28 +00:00
|
|
|
|
|
|
|
if(isNight())
|
|
|
|
backlightSetBrightness(100);
|
|
|
|
else
|
|
|
|
backlightSetBrightness(0);
|
|
|
|
|
2011-06-13 21:39:21 +00:00
|
|
|
if(ctr%5==0){
|
2011-07-09 20:47:38 +00:00
|
|
|
|
|
|
|
if(GetVoltage()<3600
|
|
|
|
#ifdef SAFE
|
|
|
|
|| GetVoltage() > 10000 // pin not connected
|
|
|
|
#endif
|
|
|
|
){
|
2011-06-13 21:39:21 +00:00
|
|
|
IOCON_PIO1_11 = 0x0;
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Output);
|
|
|
|
if( (ctr/5)%10 == 1 )
|
|
|
|
gpioSetValue (RB_LED3, 1);
|
|
|
|
else
|
|
|
|
gpioSetValue (RB_LED3, 0);
|
|
|
|
};
|
|
|
|
};
|
2011-06-13 21:19:18 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
};
|