2011-07-23 23:51:28 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
2011-07-31 23:12:21 +00:00
|
|
|
#include "basic/config.h"
|
2011-07-23 23:51:28 +00:00
|
|
|
|
2011-07-31 20:13:06 +00:00
|
|
|
#define SAMPCT (4)
|
2011-08-01 03:06:20 +00:00
|
|
|
uint32_t light=150*SAMPCT;
|
2011-07-23 23:51:28 +00:00
|
|
|
char _isnight=1;
|
|
|
|
|
2011-07-31 20:13:06 +00:00
|
|
|
#define threshold GLOBAL(daytrig)
|
|
|
|
#define RANGE GLOBAL(daytrighyst)
|
2011-07-26 23:15:52 +00:00
|
|
|
|
2011-07-23 23:51:28 +00:00
|
|
|
void LightCheck(void){
|
|
|
|
int iocon;
|
|
|
|
char iodir;
|
|
|
|
|
|
|
|
iocon=IOCON_PIO1_11;
|
2011-08-05 14:54:45 +00:00
|
|
|
//LED3 is on pin 11
|
|
|
|
iodir= (GPIO_GPIO1DIR & (1 << (11) ))?1:0;
|
2011-07-23 23:51:28 +00:00
|
|
|
|
2011-08-12 04:43:01 +00:00
|
|
|
//gpioSetDir(RB_LED3, gpioDirection_Input);
|
|
|
|
if (iodir == gpioDirection_Input) {
|
|
|
|
IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG;
|
|
|
|
light-=light/SAMPCT;
|
|
|
|
light += (adcRead(7)/2);
|
2011-07-23 23:51:28 +00:00
|
|
|
|
2011-08-12 04:43:01 +00:00
|
|
|
gpioSetDir(RB_LED3, iodir);
|
|
|
|
IOCON_PIO1_11=iocon;
|
2011-07-23 23:51:28 +00:00
|
|
|
|
2011-08-12 04:43:01 +00:00
|
|
|
if(_isnight && light/SAMPCT>(threshold+RANGE))
|
|
|
|
_isnight=0;
|
|
|
|
|
|
|
|
if(!_isnight && light/SAMPCT<threshold)
|
|
|
|
_isnight=1;
|
|
|
|
} else {
|
2011-07-23 23:51:28 +00:00
|
|
|
_isnight=1;
|
2011-08-12 04:43:01 +00:00
|
|
|
|
|
|
|
}
|
2011-07-23 23:51:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t GetLight(void){
|
2011-07-31 20:13:06 +00:00
|
|
|
return light/SAMPCT;
|
2011-07-23 23:51:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
char isNight(void){
|
|
|
|
return _isnight;
|
|
|
|
};
|