diff --git a/src/constants.py b/src/constants.py index a9059d6..388f441 100644 --- a/src/constants.py +++ b/src/constants.py @@ -12,4 +12,4 @@ LCD_SCL = 1 ANNOYTING_BUZZER_TONE = 51250 NORMAL_BUZZER_TONE = 200 ADC_RESOLUTION = 65535.0 - +MAX_VOTLAGE = 3.3 diff --git a/src/hall_sensor.py b/src/hall_sensor.py index 8f5c6bf..ec202e4 100644 --- a/src/hall_sensor.py +++ b/src/hall_sensor.py @@ -11,7 +11,7 @@ previous_time = time.ticks_ms() def hall_sensor_interruption(*args, **kargs): global ii ii += 1 - + def start_hall_sensor(): global previous_time diff --git a/src/main.py b/src/main.py index ed22042..ac31eae 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,3 @@ - from machine import ADC, I2C, Pin, PWM import time import hall_sensor diff --git a/src/parameters.py b/src/parameters.py index 473b51b..00e7b6d 100644 --- a/src/parameters.py +++ b/src/parameters.py @@ -1,8 +1,8 @@ """Percentage that the previous pressure can be lower than current one without triggering the hole alarm.""" -PRESSURE_TOLERANCE_PERCENTAGE = 10 +PRESSURE_TOLERANCE_PERCENTAGE = 1 """Pressure saturation threshold in mV to trigger the saturation alarm.""" -PRESSURE_SATURATION_THRESHOLD = 2.8 +PRESSURE_SATURATION_THRESHOLD = 1.65 """Lower limit of frequency in Hz to be considered inside interest rotation interval. (type: float)""" REFERENCE_ROTATION_DOWN_LIMIT = 250.0 @@ -13,8 +13,5 @@ REFERENCE_ROTATION_UPPER_LIMIT = 270.0 """Weather or not the buzzer should be set to an annoying tone (in oder to keep the mental healthness of the developer).""" ANNOYING_BUZZER_ENABLED = False -"""Period in milisseconds between each storage event.""" -PRESSURE_STORE_PREIOD = int(60*1e3) - """How many samples of pressure should be used in smoother.""" -PRESSURE_SMOOTH_LENGTH = 10 +PRESSURE_SMOOTH_LENGTH = 25 diff --git a/src/pressure_sensor.py b/src/pressure_sensor.py index bb18401..94653a5 100644 --- a/src/pressure_sensor.py +++ b/src/pressure_sensor.py @@ -10,6 +10,5 @@ def get_pressure(): pressure_value = 0 for i in range(parameters.PRESSURE_SMOOTH_LENGTH): pressure_value += pressure_sensor.read_u16() - print(pressure_value / parameters.PRESSURE_SMOOTH_LENGTH) - pressure_measure = float(pressure_value) / constants.ADC_RESOLUTION * 3.3 + pressure_measure = float(pressure_value) / parameters.PRESSURE_SMOOTH_LENGTH / constants.ADC_RESOLUTION * constants.MAX_VOTLAGE return pressure_measure diff --git a/src/states.py b/src/states.py index f1131e8..1dc096c 100644 --- a/src/states.py +++ b/src/states.py @@ -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 = (