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,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.

View File

@ -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.