void STM_refresh(void) { if(state_is_new) { execute_state_entry(AppState); } switch(AppState) { case READY_STATE: if (if_valve_open()) { STM_set_state(DRINKING_STATE); } break; case DRINKING_STATE: if (ADC_get_result() < ADC_LOW_SWITCH_VALUE) { STM_set_state(VERIFICATION_STATE); } if (If0_01secPassed) { LCD_display_time(get_current_time()); } break; case VERIFICATION_STATE: if(If0_01secPassed) { verification_state_duration ++; } if(ADC_get_result() > ADC_LOW_SWITCH_VALUE) { AppState = DRINKING_STATE; // don't execute drinking_state entry! } if(verification_state_duration >= VERIFICATION_LENGTH) { STM_set_state(DISPLAY_STATE); } break; case DISPLAY_STATE: if (If0_01secPassed) { led_flashing_duration ++; if (led_flashing_duration >= LED_BLINK_LENGTH) { led_off(); } } // poll the ADC (wait for the beer) if ((ADC_get_result() > ADC_HIGH_SWITCH_VALUE) && ! if_valve_open()) { STM_set_state(READY_STATE); } break; case ADC_STATE: // ADC_STATE NORMAL OPERATION if (If0_01secPassed) { LCD_carriage_return(); LCD_putsub(" "); LCD_carriage_return(); LCD_display_number((uint16_t)ADC_get_result()); } break; } clear_flags(); }
uint16_t ADC_get_result_from(uint8_t input){ ADC_set_input(input); return ADC_get_result(); }