This commit is contained in:
2026-08-10 14:00:20 +02:00
parent 75e64a0706
commit 0bc1a88e3c
4 changed files with 42 additions and 2 deletions
+4
View File
@@ -299,6 +299,10 @@ async def process_messages_task():
n_state = data["data"].get("new_cooking_state")
print(f"[LoRa] Microwave {mw_id} state changed to: {n_state}")
if n_state in (CookingStates.DONE, CookingStates.STIRRING_REQUIRED, CookingStates.ALERT):
print("buzzer alert triggered!")
beats = 5 if n_state == CookingStates.ALERT else (1 if n_state == CookingStates.STIRRING_REQUIRED else 3)
buzzer.buzzer_siren(beatsNb=beats)
if n_state == CookingStates.IDLE and microwave_states.get(mw_id) == MicrowaveState.COOKING:
microwave_states[mw_id] = MicrowaveState.DONE
print(f"[{mw_id}] Cooking finished. Waiting for user to remove dish.")
+1
View File
@@ -5,3 +5,4 @@ import sensors.temp_hum as temp_hum
import sensors.button as button
import sensors.gps as gps
import sensors.camera as camera
import sensors.buzzer as buzzer
+33
View File
@@ -0,0 +1,33 @@
import time
import grovepi
from sensors.lock import grove_lock
from shared import config
# Pin definition
BUZZER_PIN = 8
grovepi.pinMode(BUZZER_PIN, "OUTPUT")
buzzer_state = 0
def set_buzzer(state: int):
global buzzer_state
buzzer_state = state
if not config.BUZZER_ACTIVATED:
return
try:
with grove_lock:
grovepi.digitalWrite(BUZZER_PIN, state)
except Exception as e:
print(f"[BUZZER] Error occurred while setting buzzer state: {e}")
def buzzer_toggle():
global buzzer_state
new_state = 1 - buzzer_state
set_buzzer(new_state)
def buzzer_siren(beatsNb: int = 3, delay: float = 0.3):
for _ in range(beatsNb):
set_buzzer(1)
time.sleep(delay)
set_buzzer(0)
time.sleep(delay)
+2
View File
@@ -16,3 +16,5 @@ MQTT_HELLO_INTERVAL = 30
# Microwave Model
COOKING_COMPARTMENT_HEIGHT = 30 # cm
BUZZER_ACTIVATED = False