|
|
|
@ -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() |
|
|
|
|