Skip to content

Commit

Permalink
Merge branch 'main' into fw-ready-signal
Browse files Browse the repository at this point in the history
  • Loading branch information
falkecarlsen committed Aug 8, 2024
2 parents 3922324 + 9084c22 commit eb83b4b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict
9 changes: 3 additions & 6 deletions py_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ClaireState:
"""
The state of the Claire demonstrator. Can be used to cache the state.
"""

def __init__(self):
self.state = None
self.outdated = True
Expand All @@ -61,8 +60,7 @@ def set_state(self, state):
:param state: The new state to cache.
"""
self.state = state
self.outdated = state["Tube1_inflow_duty"] or state["Tube1_outflow_duty"] or state["Tube2_inflow_duty"] or \
state["Tube2_outflow_duty"]
self.outdated = state["Tube1_inflow_duty"] or state["Tube1_outflow_duty"] or state["Tube2_inflow_duty"] or state["Tube2_outflow_duty"]

def make_outdated(self):
"""Label the cached state as outdated."""
Expand All @@ -73,7 +71,6 @@ class ClaireDevice:
"""
Class that represents the Claire demonstrator setup.
"""

def __init__(self, port):
self.device = port
self.heartbeat = time()
Expand Down Expand Up @@ -254,8 +251,8 @@ def update_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
Expand Down
2 changes: 1 addition & 1 deletion py_driver/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def example_experiment():
claire = driver.ClaireDevice(PORT)
state = claire.update_state() # get current state of device
claire.print_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)
Expand Down
4 changes: 2 additions & 2 deletions py_driver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/Claire.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static Output** default_pumps = new Output*[PUMP_COUNT + 1] {


namespace default_sensor_defs {
static const auto TUBE1_HEIGHT = Sensor{ 10, "Tube1_water_mm", 0 };
static const auto TUBE2_HEIGHT = Sensor{ 11, "Tube2_water_mm", 1 };
static const auto TUBE1_HEIGHT = Sensor{ 10, "Tube1_sonar_dist_mm", 0 };
static const auto TUBE2_HEIGHT = Sensor{ 11, "Tube2_sonar_dist_mm", 1 };
}

const int SENSOR_COUNT = 2;
Expand Down

0 comments on commit eb83b4b

Please sign in to comment.