|
|
|
@ -1,31 +1,27 @@
|
|
|
|
|
import time |
|
|
|
|
from display import Display |
|
|
|
|
import time |
|
|
|
|
import hall_sensor |
|
|
|
|
import pressure_sensor |
|
|
|
|
import parameters |
|
|
|
|
from alarm import Alarm |
|
|
|
|
from storage import Storage |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StateMachine: |
|
|
|
|
pressure= None |
|
|
|
|
|
|
|
|
|
def __init__(self) -> None: |
|
|
|
|
Storage.enable_store_in_next_call() |
|
|
|
|
self.__read_previous_pressure() |
|
|
|
|
self.previous_pressure = pressure_sensor.get_pressure() |
|
|
|
|
time.sleep(0.02) |
|
|
|
|
self.__measure_pressure() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_task_loop(self): |
|
|
|
|
time.sleep(0.02) |
|
|
|
|
self.wait_for_correct_rotation_frequency() |
|
|
|
|
self.handle_pressure() |
|
|
|
|
while True: |
|
|
|
|
self.wait_for_correct_rotation_frequency() |
|
|
|
|
self.handle_pressure() |
|
|
|
|
time.sleep(0.03) |
|
|
|
|
|
|
|
|
|
def wait_for_correct_rotation_frequency(self): |
|
|
|
|
while self.__rotation_is_within_limits(): |
|
|
|
|
print('waiting correct rotation') |
|
|
|
|
time.sleep(0.02) |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
while not self.__rotation_is_within_limits(): |
|
|
|
|
time.sleep(0.03) |
|
|
|
|
|
|
|
|
|
def __measure_pressure(self): |
|
|
|
|
self.current_pressure = pressure_sensor.get_pressure() |
|
|
|
|
|
|
|
|
@ -41,15 +37,6 @@ class StateMachine:
|
|
|
|
|
there_is_a_hole = self.__pressure_is_lower_than_before() |
|
|
|
|
if there_is_a_hole: |
|
|
|
|
Alarm.trigger_hole_alarm() |
|
|
|
|
else: |
|
|
|
|
self.__save_current_pressure() |
|
|
|
|
|
|
|
|
|
def __save_current_pressure(self): |
|
|
|
|
Storage.save_pressure(self.current_pressure) |
|
|
|
|
self.previous_pressure = self.current_pressure |
|
|
|
|
|
|
|
|
|
def __read_previous_pressure(self): |
|
|
|
|
self.previous_pressure = Storage.retrieve_pressure() |
|
|
|
|
|
|
|
|
|
def __pressure_is_lower_than_before(self) -> bool: |
|
|
|
|
pressure_is_lower = ( |
|
|
|
|