Browse Source

Make alarm sleep.

main
gabriel becker 2 years ago
parent
commit
7327828136
  1. 32
      src/alarm.py
  2. 3
      src/parameters.py

32
src/alarm.py

@ -1,8 +1,9 @@
import time
from machine import Pin
from machine import Pin, Timer
import buzzer
from display import Display
import constants
import parameters
SATURATED_MESSAGE = """Filtro saturado."""
@ -10,21 +11,28 @@ HOLE_MESSAGE = """Filtro ou linha \nfurado."""
class Alarm:
reset_btnn = Pin(constants.RESET_BUTTON_PIN, mode=Pin.IN)
led = Pin(constants.ALARM_LED_PIN, mode=Pin.OUT)
interrupt_timer = None
@staticmethod
def trigger_saturated_alarm():
Display.print(SATURATED_MESSAGE)
buzzer.sing_alarm()
while Alarm.reset_button_not_pressed():
time.sleep(0.05)
Alarm.stop_alarm()
Alarm.blink_led_and_wait_for_reset()
@staticmethod
def trigger_hole_alarm():
Display.print(HOLE_MESSAGE)
Alarm.blink_led_and_wait_for_reset()
@staticmethod
def blink_led_and_wait_for_reset():
buzzer.sing_alarm()
Alarm.led.on()
while Alarm.reset_button_not_pressed():
time.sleep(0.05)
Alarm.stop_alarm()
Alarm.led.off()
Alarm.sleep_alarm()
@staticmethod
def stop_alarm():
@ -35,3 +43,17 @@ class Alarm:
def reset_button_not_pressed():
was_not_pressed = Alarm.reset_btnn.value() < 1
return was_not_pressed
@staticmethod
def sleep_alarm():
interrupt_timer = Timer(
period=int(parameters.ALARM_PAUSE_PERIOD * 1e3),
mode=Timer.ONE_SHOT,
callback=Alarm.__wake_up_alarm
)
Alarm.interrupt_timer = interrupt_timer
@staticmethod
def __wake_up_alarm(*args, **kargs):
Alarm.interrupt_timer.deinit()
Alarm.blink_led_and_wait_for_reset()

3
src/parameters.py

@ -15,3 +15,6 @@ ANNOYING_BUZZER_ENABLED = False
"""How many samples of pressure should be used in smoother."""
PRESSURE_SMOOTH_LENGTH = 25
"""Period in seconds to wait when alarm reset button is presset until it starts again."""
ALARM_PAUSE_PERIOD = 5

Loading…
Cancel
Save