From 3bcc2fd9851e9743450b5734dda05536aae6e641 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Fri, 26 Aug 2022 12:21:34 -0400 Subject: [PATCH] refactor to expose duty_cycle as the ON duty_cycle --- pioreactor_air_bubbler/additional_config.ini | 2 +- pioreactor_air_bubbler/air_bubbler.py | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/pioreactor_air_bubbler/additional_config.ini b/pioreactor_air_bubbler/additional_config.ini index b4cc55d..b5a9d09 100644 --- a/pioreactor_air_bubbler/additional_config.ini +++ b/pioreactor_air_bubbler/additional_config.ini @@ -6,5 +6,5 @@ duty_cycle=10 # this should be tuned to produce modest bubbles hertz=200 pre_delay_duration=1.5 -post_delay_duration=0.1 +post_delay_duration=0.75 enable_dodging_od=1 \ No newline at end of file diff --git a/pioreactor_air_bubbler/air_bubbler.py b/pioreactor_air_bubbler/air_bubbler.py index fd9e4f7..c03282a 100644 --- a/pioreactor_air_bubbler/air_bubbler.py +++ b/pioreactor_air_bubbler/air_bubbler.py @@ -14,7 +14,6 @@ class AirBubbler(BackgroundJobWithDodgingContrib): published_settings = { "duty_cycle": {"settable": False, "unit": "%", "datatype": "float"} } - _previous_duty_cycle = 0.0 def __init__(self, duty_cycle: float, hertz: float=60, unit:str=None, experiment:str=None): super(AirBubbler, self).__init__( @@ -32,11 +31,11 @@ def __init__(self, duty_cycle: float, hertz: float=60, unit:str=None, experiment "Unable to find `air_bubbler` under PWM section in the config.ini" ) + + self.duty_cycle = duty_cycle self.pwm = PWM(self.pin, self.hertz) self.pwm.start(0) - self.set_duty_cycle(duty_cycle) - def on_disconnected(self): self.stop_pumping() self.pwm.stop() @@ -45,17 +44,15 @@ def on_disconnected(self): def stop_pumping(self): if hasattr(self, "pwm"): # if the user unpauses, we want to go back to their previous value, and not the default. - self._previous_duty_cycle = self.duty_cycle - self.set_duty_cycle(0) + self.pwm.change_duty_cycle(0) def start_pumping(self): - self.set_duty_cycle(self._previous_duty_cycle) + self.pwm.change_duty_cycle(self.duty_cycle) def on_sleeping(self): self.stop_pumping() def on_sleeping_to_ready(self) -> None: - self.duty_cycle = self._previous_duty_cycle self.start_pumping() def set_duty_cycle(self, value): @@ -74,15 +71,12 @@ def click_air_bubbler(): """ turn on air bubbler """ - if is_pio_job_running("od_reading"): - dc = 0.0 - else: - dc = config.getfloat("air_bubbler", "duty_cycle") + dc = config.getfloat("air_bubbler", "duty_cycle") hertz = config.getfloat("air_bubbler", "hertz") ab = AirBubbler( duty_cycle=dc, hertz=hertz, unit=get_unit_name(), experiment=get_latest_experiment_name() ) - + ab.start_pumping() ab.block_until_disconnected()