From adeb77e531047c85282c7d84b5a74576beaec0e9 Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:28:51 +0200 Subject: [PATCH 1/6] add tube scoping in getStatus --- examples/Console/Console.ino | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/Console/Console.ino b/examples/Console/Console.ino index 5c38077..6d967c8 100644 --- a/examples/Console/Console.ino +++ b/examples/Console/Console.ino @@ -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].name) + "\": " + claire.getRange(claire.sensors[tube], filtered) + ", "; } for (int i = 0; i < claire.pumpCount; i++) { From 4c0d79227f04436bc9649383dfcf235df9922819 Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:40:34 +0200 Subject: [PATCH 2/6] use optional tube param in Status cmds --- examples/Console/Console.ino | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/Console/Console.ino b/examples/Console/Console.ino index 6d967c8..e5b0039 100644 --- a/examples/Console/Console.ino +++ b/examples/Console/Console.ino @@ -79,7 +79,7 @@ String getStatus(bool filtered, int tube = 0) { } if (1 <= tube && tube <= 2) { - fmt += "\"" + String(claire.sensors[tube].name) + "\": " + claire.getRange(claire.sensors[tube], filtered) + ", "; + fmt += "\"" + String(claire.sensors[tube - 1].name) + "\": " + claire.getRange(claire.sensors[tube - 1], filtered) + ", "; } for (int i = 0; i < claire.pumpCount; i++) { @@ -95,13 +95,22 @@ String getStatus(bool filtered, int tube = 0) { void OnStatus() { // do default samples - Serial.println(getStatus(true)); + int tube = 0; + if (cmdMessenger.isArgOk()) { + tube = cmdMessenger.readInt16Arg(); + Serial.println("Got tube: " + String(tube)); + } + 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(); } From 67eee842385e1ffa2dc6bffdb8173295b22ed68c Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:42:58 +0200 Subject: [PATCH 3/6] rewrite fw-usage --- examples/Console/Console.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Console/Console.ino b/examples/Console/Console.ino index e5b0039..4a65629 100644 --- a/examples/Console/Console.ino +++ b/examples/Console/Console.ino @@ -261,8 +261,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 ; - Set pump flow. 0 = off, 1..100 = proportional flow-rate"); Serial.println(" = {1: TUBE1_IN, 2: TUBE1_OUT, 3: TUBE2_IN, 4: TUBE2_OUT, 5: STREAM_OUT}"); From c738ba11f8319450c3e383cef3893279a514b5c7 Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:47:53 +0200 Subject: [PATCH 4/6] remove debug --- examples/Console/Console.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/Console/Console.ino b/examples/Console/Console.ino index 4a65629..9cf2041 100644 --- a/examples/Console/Console.ino +++ b/examples/Console/Console.ino @@ -98,7 +98,6 @@ void OnStatus() { int tube = 0; if (cmdMessenger.isArgOk()) { tube = cmdMessenger.readInt16Arg(); - Serial.println("Got tube: " + String(tube)); } Serial.println(getStatus(true, tube)); OnReady(); From 67cdba4f14c28679d6b299097f6ff254a6f14606 Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:48:35 +0200 Subject: [PATCH 5/6] add driver support for status tube selection and quick-mode --- py_driver/driver.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/py_driver/driver.py b/py_driver/driver.py index 2c6fdb8..c8bd622 100644 --- a/py_driver/driver.py +++ b/py_driver/driver.py @@ -235,7 +235,7 @@ 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: @@ -243,7 +243,20 @@ def update_state(self): # 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 From 12a16a72889f328966daabe40919ef37ff79430d Mon Sep 17 00:00:00 2001 From: falkecarlsen <11318702+falkecarlsen@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:50:11 +0200 Subject: [PATCH 6/6] bump version (no fw change, only Console) --- library.properties | 2 +- py_driver/driver.py | 2 +- src/Claire.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index f20dce5..195279d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CLAIRE -version=0.1.12 +version=0.1.13 author=Falke Carlsen maintainer=Falke Carlsen sentence=API to interface with CLAIRE water management demonstrator at DEIS-AAU. diff --git a/py_driver/driver.py b/py_driver/driver.py index c8bd622..4ea3297 100644 --- a/py_driver/driver.py +++ b/py_driver/driver.py @@ -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 diff --git a/src/Claire.h b/src/Claire.h index d610c5e..de5ed03 100644 --- a/src/Claire.h +++ b/src/Claire.h @@ -4,7 +4,7 @@ #include #include -#define VERSION "0.1.12" +#define VERSION "0.1.13" #define OUTPUT_GPIO_MIN 2 #define OUTPUT_GPIO_MAX 7