From f49c70ead623fc1f388e08d28e402c8b2480f0df Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 9 Mar 2023 21:18:10 -0500 Subject: [PATCH] Define all command chars as static constants. Provide an identity when initializing and allow for setting with another method. --- ino/lib/McopySerial/McopySerial.cpp | 8 ++- ino/lib/McopySerial/McopySerial.h | 86 +++++++++++++------------ ino/mcopy_cam_canon/McopySerial.cpp | 8 ++- ino/mcopy_cam_canon/McopySerial.h | 86 +++++++++++++------------ ino/mcopy_cam_canon/mcopy_cam_canon.ino | 4 +- scripts/ino.sh | 2 +- 6 files changed, 103 insertions(+), 91 deletions(-) diff --git a/ino/lib/McopySerial/McopySerial.cpp b/ino/lib/McopySerial/McopySerial.cpp index d8e40c4..82da107 100644 --- a/ino/lib/McopySerial/McopySerial.cpp +++ b/ino/lib/McopySerial/McopySerial.cpp @@ -2,14 +2,18 @@ #include "McopySerial.h" -McopySerial::McopySerial () { - //create mcopy serial +McopySerial::McopySerial (char identity) { + id = identity; } void McopySerial::begin () { Serial.begin(baud); } +void McopySerial::identify (char identity) { + id = identity; +} + char McopySerial::loop () { if (Serial.available()) { cmdChar = (char) Serial.read(); diff --git a/ino/lib/McopySerial/McopySerial.h b/ino/lib/McopySerial/McopySerial.h index 505430f..776ea8b 100644 --- a/ino/lib/McopySerial/McopySerial.h +++ b/ino/lib/McopySerial/McopySerial.h @@ -9,60 +9,62 @@ class McopySerial { volatile int baud = 57600; volatile bool debugOn = false; volatile char cmdChar = 'z'; + volatile char id; void internal (); public: /* CMD FLAGS */ - char BLACK = 'b'; - char CAMERA = 'c'; - char CAMERA_BACKWARD = 'f'; - char CAMERA_CAPPER_IDENTIFIER = '8'; - char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; - char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; - char CAMERA_FORWARD = 'e'; - char CAMERA_IDENTIFIER = 'k'; - char CAMERA_PROJECTORS_IDENTIFIER = '5'; - char CAMERA_SECOND = '3'; - char CAMERA_SECOND_BACKWARD = '2'; - char CAMERA_SECOND_FORWARD = '1'; - char CAMERA_SECOND_IDENTIFIER = 'y'; - char CAMERA_TIMED = 'n'; - char CAMERAS = '4'; - char CAMERAS_IDENTIFIER = 'a'; - char CAMERAS_PROJECTOR_IDENTIFIER = '6'; - char CAMERAS_PROJECTORS_IDENTIFIER = '7'; - char CAPPER_IDENTIFIER = 'C'; - char CAPPER_OFF = 'B'; - char CAPPER_ON = 'A'; - char CONNECT = 'i'; - char DEBUG = 'd'; - char LIGHT = 'l'; - char LIGHT_IDENTIFIER = 'o'; - char MCOPY_IDENTIFIER = 'm'; - char PROJECTOR = 'p'; - char PROJECTOR_BACKWARD = 'h'; - char PROJECTOR_CAMERA_IDENTIFIER = 's'; - char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; - char PROJECTOR_FORWARD = 'g'; - char PROJECTOR_IDENTIFIER = 'j'; - char PROJECTOR_LIGHT_IDENTIFIER = 'q'; - char PROJECTOR_SECOND = 'w'; - char PROJECTOR_SECOND_BACKWARD = 'v'; - char PROJECTOR_SECOND_FORWARD = 'u'; - char PROJECTOR_SECOND_IDENTIFIER = 't'; - char PROJECTORS = 'x'; - char PROJECTORS_IDENTIFIER = 'd'; - char TAKEUP_BACKWARD = 'E'; - char TAKEUP_FORWARD = 'D'; + static const char BLACK = 'b'; + static const char CAMERA = 'c'; + static const char CAMERA_BACKWARD = 'f'; + static const char CAMERA_CAPPER_IDENTIFIER = '8'; + static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + static const char CAMERA_FORWARD = 'e'; + static const char CAMERA_IDENTIFIER = 'k'; + static const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + static const char CAMERA_SECOND = '3'; + static const char CAMERA_SECOND_BACKWARD = '2'; + static const char CAMERA_SECOND_FORWARD = '1'; + static const char CAMERA_SECOND_IDENTIFIER = 'y'; + static const char CAMERA_TIMED = 'n'; + static const char CAMERAS = '4'; + static const char CAMERAS_IDENTIFIER = 'a'; + static const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + static const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + static const char CAPPER_IDENTIFIER = 'C'; + static const char CAPPER_OFF = 'B'; + static const char CAPPER_ON = 'A'; + static const char CONNECT = 'i'; + static const char DEBUG = 'd'; + static const char LIGHT = 'l'; + static const char LIGHT_IDENTIFIER = 'o'; + static const char MCOPY_IDENTIFIER = 'm'; + static const char PROJECTOR = 'p'; + static const char PROJECTOR_BACKWARD = 'h'; + static const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + static const char PROJECTOR_FORWARD = 'g'; + static const char PROJECTOR_IDENTIFIER = 'j'; + static const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + static const char PROJECTOR_SECOND = 'w'; + static const char PROJECTOR_SECOND_BACKWARD = 'v'; + static const char PROJECTOR_SECOND_FORWARD = 'u'; + static const char PROJECTOR_SECOND_IDENTIFIER = 't'; + static const char PROJECTORS = 'x'; + static const char PROJECTORS_IDENTIFIER = 'd'; + static const char TAKEUP_BACKWARD = 'E'; + static const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(); + McopySerial(char identity); void begin(); void setBaud(int baudRate); char loop(); + void identify(char identity); void debug (bool state); void log (String message); diff --git a/ino/mcopy_cam_canon/McopySerial.cpp b/ino/mcopy_cam_canon/McopySerial.cpp index d8e40c4..82da107 100644 --- a/ino/mcopy_cam_canon/McopySerial.cpp +++ b/ino/mcopy_cam_canon/McopySerial.cpp @@ -2,14 +2,18 @@ #include "McopySerial.h" -McopySerial::McopySerial () { - //create mcopy serial +McopySerial::McopySerial (char identity) { + id = identity; } void McopySerial::begin () { Serial.begin(baud); } +void McopySerial::identify (char identity) { + id = identity; +} + char McopySerial::loop () { if (Serial.available()) { cmdChar = (char) Serial.read(); diff --git a/ino/mcopy_cam_canon/McopySerial.h b/ino/mcopy_cam_canon/McopySerial.h index 505430f..776ea8b 100644 --- a/ino/mcopy_cam_canon/McopySerial.h +++ b/ino/mcopy_cam_canon/McopySerial.h @@ -9,60 +9,62 @@ class McopySerial { volatile int baud = 57600; volatile bool debugOn = false; volatile char cmdChar = 'z'; + volatile char id; void internal (); public: /* CMD FLAGS */ - char BLACK = 'b'; - char CAMERA = 'c'; - char CAMERA_BACKWARD = 'f'; - char CAMERA_CAPPER_IDENTIFIER = '8'; - char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; - char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; - char CAMERA_FORWARD = 'e'; - char CAMERA_IDENTIFIER = 'k'; - char CAMERA_PROJECTORS_IDENTIFIER = '5'; - char CAMERA_SECOND = '3'; - char CAMERA_SECOND_BACKWARD = '2'; - char CAMERA_SECOND_FORWARD = '1'; - char CAMERA_SECOND_IDENTIFIER = 'y'; - char CAMERA_TIMED = 'n'; - char CAMERAS = '4'; - char CAMERAS_IDENTIFIER = 'a'; - char CAMERAS_PROJECTOR_IDENTIFIER = '6'; - char CAMERAS_PROJECTORS_IDENTIFIER = '7'; - char CAPPER_IDENTIFIER = 'C'; - char CAPPER_OFF = 'B'; - char CAPPER_ON = 'A'; - char CONNECT = 'i'; - char DEBUG = 'd'; - char LIGHT = 'l'; - char LIGHT_IDENTIFIER = 'o'; - char MCOPY_IDENTIFIER = 'm'; - char PROJECTOR = 'p'; - char PROJECTOR_BACKWARD = 'h'; - char PROJECTOR_CAMERA_IDENTIFIER = 's'; - char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; - char PROJECTOR_FORWARD = 'g'; - char PROJECTOR_IDENTIFIER = 'j'; - char PROJECTOR_LIGHT_IDENTIFIER = 'q'; - char PROJECTOR_SECOND = 'w'; - char PROJECTOR_SECOND_BACKWARD = 'v'; - char PROJECTOR_SECOND_FORWARD = 'u'; - char PROJECTOR_SECOND_IDENTIFIER = 't'; - char PROJECTORS = 'x'; - char PROJECTORS_IDENTIFIER = 'd'; - char TAKEUP_BACKWARD = 'E'; - char TAKEUP_FORWARD = 'D'; + static const char BLACK = 'b'; + static const char CAMERA = 'c'; + static const char CAMERA_BACKWARD = 'f'; + static const char CAMERA_CAPPER_IDENTIFIER = '8'; + static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + static const char CAMERA_FORWARD = 'e'; + static const char CAMERA_IDENTIFIER = 'k'; + static const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + static const char CAMERA_SECOND = '3'; + static const char CAMERA_SECOND_BACKWARD = '2'; + static const char CAMERA_SECOND_FORWARD = '1'; + static const char CAMERA_SECOND_IDENTIFIER = 'y'; + static const char CAMERA_TIMED = 'n'; + static const char CAMERAS = '4'; + static const char CAMERAS_IDENTIFIER = 'a'; + static const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + static const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + static const char CAPPER_IDENTIFIER = 'C'; + static const char CAPPER_OFF = 'B'; + static const char CAPPER_ON = 'A'; + static const char CONNECT = 'i'; + static const char DEBUG = 'd'; + static const char LIGHT = 'l'; + static const char LIGHT_IDENTIFIER = 'o'; + static const char MCOPY_IDENTIFIER = 'm'; + static const char PROJECTOR = 'p'; + static const char PROJECTOR_BACKWARD = 'h'; + static const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + static const char PROJECTOR_FORWARD = 'g'; + static const char PROJECTOR_IDENTIFIER = 'j'; + static const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + static const char PROJECTOR_SECOND = 'w'; + static const char PROJECTOR_SECOND_BACKWARD = 'v'; + static const char PROJECTOR_SECOND_FORWARD = 'u'; + static const char PROJECTOR_SECOND_IDENTIFIER = 't'; + static const char PROJECTORS = 'x'; + static const char PROJECTORS_IDENTIFIER = 'd'; + static const char TAKEUP_BACKWARD = 'E'; + static const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(); + McopySerial(char identity); void begin(); void setBaud(int baudRate); char loop(); + void identify(char identity); void debug (bool state); void log (String message); diff --git a/ino/mcopy_cam_canon/mcopy_cam_canon.ino b/ino/mcopy_cam_canon/mcopy_cam_canon.ino index 1b820f2..071e623 100644 --- a/ino/mcopy_cam_canon/mcopy_cam_canon.ino +++ b/ino/mcopy_cam_canon/mcopy_cam_canon.ino @@ -33,7 +33,7 @@ volatile bool ledState; const String name_remote = "mcopy"; CanonBLERemote canon_ble(name_remote); TickTwo blinker(blink, 500); -McopySerial mc; +McopySerial mc(McopySerial::CAMERA); volatile boolean connected = false; @@ -86,7 +86,7 @@ void loop() if (cmd == 'c' && last + 1000 < now) { shutter(); } - + // Shutter if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){ shutter(); diff --git a/scripts/ino.sh b/scripts/ino.sh index e9564a1..5e2567a 100644 --- a/scripts/ino.sh +++ b/scripts/ino.sh @@ -8,7 +8,7 @@ if [ -f "$(which jq)" ]; then awk '{print} /CMD FLAGS/ {exit}' "${HEADER}" > "${TMP_FILE}" - cat ./data/cfg.json | jq -r '.arduino.cmd | keys[] as $k | " char \($k) = '"'"'\(.[$k])'"'"';"' | awk '{print "\t"$1" "toupper($2)" "$3" "$4}' >> "${TMP_FILE}" + cat ./data/cfg.json | jq -r '.arduino.cmd | keys[] as $k | " static const char \($k) = '"'"'\(.[$k])'"'"';"' | awk '{print "\t"$1" "$2" "$3" "toupper($4)" "$5" "$6}' >> "${TMP_FILE}" awk '/END CMD/,EOF { print $0 }' "${HEADER}" >> "${TMP_FILE}"