Replaced 5 step if-else by switch-case

This commit is contained in:
Stefan Kalscheuer 2018-02-10 12:42:39 +01:00
parent 4ca0582ff3
commit 43f65a2a66
2 changed files with 18 additions and 13 deletions

View File

@ -141,15 +141,20 @@ int main(void) {
led = GREEN_BLINK; // Set green LED blink for coffee. led = GREEN_BLINK; // Set green LED blink for coffee.
} }
if (make_coffee == 1) { switch (make_coffee) {
case 1:
pump_time = TIME_1_ESPRESSO; // 1 cup of espresso (2s preinfusion included). pump_time = TIME_1_ESPRESSO; // 1 cup of espresso (2s preinfusion included).
} else if (make_coffee == 2) { break;
case 2:
pump_time = TIME_2_ESPRESSO; // 2 cups of espresso (2s preinfusion included). pump_time = TIME_2_ESPRESSO; // 2 cups of espresso (2s preinfusion included).
} else if (make_coffee == 3) { break;
case 3:
pump_time = TIME_1_COFFEE; // 1 cup of coffee. pump_time = TIME_1_COFFEE; // 1 cup of coffee.
} else if (make_coffee == 4) { break;
case 4:
pump_time = TIME_2_COFFEE; // 2 cups of coffee. pump_time = TIME_2_COFFEE; // 2 cups of coffee.
} else { break;
default:
make_coffee = 0; make_coffee = 0;
} }
@ -244,7 +249,7 @@ void init() {
/** /**
* Clear bits and set controller to sleep mode. * Clear bits and set controller to sleep mode.
*/ */
void power_off() { void power_off(void) {
cli(); // Disable interrupts. cli(); // Disable interrupts.
set_bit(GIMSK, INT0); // Activate interrupt 0 (for wake-up). set_bit(GIMSK, INT0); // Activate interrupt 0 (for wake-up).
clear_bit(TIMSK, TOIE1); // Deactivate timer 1. clear_bit(TIMSK, TOIE1); // Deactivate timer 1.

View File

@ -130,8 +130,8 @@
#define VIOLET_BLINK 0b00100010 #define VIOLET_BLINK 0b00100010
// Prototypes: // Prototypes:
void init(); // Initialization. void init(void); // Initialization.
void power_off(); // Power off to sleep mode. void power_off(void); // Power off to sleep mode.
void update_water(void); // Update water state. void update_water(void); // Update water state.
void update_temperature(void); // Update temperature state. void update_temperature(void); // Update temperature state.
unsigned int detect_zero_crossing(void); // Detect zero crossing. unsigned int detect_zero_crossing(void); // Detect zero crossing.