2011-05-21 10:05:48 +00:00
|
|
|
#include <sysinit.h>
|
2011-06-13 21:39:21 +00:00
|
|
|
#include "basic/basic.h"
|
2011-07-31 23:34:11 +00:00
|
|
|
#include "basic/config.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"
|
2011-08-04 22:49:00 +00:00
|
|
|
#include "lcd/image.h"
|
2011-07-17 00:00:02 +00:00
|
|
|
#include "filesystem/ff.h"
|
2011-07-31 20:13:06 +00:00
|
|
|
#include "usb/usbmsc.h"
|
2011-07-23 21:47:42 +00:00
|
|
|
#include "basic/random.h"
|
2011-08-04 17:00:02 +00:00
|
|
|
#include "funk/nrf24l01p.h"
|
2011-07-17 00:00:02 +00:00
|
|
|
|
2011-05-21 10:05:48 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-06-20 21:33:42 +00:00
|
|
|
void main_default(void) {
|
2011-07-26 22:25:24 +00:00
|
|
|
systickInit(SYSTICKSPEED);
|
2011-08-04 22:49:00 +00:00
|
|
|
|
|
|
|
//show bootscreen
|
|
|
|
lcdClear();
|
|
|
|
lcdLoadImage("r0ket.lcd");
|
|
|
|
lcdRefresh();
|
2011-08-04 23:44:34 +00:00
|
|
|
lcdClear();
|
2011-08-04 22:49:00 +00:00
|
|
|
|
|
|
|
switch(getInputRaw()){
|
2011-07-31 20:13:06 +00:00
|
|
|
case BTN_ENTER:
|
2011-08-05 21:33:31 +00:00
|
|
|
lcdPrint("ISP active");
|
2011-08-05 18:38:21 +00:00
|
|
|
lcdRefresh();
|
|
|
|
ReinvokeISP();
|
2011-07-31 20:13:06 +00:00
|
|
|
break;
|
2011-08-04 17:00:02 +00:00
|
|
|
case BTN_UP: // Reset config
|
2011-08-05 15:53:18 +00:00
|
|
|
saveConfig();
|
2011-08-04 17:00:02 +00:00
|
|
|
break;
|
2011-07-31 20:13:06 +00:00
|
|
|
case BTN_DOWN:
|
|
|
|
usbMSCInit();
|
2011-08-05 21:33:31 +00:00
|
|
|
while(1);
|
|
|
|
//delayms_power(100);
|
2011-07-31 20:13:06 +00:00
|
|
|
break;
|
2011-07-04 20:49:35 +00:00
|
|
|
};
|
|
|
|
|
2011-07-26 22:57:36 +00:00
|
|
|
readConfig();
|
2011-08-05 09:54:36 +00:00
|
|
|
if(getInputRaw()==BTN_RIGHT){
|
|
|
|
GLOBAL(develmode)=1;
|
|
|
|
applyConfig();
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
2011-08-01 21:49:41 +00:00
|
|
|
|
|
|
|
|
2011-08-05 21:33:31 +00:00
|
|
|
static void queue_setinvert(void){
|
2011-08-01 21:49:41 +00:00
|
|
|
lcdSetInvert(1);
|
|
|
|
};
|
2011-08-05 21:33:31 +00:00
|
|
|
static void queue_unsetinvert(void){
|
2011-08-01 21:49:41 +00:00
|
|
|
lcdSetInvert(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0)
|
|
|
|
|
2011-08-04 11:11:28 +00:00
|
|
|
// every SYSTICKSPEED ms
|
2011-06-13 21:19:18 +00:00
|
|
|
void tick_default(void) {
|
|
|
|
static int ctr;
|
|
|
|
ctr++;
|
2011-07-24 13:44:35 +00:00
|
|
|
incTimer();
|
2011-08-01 21:49:41 +00:00
|
|
|
|
2011-08-04 11:11:28 +00:00
|
|
|
EVERY(1024,0){
|
2011-07-25 21:26:18 +00:00
|
|
|
if(!adcMutex){
|
|
|
|
VoltageCheck();
|
|
|
|
LightCheck();
|
2011-07-25 21:41:26 +00:00
|
|
|
}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
|
|
|
|
2011-08-01 21:49:41 +00:00
|
|
|
static char night=0;
|
2011-08-05 21:33:31 +00:00
|
|
|
static char posleds = 0;
|
2011-08-04 11:11:28 +00:00
|
|
|
EVERY(128,2){
|
2011-08-05 21:33:31 +00:00
|
|
|
if( isNight() ){
|
|
|
|
if( GLOBAL(positionleds) ){
|
|
|
|
gpioSetValue (RB_LED0, 1);
|
|
|
|
gpioSetValue (RB_LED2, 1);
|
|
|
|
posleds = 1;
|
|
|
|
}else if( posleds = 1 ){
|
|
|
|
gpioSetValue (RB_LED0, 0);
|
|
|
|
gpioSetValue (RB_LED2, 0);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if( posleds ){
|
|
|
|
posleds = 0;
|
|
|
|
gpioSetValue (RB_LED0, 0);
|
|
|
|
gpioSetValue (RB_LED2, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-01 21:49:41 +00:00
|
|
|
if(night!=isNight()){
|
|
|
|
night=isNight();
|
|
|
|
if(night){
|
|
|
|
backlightSetBrightness(GLOBAL(lcdbacklight));
|
2011-08-02 08:50:51 +00:00
|
|
|
push_queue(queue_unsetinvert);
|
2011-08-01 21:49:41 +00:00
|
|
|
}else{
|
|
|
|
backlightSetBrightness(0);
|
2011-08-02 08:50:51 +00:00
|
|
|
push_queue(queue_setinvert);
|
2011-08-05 21:33:31 +00:00
|
|
|
};
|
2011-08-01 21:49:41 +00:00
|
|
|
};
|
|
|
|
};
|
2011-07-23 23:51:28 +00:00
|
|
|
|
2011-07-09 20:47:38 +00:00
|
|
|
|
2011-08-01 21:49:41 +00:00
|
|
|
EVERY(50,0){
|
2011-08-04 23:22:34 +00:00
|
|
|
if(GLOBAL(chargeled)){
|
2011-08-12 04:43:01 +00:00
|
|
|
char iodir= (GPIO_GPIO1DIR & (1 << (11) ))?1:0;
|
|
|
|
if(GetChrgStat()) {
|
|
|
|
if (iodir == gpioDirection_Input){
|
|
|
|
IOCON_PIO1_11 = 0x0;
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Output);
|
|
|
|
gpioSetValue (RB_LED3, 1);
|
|
|
|
LightCheck();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (iodir != gpioDirection_Input){
|
|
|
|
gpioSetValue (RB_LED3, 0);
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Input);
|
|
|
|
IOCON_PIO1_11 = 0x41;
|
|
|
|
LightCheck();
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 23:22:34 +00:00
|
|
|
};
|
|
|
|
|
2011-08-01 21:49:41 +00:00
|
|
|
if(GetVoltage()<3600){
|
2011-06-13 21:39:21 +00:00
|
|
|
IOCON_PIO1_11 = 0x0;
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Output);
|
2011-07-26 22:25:24 +00:00
|
|
|
if( (ctr/(50/SYSTICKSPEED))%10 == 1 )
|
2011-06-13 21:39:21 +00:00
|
|
|
gpioSetValue (RB_LED3, 1);
|
|
|
|
else
|
|
|
|
gpioSetValue (RB_LED3, 0);
|
|
|
|
};
|
|
|
|
};
|
2011-08-04 11:11:28 +00:00
|
|
|
|
|
|
|
EVERY(4096,17){
|
2011-08-04 17:00:02 +00:00
|
|
|
push_queue(nrf_check_reset);
|
2011-08-04 11:11:28 +00:00
|
|
|
};
|
2011-06-13 21:19:18 +00:00
|
|
|
return;
|
|
|
|
};
|