Fix a few things.

This commit is contained in:
Stefan `Sec` Zehl 2011-07-31 22:13:06 +02:00
parent c95eb0844f
commit aa821fca3f
9 changed files with 67 additions and 27 deletions

View File

@ -5,6 +5,7 @@
#include "lcd/fonts/smallfonts.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "usb/usbmsc.h"
#include "basic/random.h"
/**************************************************************************/
@ -12,12 +13,18 @@
void main_default(void) {
systickInit(SYSTICKSPEED);
if(getInputRaw()==BTN_ENTER){
switch(getInputRaw()){
case BTN_ENTER:
ISPandReset();
break;
case BTN_DOWN:
usbMSCInit();
while(1)
delayms_power(100);
break;
};
readConfig();
applyConfig();
randomInit();
return;
@ -41,12 +48,13 @@ void tick_default(void) {
if(ctr>100/SYSTICKSPEED){
if(isNight()){
backlightSetBrightness(GLOBAL(lcdbacklight));
if(GLOBAL(nightinvert))
lcdSetInvert(0);
} else {
backlightSetBrightness(0);
if(GLOBAL(nightinvert))
if(GLOBAL(dayinvert))
lcdSetInvert(1);
else
lcdSetInvert(0);
}
}

View File

@ -29,6 +29,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +49,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

View File

@ -29,6 +29,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +49,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

View File

@ -34,6 +34,9 @@ void rbInit() {
gpioSetDir(RB_BTN4, gpioDirection_Input);
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
// prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;

View File

@ -81,6 +81,7 @@
#define RB_PWR_GOOD 1,8
#define RB_PWR_CHRG 2,3
#define RB_PWR_CHRG_IO IOCON_PIO2_3
#define RB_PWR_LCDBL 0,0
#define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_0
@ -203,12 +204,13 @@ extern struct CDESC the_config[];
#define GLOBALversion (the_config[0].value)
#define GLOBALprivacy (the_config[1].value)
#define GLOBALnighttrigger (the_config[2].value)
#define GLOBALnightinvert (the_config[3].value)
#define GLOBALlcdbacklight (the_config[4].value)
#define GLOBALlcdmirror (the_config[5].value)
#define GLOBALlcdinvert (the_config[6].value)
#define GLOBALlcdcontrast (the_config[7].value)
#define GLOBALdaytrig (the_config[2].value)
#define GLOBALdaytrighyst (the_config[3].value)
#define GLOBALdayinvert (the_config[4].value)
#define GLOBALlcdbacklight (the_config[5].value)
#define GLOBALlcdmirror (the_config[6].value)
#define GLOBALlcdinvert (the_config[7].value)
#define GLOBALlcdcontrast (the_config[8].value)
#define GLOBAL(x) GLOBAL ## x

View File

@ -10,12 +10,13 @@
struct CDESC the_config[]= {
{"version", CFGVER, CFGVER, CFGVER},
{"privacy", 3, 0, 2 },
{"nighttrigger", 310/2, 0, 255},
{"nightinvert", 1, 0, 1 },
{"daytrig", 310/2, 0, 255},
{"daytrighyst", 10, 0, 50 },
{"dayinvert", 1, 0, 1 },
{"lcdbacklight", 50, 0, 100},
{"lcdmirror", 0, 0, 1 },
{"lcdinvert", 0, 0, 1 },
{"lcdcontrast", 3, 1, 6 },
{"lcdcontrast", 0, 1, 6 },
{ NULL, 0, 0, 0 },
};
@ -25,6 +26,7 @@ struct CDESC the_config[]= {
/**************************************************************************/
void applyConfig(){
if(GLOBAL(lcdcontrast)>0)
lcdSetContrast(GLOBAL(lcdcontrast));
return 0;
};

View File

@ -2,12 +2,12 @@
#include "basic/basic.h"
#define RANGE (10)
#define HYST (4)
uint32_t light=300*HYST;
#define SAMPCT (4)
uint32_t light=300*SAMPCT;
char _isnight=1;
#define threshold GLOBAL(nighttrigger)
#define threshold GLOBAL(daytrig)
#define RANGE GLOBAL(daytrighyst)
void LightCheck(void){
int iocon;
@ -21,7 +21,7 @@ void LightCheck(void){
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG;
light-=light/HYST;
light-=light/SAMPCT;
light += (adcRead(7)/2);
gpioSetDir(RB_LED3, iodir);
@ -31,15 +31,15 @@ void LightCheck(void){
threshold=320;
};
if(_isnight && light/HYST>(threshold+RANGE))
if(_isnight && light/SAMPCT>(threshold+RANGE))
_isnight=0;
if(!_isnight && light/HYST<threshold)
if(!_isnight && light/SAMPCT<threshold)
_isnight=1;
};
uint32_t GetLight(void){
return light/HYST;
return light/SAMPCT;
};
char isNight(void){

View File

@ -76,7 +76,7 @@ void mesh_recvloop(void){
};
if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()-(200/SYSTICKSPEED))/(1000/SYSTICKSPEED));
time_t toff=MO_TIME(buf)-((getTimer()-(1000/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet) // Do not live in the past.
_timet = toff;
continue;

View File

@ -30,4 +30,5 @@ void lcdSafeSetPixel(char x, char y, bool f);
bool lcdGetPixel(char x, char y);
void lcdShift(int x, int y, bool wrap);
void lcdSetContrast(int c);
void lcdSetInvert();
#endif