Microwave Screen + defrost mode

This commit is contained in:
2026-08-06 19:27:35 +02:00
parent 25e635e207
commit 35a330e7ae
4 changed files with 169 additions and 29 deletions
+25 -21
View File
@@ -2,9 +2,9 @@ import gc
import sys
import time
import _thread
from lib.microwaveScreen import MicrowaveScreen
import uasyncio as asyncio
from machine import Pin, SoftI2C
import framebuf
import ssd1306
# Clean memory immediately
@@ -30,7 +30,9 @@ data_queue = SafeQueue()
lora = None
uart_device = None
magnetron_led = None
display = None
microwave_screen = None
defrost_mode = False
PING_PAYLOAD = {
"id": DEVICE_ID,
@@ -39,7 +41,7 @@ PING_PAYLOAD = {
def init_hardware():
"""Initializes all hardware components."""
global lora, uart_device, magnetron_led, display
global lora, uart_device, magnetron_led, microwave_screen
print("[Main] Initializing hardware peripherals...")
@@ -47,7 +49,15 @@ def init_hardware():
vext = Pin(19, Pin.OUT)
vext.value(0)
time.sleep_ms(100)
# Init OLED Display
scl_pin = Pin(18, Pin.OUT, pull=Pin.PULL_UP)
sda_pin = Pin(17, Pin.OUT, pull=Pin.PULL_UP)
display_i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=100000)
display = ssd1306.SSD1306_I2C(128, 64, display_i2c, addr=0x3C)
microwave_screen = MicrowaveScreen(display)
microwave_screen.bootScreen()
# Init LoRa
lora = get_lora()
lora.configure(freq=868.1, sf=7)
@@ -57,14 +67,6 @@ def init_hardware():
magnetron_led.color = RGBLED.WHITE_YELLOW
magnetron_led.off()
# Init OLED Display
scl_pin = Pin(18, Pin.OUT, pull=Pin.PULL_UP)
sda_pin = Pin(17, Pin.OUT, pull=Pin.PULL_UP)
display_i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=100000)
display = ssd1306.SSD1306_I2C(128, 64, display_i2c, addr=0x3C)
display.text("Booting...", 1, 2, 1)
display.show()
# Init UART
uart_device = get_uart(uart_id=1, tx_pin=46, rx_pin=45)
@@ -113,16 +115,11 @@ def cooking_state_on_state_change(state):
uart_device.send_as_command(UARTCommand(UARTCommandType.COOKING_STATE_UPDATE, {"state": state.state}))
if lora:
lora.send_reliable({"id": DEVICE_ID, "new_cooking_state": state.state})
# Update OLED display
if display:
display.fill(0)
display.text(cookingState.CookingStates.get_state_name(state.state), 1, 2, 1)
display.show()
def cooking_state_on_refresh(state):
# TODO: Show screen information
pass
# Update OLED display
if microwave_screen:
microwave_screen.update(state, defrost_mode)
def cooking_state_on_pause(state):
# If the cooking is unpaused and was in STIRRING_REQUIRED or ALERT state, we set the state back to COOKING.
@@ -166,7 +163,7 @@ async def uart_polling_task():
async def lora_process_task():
"""Consumes packets pushed to data_queue by the LoRa hardware thread."""
global cooking_state
global cooking_state, defrost_mode, microwave_screen
while True:
while not data_queue.empty():
@@ -190,6 +187,10 @@ async def lora_process_task():
print("[LoRa Process] Cooking resumed via orchestrator command.")
else:
log("[LoRa Process] No active cooking state to toggle pause/resume.")
elif data["action"] == LoraCommands.TOGGLE_DEFROST:
print("[LoRa Process] Toggling defrost mode via orchestrator command.")
defrost_mode = data["defrost_state"]
microwave_screen.update(cooking_state, defrost_mode)
await asyncio.sleep_ms(50)
@@ -215,6 +216,7 @@ async def memory_cleanup_task():
# --- BOOTSTRAP ---
async def main():
global cooking_state, defrost_mode, microwave_screen
print("[Main] Starting application...")
init_hardware()
@@ -234,6 +236,8 @@ async def main():
asyncio.create_task(memory_cleanup_task())
print("[Main] All async tasks running concurrently!")
microwave_screen.update(None, defrost_mode)
# Keep main task alive indefinitely
while True: