Fix changing cooking state
This commit is contained in:
@@ -76,35 +76,24 @@ def init_hardware():
|
|||||||
mlx_temperature_sensor = temperature_sensor.MLX90614(temperature_sensor_i2c)
|
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):
|
def on_cooking_state_change(state):
|
||||||
"""Callback executed whenever local cooking state transitions."""
|
"""Callback executed whenever local cooking state transitions."""
|
||||||
BLINK_INTERVAL_MS = 500
|
BLINK_INTERVAL_MS = 500
|
||||||
|
|
||||||
if status_led and cookingState:
|
if status_led and cookingState:
|
||||||
if state == cookingState.CookingStates.IDLE:
|
if state.state == cookingState.CookingStates.IDLE:
|
||||||
status_led.color = status_led.OFF
|
status_led.color = status_led.OFF
|
||||||
status_led.blink_off()
|
status_led.blink_off()
|
||||||
elif state == cookingState.CookingStates.COOKING:
|
elif state.state == cookingState.CookingStates.COOKING:
|
||||||
status_led.color = status_led.YELLOW
|
status_led.color = status_led.YELLOW
|
||||||
status_led.blink_off()
|
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.color = status_led.ORANGE
|
||||||
status_led.blink_on(BLINK_INTERVAL_MS)
|
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.color = status_led.RED
|
||||||
status_led.blink_on(BLINK_INTERVAL_MS)
|
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.color = status_led.GREEN
|
||||||
status_led.blink_off()
|
status_led.blink_off()
|
||||||
|
|
||||||
@@ -193,23 +182,20 @@ async def sensor_publisher_task():
|
|||||||
|
|
||||||
async def uart_task():
|
async def uart_task():
|
||||||
"""Polls incoming UART messages from the LoRa board using dynamic method fallback."""
|
"""Polls incoming UART messages from the LoRa board using dynamic method fallback."""
|
||||||
|
global cooking_state
|
||||||
while True:
|
while True:
|
||||||
if uart_device:
|
if uart_device:
|
||||||
try:
|
try:
|
||||||
cmd = uart_device.read_as_command()
|
cmd = uart_device.read_as_command()
|
||||||
|
|
||||||
if cmd:
|
if cmd:
|
||||||
print("[UART] Command received from LoRa board:", cmd)
|
print("[UART] Command received from LoRa board:", cmd.command_type, cmd.payload)
|
||||||
if (
|
if (
|
||||||
hasattr(cmd, "command_type")
|
hasattr(cmd, "command_type")
|
||||||
and cmd.command_type == UARTCommandType.STATE_UPDATE
|
and cmd.command_type == UARTCommandType.COOKING_STATE_UPDATE
|
||||||
and on_received_cooking_state_update
|
|
||||||
):
|
):
|
||||||
on_received_cooking_state_update(
|
if cooking_state:
|
||||||
cmd.payload.get("state"),
|
cooking_state.set_state(cmd.payload.get("state"))
|
||||||
cmd.payload.get("is_error", False),
|
|
||||||
cmd.payload.get("is_terminated", False),
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[UART Task] Error reading command:", e)
|
print("[UART Task] Error reading command:", e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user