X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=heater.git;a=blobdiff_plain;f=firmware%2Fmain.c;h=a6cc1a8366350e69b728ace665e976479805a1ed;hp=0d45ac93d9a6429bc040486f173f93a2f7d9b0bc;hb=cba1b50d5359b6b983c179b6ff6a59aee39d5706;hpb=e847a9fc0c504419a8e2f93a813312d0be94c7ef diff --git a/firmware/main.c b/firmware/main.c index 0d45ac9..a6cc1a8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -21,14 +21,9 @@ * Buttons: * There are two buttons (+ and -). Any button can wake the system up from * the power-down state. - * TODO: When the system is woken up by the "-" button, - * it starts with the minimum output power, when it is woken up by the "+" - * button, it start with the maximum output power. * When running, the "-" button is used for decreasing the output power, * the "+" button is for increasing it. - * When on the lowest power state, the "-" button switches the system off. - * Long "-" button press switches the system off, long "+" button - * press sets the output power to maximum. + * Any long button press switches the system off. * * Status LED: * When powering up by a button press, the LED goes on to provide a visual @@ -390,8 +385,14 @@ static void status_led_next_pattern() if (display_power_level) { n_blinks = power_level + 1; - blink_on_time = 1; - blink_off_time = 2; + if (batt_on >> 8 == batt_off >> 8) { // load unplugged + n_blinks = 2 * n_blinks; + blink_on_time = 0; + blink_off_time = 0; + } else { + blink_on_time = 2; + blink_off_time = 2; + } } else { unsigned char b_level = battery_level(); if (b_level) { @@ -404,11 +405,11 @@ static void status_led_next_pattern() } n_blinks = b_level + 1; - blink_on_time = 3; + blink_on_time = 4; blink_off_time = 0; } - blink_counter = 10; + blink_counter = 12; display_power_level = !display_power_level; } @@ -433,19 +434,12 @@ static void button_pressed(unsigned char button, unsigned char long_press) { // ignore simlultaneous button 1 and 2 press if (long_press) { - if (button == 1) { - power_down(); - return; - } else if (button == 2) { - power_level = N_POWER_LEVELS-1; - } + power_down(); + return; } else { // short press if (button == 1) { if (power_level > 0) { --power_level; - } else { - power_down(); - return; } } else if (button == 2) { if (power_level < N_POWER_LEVELS-1) { @@ -569,6 +563,10 @@ int main() log_byte(batt_on >> 8); #endif } + if (jiffies == 0) { + log_byte(batt_on >> 8); + log_byte(batt_off >> 8); + } log_flush(); } }