2011-07-23 23:51:28 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
|
|
|
#define RANGE (10)
|
|
|
|
#define HYST (4)
|
|
|
|
uint32_t light=300*HYST;
|
|
|
|
char _isnight=1;
|
|
|
|
|
2011-07-31 16:15:44 +00:00
|
|
|
#define threshold GLOBAL(nighttrigger)
|
2011-07-26 23:15:52 +00:00
|
|
|
|
2011-07-23 23:51:28 +00:00
|
|
|
void LightCheck(void){
|
|
|
|
int iocon;
|
|
|
|
char iodir;
|
|
|
|
|
|
|
|
int value;
|
|
|
|
|
|
|
|
iocon=IOCON_PIO1_11;
|
|
|
|
// iodir=gpioGetDir(RB_LED3);
|
|
|
|
iodir= (GPIO_GPIO1DIR & (1 << (RB_LED3) ))?1:0;
|
|
|
|
|
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Input);
|
|
|
|
IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG;
|
|
|
|
light-=light/HYST;
|
2011-07-31 16:15:44 +00:00
|
|
|
light += (adcRead(7)/2);
|
2011-07-23 23:51:28 +00:00
|
|
|
|
|
|
|
gpioSetDir(RB_LED3, iodir);
|
|
|
|
IOCON_PIO1_11=iocon;
|
|
|
|
|
2011-07-26 23:15:52 +00:00
|
|
|
if(threshold==0){ // uninitialized?
|
|
|
|
threshold=320;
|
2011-07-23 23:51:28 +00:00
|
|
|
};
|
|
|
|
|
2011-07-26 23:15:52 +00:00
|
|
|
if(_isnight && light/HYST>(threshold+RANGE))
|
2011-07-23 23:51:28 +00:00
|
|
|
_isnight=0;
|
|
|
|
|
2011-07-26 23:15:52 +00:00
|
|
|
if(!_isnight && light/HYST<threshold)
|
2011-07-23 23:51:28 +00:00
|
|
|
_isnight=1;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t GetLight(void){
|
|
|
|
return light/HYST;
|
|
|
|
};
|
|
|
|
|
|
|
|
char isNight(void){
|
|
|
|
return _isnight;
|
|
|
|
};
|