From 43f65a2a66636af6badfc200d743590078d4e05a Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sat, 10 Feb 2018 12:42:39 +0100 Subject: [PATCH] Replaced 5 step if-else by switch-case --- firmware/main.c | 27 ++++++++++++++++----------- firmware/main.h | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 5349000..da31095 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -141,16 +141,21 @@ int main(void) { led = GREEN_BLINK; // Set green LED blink for coffee. } - if (make_coffee == 1) { - pump_time = TIME_1_ESPRESSO; // 1 cup of espresso (2s preinfusion included). - } else if (make_coffee == 2) { - pump_time = TIME_2_ESPRESSO; // 2 cups of espresso (2s preinfusion included). - } else if (make_coffee == 3) { - pump_time = TIME_1_COFFEE; // 1 cup of coffee. - } else if (make_coffee == 4) { - pump_time = TIME_2_COFFEE; // 2 cups of coffee. - } else { - make_coffee = 0; + switch (make_coffee) { + case 1: + pump_time = TIME_1_ESPRESSO; // 1 cup of espresso (2s preinfusion included). + break; + case 2: + pump_time = TIME_2_ESPRESSO; // 2 cups of espresso (2s preinfusion included). + break; + case 3: + pump_time = TIME_1_COFFEE; // 1 cup of coffee. + break; + case 4: + pump_time = TIME_2_COFFEE; // 2 cups of coffee. + break; + default: + make_coffee = 0; } user_time_counter = 0; // Reset user time counter. @@ -244,7 +249,7 @@ void init() { /** * Clear bits and set controller to sleep mode. */ -void power_off() { +void power_off(void) { cli(); // Disable interrupts. set_bit(GIMSK, INT0); // Activate interrupt 0 (for wake-up). clear_bit(TIMSK, TOIE1); // Deactivate timer 1. diff --git a/firmware/main.h b/firmware/main.h index 3d77e72..e87da8f 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -130,8 +130,8 @@ #define VIOLET_BLINK 0b00100010 // Prototypes: -void init(); // Initialization. -void power_off(); // Power off to sleep mode. +void init(void); // Initialization. +void power_off(void); // Power off to sleep mode. void update_water(void); // Update water state. void update_temperature(void); // Update temperature state. unsigned int detect_zero_crossing(void); // Detect zero crossing.