diff --git a/micro_ondes/esp_wifi/main.py b/micro_ondes/esp_wifi/main.py index a61757a..ee0ef10 100644 --- a/micro_ondes/esp_wifi/main.py +++ b/micro_ondes/esp_wifi/main.py @@ -76,35 +76,24 @@ def init_hardware(): mlx_temperature_sensor = temperature_sensor.MLX90614(temperature_sensor_i2c) -def on_received_cooking_state_update(state, is_error=False, is_terminated=False): - """Callback executed when state changes are received from the LoRa board over UART.""" - if cooking_state: - if is_error: - cooking_state.set_state(cookingState.CookingStates.ERROR) - elif is_terminated: - cooking_state.set_state(cookingState.CookingStates.ABORTED) - else: - cooking_state.set_state(state) - - def on_cooking_state_change(state): """Callback executed whenever local cooking state transitions.""" BLINK_INTERVAL_MS = 500 if status_led and cookingState: - if state == cookingState.CookingStates.IDLE: + if state.state == cookingState.CookingStates.IDLE: status_led.color = status_led.OFF status_led.blink_off() - elif state == cookingState.CookingStates.COOKING: + elif state.state == cookingState.CookingStates.COOKING: status_led.color = status_led.YELLOW status_led.blink_off() - elif state == cookingState.CookingStates.STIRRING_REQUIRED: + elif state.state == cookingState.CookingStates.STIRRING_REQUIRED: status_led.color = status_led.ORANGE status_led.blink_on(BLINK_INTERVAL_MS) - elif state == cookingState.CookingStates.ALERT: + elif state.state == cookingState.CookingStates.ALERT: status_led.color = status_led.RED status_led.blink_on(BLINK_INTERVAL_MS) - elif state == cookingState.CookingStates.DONE: + elif state.state == cookingState.CookingStates.DONE: status_led.color = status_led.GREEN status_led.blink_off() @@ -193,23 +182,20 @@ async def sensor_publisher_task(): async def uart_task(): """Polls incoming UART messages from the LoRa board using dynamic method fallback.""" + global cooking_state while True: if uart_device: try: cmd = uart_device.read_as_command() if cmd: - print("[UART] Command received from LoRa board:", cmd) + print("[UART] Command received from LoRa board:", cmd.command_type, cmd.payload) if ( hasattr(cmd, "command_type") - and cmd.command_type == UARTCommandType.STATE_UPDATE - and on_received_cooking_state_update + and cmd.command_type == UARTCommandType.COOKING_STATE_UPDATE ): - on_received_cooking_state_update( - cmd.payload.get("state"), - cmd.payload.get("is_error", False), - cmd.payload.get("is_terminated", False), - ) + if cooking_state: + cooking_state.set_state(cmd.payload.get("state")) except Exception as e: print("[UART Task] Error reading command:", e)