{ 0, 1, PWMLED_ADC_SHIFT }, // pwmled 1
{ 0, 1, PWMLED_ADC_SHIFT }, // pwmled 2
{ 0, 1, PWMLED_ADC_SHIFT }, // pwmled 3
- { 0, 1, 3 }, // ambient
+ { 0, 1, AMBIENT_ADC_SHIFT }, // ambient
{ 0, 1, 0 }, // battery
{ 0, 1, 0 }, // gain20
{ 0, 1, 0 }, // buttons
#include "lights.h"
+#define AMBIENT_VAL_SHIFT 3
static uint16_t ambient_val;
volatile unsigned char ambient_zone;
* and having small overlaps in order to provide a bit of hysteresis.
*/
static ambient_zone_t ambient_zones[] = {
- { 0x0000, 0xa400 }, // dark
- { 0xa000, 0xc000 },
- { 0xbe00, 0xc800 },
- { 0xc600, 0xffff }
+ { 0x0000 , 0x0290<<AMBIENT_VAL_SHIFT }, // dark
+ { 0x0280<<AMBIENT_VAL_SHIFT, 0x0300<<AMBIENT_VAL_SHIFT }, // evening
+ { 0x02f8<<AMBIENT_VAL_SHIFT, 0x0320<<AMBIENT_VAL_SHIFT }, // dawn
+ { 0x0318<<AMBIENT_VAL_SHIFT, 0xffff }, // day
};
#define N_AMBIENT_ZONES (sizeof(ambient_zones)/sizeof(ambient_zones[0]))
{
unsigned char old_zone = ambient_zone;
- ambient_val += adcval - (ambient_val >> 3);
+ ambient_val += adcval - (ambient_val
+ >> (AMBIENT_VAL_SHIFT - AMBIENT_ADC_SHIFT));
while (ambient_zones[ambient_zone].lo > ambient_val)
ambient_zone--;
void gpio_set(unsigned char n, unsigned char on);
/* ambient.c */
+#define AMBIENT_ADC_SHIFT 0 /* 1 measurement per callback */
void init_ambient();
extern volatile unsigned char ambient_zone;
void ambient_adc(uint16_t adc_val);