Skip to content

Commit

Permalink
Merge pull request #53 from DEIS-Tools/range-single-tube
Browse files Browse the repository at this point in the history
Firmware: Add option to range a single tube
  • Loading branch information
falkecarlsen authored Aug 12, 2024
2 parents 519f835 + 12a16a7 commit dcad45a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
33 changes: 26 additions & 7 deletions examples/Console/Console.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,24 @@ void OnCommandList() {
OnReady();
}

String getStatus(bool filtered) {
String getStatus(bool filtered, int tube = 0) {
// Construct dict from demonstrator state and report at end.
// Error reporting is handled by called functions, and sentinel (-1) is used for error state.

if (0 > tube || tube > 2) {
return "Error: Tube index is out of bounds [1..2], for both use value of 0. Received: " + String(tube);
}

String fmt = "{";

for (int i = 0; i < claire.sensorCount; i++) {
fmt += "\"" + String(claire.sensors[i].name) + "\": " + claire.getRange(claire.sensors[i], filtered) + ", ";
if (tube == 0) {
for (int i = 0; i < claire.sensorCount; i++) {
fmt += "\"" + String(claire.sensors[i].name) + "\": " + claire.getRange(claire.sensors[i], filtered) + ", ";
}
}

if (1 <= tube && tube <= 2) {
fmt += "\"" + String(claire.sensors[tube - 1].name) + "\": " + claire.getRange(claire.sensors[tube - 1], filtered) + ", ";
}

for (int i = 0; i < claire.pumpCount; i++) {
Expand All @@ -84,13 +95,21 @@ String getStatus(bool filtered) {

void OnStatus() {
// do default samples
Serial.println(getStatus(true));
int tube = 0;
if (cmdMessenger.isArgOk()) {
tube = cmdMessenger.readInt16Arg();
}
Serial.println(getStatus(true, tube));
OnReady();
}

void OnQuickStatus() {
// only do one sample
Serial.println(getStatus(false));
int tube = 0;
if (cmdMessenger.isArgOk()) {
tube = cmdMessenger.readInt16Arg();
}
Serial.println(getStatus(false, tube));
OnReady();
}

Expand Down Expand Up @@ -241,8 +260,8 @@ void OnVerbosity() {
void ShowCommands() {
Serial.println("Usage: cmd [args] ;");
Serial.println(" 0; - This command list");
Serial.println(" 1; - Status of system in k:v");
Serial.println(" 2; - Quick status (1 sample) of system in k:v");
Serial.println(" 1 [tube]; - Status of system in k:v. Optionally sample only given tube.");
Serial.println(" 2 [tube]; - Quick status (1 sample) of system in k:v. Optionally sample only given tube.");
Serial.println(" 3; - Emergency stop all actuators");
Serial.println(" 4 <pump> <flow>; - Set pump flow. 0 = off, 1..100 = proportional flow-rate");
Serial.println(" <pump> = {1: TUBE1_IN, 2: TUBE1_OUT, 3: TUBE2_IN, 4: TUBE2_OUT, 5: STREAM_OUT}");
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=CLAIRE
version=0.1.12
version=0.1.13
author=Falke Carlsen <[email protected]>
maintainer=Falke Carlsen <[email protected]>
sentence=API to interface with CLAIRE water management demonstrator at DEIS-AAU.
Expand Down
19 changes: 16 additions & 3 deletions py_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

IMMEDIATE_OUTPUT = True
TAG = "DRIVER:"
CLAIRE_VERSION = "v0.1.12"
CLAIRE_VERSION = "v0.1.13"
TUBE_MAX_LEVEL = 900
DEBUG = True
COMMUNICATION_TIMEOUT = 10
Expand Down Expand Up @@ -235,15 +235,28 @@ def check_version(self):
# check if device is ready
assert self.ready()

def update_state(self):
def update_state(self, tube=None, quick=False):
"""Get the last state of the device. If cached state is outdated, a new sensor reading is requested."""
# Return cached state if not outdated.
if not self.state.outdated and self.state.last_update >= time() - COMMUNICATION_TIMEOUT:
return self.state.state

# Ask for new state reading.
size_buffer = self.last_printed_buf_line
self.write('1;')

arg = ""

if quick:
arg += "2"
else:
arg += "1"

if tube:
arg += f" {tube};"
else:
arg += ";"

self.write(arg)

# Wait for the state to be received.
total_wait = 0
Expand Down
2 changes: 1 addition & 1 deletion src/Claire.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Arduino.h>
#include <EEPROM.h>

#define VERSION "0.1.12"
#define VERSION "0.1.13"

#define OUTPUT_GPIO_MIN 2
#define OUTPUT_GPIO_MAX 7
Expand Down

0 comments on commit dcad45a

Please sign in to comment.