|
|
|
|
@ -37,13 +37,27 @@ uint8_t heat_off[2] = {0, 0};
|
|
|
|
|
uint8_t input_state = 0;
|
|
|
|
|
uint8_t dev_state = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t startup = 1;
|
|
|
|
|
uint8_t eeprom_write = 0;
|
|
|
|
|
#define ONE_MINUTE 1536
|
|
|
|
|
uint16_t eeprom_clk = ONE_MINUTE;
|
|
|
|
|
|
|
|
|
|
/* gray code to change lookup table, index is old state .. new state */
|
|
|
|
|
int8_t state_change[16] = {0, 1, -1, 0, -1, 0, 0, 1, 1, 0, 0, -1, 0, -1, 1, 0};
|
|
|
|
|
//int8_t state_change[16] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ISR(TIM1_OVF_vect)
|
|
|
|
|
{
|
|
|
|
|
/* timeout for displaying target temperature */
|
|
|
|
|
if(setting_timeout) {setting_timeout--;}
|
|
|
|
|
if(eeprom_clk) {eeprom_clk--;}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
startup = 0;
|
|
|
|
|
eeprom_write = 1;
|
|
|
|
|
eeprom_clk = ONE_MINUTE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* incremtening softpwm, toggling output if needed */
|
|
|
|
|
heat_pwm++;
|
|
|
|
|
@ -139,7 +153,7 @@ inline void io_init(void)
|
|
|
|
|
inline void led_init(void)
|
|
|
|
|
{
|
|
|
|
|
TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << COM0B0) | (1 << WGM01) | (1 << WGM00);/* pwm enable: fast, A not inverted, B inverted */
|
|
|
|
|
TCCR0B = (1 << CS02) | (1 << CS00);/* prescaler / 1024 */
|
|
|
|
|
TCCR0B = (1 << CS00);/* prescaler / 1024 */
|
|
|
|
|
OCR0A = OCR0B = led_color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -175,7 +189,15 @@ inline void heat_init(void)
|
|
|
|
|
TCCR1B = (1 << WGM12) | (1 << CS10);/* some mode allowing to set timer TOP, no prescaler */
|
|
|
|
|
TIMSK1 = (1 << TOIE1);/* interupt on overflow */
|
|
|
|
|
OCR1A = 39063;
|
|
|
|
|
/* insert loading of heat setting here */
|
|
|
|
|
|
|
|
|
|
/* read eeprom */
|
|
|
|
|
while(EECR & (1 << EEPE)) {;}
|
|
|
|
|
EEAR = 0;
|
|
|
|
|
EECR = (1 << EERE);
|
|
|
|
|
target = EEDR << 8;
|
|
|
|
|
EEARL = 1;
|
|
|
|
|
EECR |= (1 << EERE);
|
|
|
|
|
target |= EEDR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void input_init(void)
|
|
|
|
|
@ -189,10 +211,10 @@ int main(void)
|
|
|
|
|
/* if we store the last setting somewhere calculate led_color from it before calling led_init() */
|
|
|
|
|
|
|
|
|
|
io_init();
|
|
|
|
|
led_init();
|
|
|
|
|
adc_init();
|
|
|
|
|
heat_init();
|
|
|
|
|
input_init();
|
|
|
|
|
led_init();
|
|
|
|
|
sei();
|
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
@ -210,6 +232,7 @@ int main(void)
|
|
|
|
|
if(dev_state)
|
|
|
|
|
{
|
|
|
|
|
heat_output = control_output();
|
|
|
|
|
if(startup && heat_output > 192) {heat_output = 192;}
|
|
|
|
|
heat_on[0] = 0;
|
|
|
|
|
heat_on[1] = 128;
|
|
|
|
|
heat_off[0] = heat_output;
|
|
|
|
|
@ -225,6 +248,23 @@ int main(void)
|
|
|
|
|
if(!dev_state) {led_off();}
|
|
|
|
|
else if(setting_timeout) {led_set(target);}
|
|
|
|
|
else {led_set(temperature);}
|
|
|
|
|
|
|
|
|
|
if(eeprom_write && dev_state)
|
|
|
|
|
{
|
|
|
|
|
while(EECR & (1 << EEPE)) {;}
|
|
|
|
|
EEARL = 0;
|
|
|
|
|
EEDR = (target >> 8) & 0xff;
|
|
|
|
|
EECR |= (1 << EEMPE);
|
|
|
|
|
EECR |= (1 << EEPE);
|
|
|
|
|
|
|
|
|
|
while(EECR & (1 << EEPE)) {;}
|
|
|
|
|
EEARL = 1;
|
|
|
|
|
EEDR = target & 0xff;
|
|
|
|
|
EECR |= (1 << EEMPE);
|
|
|
|
|
EECR |= (1 << EEPE);
|
|
|
|
|
|
|
|
|
|
eeprom_write = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|