Alerts
This commit is contained in:
@@ -17,6 +17,7 @@ from shared.uart_comm import UARTCommand, UARTCommandType
|
||||
from shared.sensors import RGBLED
|
||||
from shared.logging import log
|
||||
from shared.lora_device import LoraCommands
|
||||
from shared.alerts import Alert, AlertType, AlertManager
|
||||
|
||||
# --- READ DEVICE ID ---
|
||||
try:
|
||||
@@ -37,6 +38,7 @@ current_temp = [None, None]
|
||||
last_temp = [None, None]
|
||||
temperature_asked = False
|
||||
last_temp_request_time = 0
|
||||
alert_manager = None
|
||||
|
||||
|
||||
PING_PAYLOAD = {
|
||||
@@ -44,6 +46,11 @@ PING_PAYLOAD = {
|
||||
"type": deviceTypes.DEVICE_TYPES["MICROWAVE"]
|
||||
}
|
||||
|
||||
def on_new_alert(alert: Alert):
|
||||
global microwave_screen
|
||||
print(f"[Alert Manager] New alert received: {alert.to_dict()}")
|
||||
microwave_screen.message(alert.message, True)
|
||||
|
||||
def init_hardware():
|
||||
"""Initializes all hardware components."""
|
||||
global lora, uart_device, magnetron_led, microwave_screen
|
||||
@@ -247,8 +254,13 @@ async def lora_process_task():
|
||||
print("[LoRa Process] Toggling defrost mode via orchestrator command.")
|
||||
defrost_mode = data["defrost_state"]
|
||||
microwave_screen.update(cooking_state, defrost_mode)
|
||||
elif data["action"] == LoraCommands.NEW_ALERT:
|
||||
alert = Alert(data.get("alert_type"), data.get("message", "Unsafe area"))
|
||||
alert.timestamp = data.get("timestamp", time.time())
|
||||
print(f"[LoRa Process] New alert received via orchestrator: {alert.to_dict()}")
|
||||
alert_manager.add_alert(alert)
|
||||
|
||||
await asyncio.sleep_ms(50)
|
||||
await asyncio.sleep_ms(100)
|
||||
|
||||
|
||||
async def cooking_loop_task():
|
||||
@@ -276,11 +288,14 @@ async def memory_cleanup_task():
|
||||
|
||||
# --- BOOTSTRAP ---
|
||||
async def main():
|
||||
global cooking_state, defrost_mode, microwave_screen
|
||||
global cooking_state, defrost_mode, microwave_screen, alert_manager
|
||||
print("[Main] Starting application...")
|
||||
|
||||
init_hardware()
|
||||
|
||||
alert_manager = AlertManager()
|
||||
alert_manager.set_on_alert_callback(on_new_alert)
|
||||
|
||||
# Launch dedicated hardware thread for LoRa RX
|
||||
try:
|
||||
_thread.stack_size(16 * 1024)
|
||||
|
||||
Reference in New Issue
Block a user