diff --git a/py_driver/driver.py b/py_driver/driver.py index 036fc64..0f72b6d 100644 --- a/py_driver/driver.py +++ b/py_driver/driver.py @@ -199,8 +199,8 @@ def get_state(self): state = self.get_last_raw_state() if state: # Convert distance to water level - state["Tube1_water_mm"] = round(self.convert_distance_to_level(state["Tube1_water_mm"]), 1) - state["Tube2_water_mm"] = round(self.convert_distance_to_level(state["Tube2_water_mm"]), 1) + state["Tube1_sonar_dist_mm"] = round(self.convert_distance_to_level(state["Tube1_sonar_dist_mm"]), 1) + state["Tube2_sonar_dist_mm"] = round(self.convert_distance_to_level(state["Tube2_sonar_dist_mm"]), 1) self.state = ClaireState() self.state.set_state(state) return state diff --git a/py_driver/experiment.py b/py_driver/experiment.py index a9b4050..42a615a 100644 --- a/py_driver/experiment.py +++ b/py_driver/experiment.py @@ -11,7 +11,7 @@ def example_experiment(): claire = driver.ClaireDevice(PORT) state = claire.get_state() # get current state of device claire.print_state(state) - print(f'Current height of TUBE1: {state["Tube1_water_mm"]}') + print(f'Current height of TUBE1: {state["Tube1_sonar_dist_mm"]}') claire.set_inflow(1, 100) sleep(3) diff --git a/py_driver/utils.py b/py_driver/utils.py index 7af5778..796e670 100644 --- a/py_driver/utils.py +++ b/py_driver/utils.py @@ -4,7 +4,7 @@ # Compact regex pattern to match Python dictionaries dict_pattern = re.compile( r'\{\s*"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:\s*(-?\d+(\.\d+)?|"\w*")\s*(,\s*"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:\s*(-?\d+(\.\d+)?|"\w*"))*\s*\}') -test_string = '{"Tube1_water_mm": -1.00, "Tube2_water_mm": -1.00, "Tube1_inflow_duty": 0,"Tube1_outflow_duty": 0,"Tube2_inflow_duty": 0,"Tube2_outflow_duty": 0,"Stream_inflow_duty": 0,"Stream_outflow_duty": 0}' +test_string = '{"Tube1_sonar_dist_mm": -1.00, "Tube2_sonar_dist_mm": -1.00, "Tube1_inflow_duty": 0,"Tube1_outflow_duty": 0,"Tube2_inflow_duty": 0,"Tube2_outflow_duty": 0,"Stream_inflow_duty": 0,"Stream_outflow_duty": 0}' def is_dict(s: str) -> bool: @@ -24,7 +24,7 @@ def is_dict(s: str) -> bool: def parse_str_dict(s: str) -> dict: """ >>> parse_str_dict(test_string) - {'Tube1_water_mm': -1.0, 'Tube2_water_mm': -1.0, 'Tube1_inflow_duty': 0, 'Tube1_outflow_duty': 0, 'Tube2_inflow_duty': 0, 'Tube2_outflow_duty': 0, 'Stream_inflow_duty': 0, 'Stream_outflow_duty': 0} + {'Tube1_sonar_dist_mm': -1.0, 'Tube2_sonar_dist_mm': -1.0, 'Tube1_inflow_duty': 0, 'Tube1_outflow_duty': 0, 'Tube2_inflow_duty': 0, 'Tube2_outflow_duty': 0, 'Stream_inflow_duty': 0, 'Stream_outflow_duty': 0} >>> parse_str_dict('{"a": 1, "b": 2}') {'a': 1, 'b': 2}