From 5c5e894a9a1b78a64d6f3dffca3c45c7cf163643 Mon Sep 17 00:00:00 2001 From: Paul Goeser Date: Tue, 12 Mar 2013 01:27:44 +0100 Subject: [PATCH] =?UTF-8?q?device=5Fon(),=20device=5Foff(),=20chaned=20max?= =?UTF-8?q?=20temperature=20to=20105=C2=B0C=20even=20though=20max=20displa?= =?UTF-8?q?y=20temp=20is=20still=20at=2080=C2=B0C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firmware/cup.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/firmware/cup.c b/firmware/cup.c index b726d52..1777f7c 100644 --- a/firmware/cup.c +++ b/firmware/cup.c @@ -19,7 +19,7 @@ #define LED_RED_TEMP 800 #define TARGET_TEMP_MIN 300 -#define TARGET_TEMP_MAX 1520 +#define TARGET_TEMP_MAX 1050 uint8_t setting_timeout = 0; @@ -109,16 +109,22 @@ ISR(PCINT0_vect) { dev_state = !dev_state; toggle_timeout = TOGGLE_TIMEOUT; + if(dev_state) { + device_on(); + } else { + device_off(); + } + } int8_t change = state_change[((input_state & 3) << 2) | (new_state & 3)]; if(change) { target += change * 6;//0.6K * 4 per step 10; // 1 celsius per step - //if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;} - //else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;} - if(target < LED_GREEN_TEMP) {target = LED_GREEN_TEMP;} - else if(target > LED_RED_TEMP) {target = LED_RED_TEMP;} + if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;} + else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;} + //if(target < LED_GREEN_TEMP) {target = LED_GREEN_TEMP;} + //else if(target > LED_RED_TEMP) {target = LED_RED_TEMP;} setting_timeout = TIMEOUT; } @@ -210,10 +216,6 @@ inline void led_init(void) inline void led_set(uint16_t value) { - if(!led_is_on){ - led_init(); - led_is_on = 1; - } uint8_t pwmval; if (LED_GREEN_TEMP <= value && value < LED_RED_TEMP) { pwmval = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP); @@ -228,13 +230,28 @@ inline void led_set(uint16_t value) inline void led_off(void) { - led_is_on = 0; - TCCR0B = 0; // stop pwm - TCCR0A = 0; // disconnect outputs; // OCR0A = 0; // OCR0B = 255; } +inline void device_off(void) +{ + TCCR0B = 0; // stop pwm + TCCR0A = 0; // disconnect outputs; + ADCSRA &= ~(1<