From 844bb286a5be0013982eb39f42c95b47c44273d5 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 9 Mar 2023 21:01:20 -0500 Subject: [PATCH] Build the skeleton of McopySerial. Contains all command chars as flags. Is now re-built with latest command flags automatically when syncing to all projects. Compiles. Will implement more in canon firmware. --- ino/lib/McopySerial/McopySerial.cpp | 11 ++---- ino/lib/McopySerial/McopySerial.h | 52 +++++++++++++++++++++++-- ino/mcopy_cam_canon/McopySerial.cpp | 11 ++---- ino/mcopy_cam_canon/McopySerial.h | 52 +++++++++++++++++++++++-- ino/mcopy_cam_canon/mcopy_cam_canon.ino | 14 +++---- scripts/ino.sh | 16 +++++++- 6 files changed, 125 insertions(+), 31 deletions(-) diff --git a/ino/lib/McopySerial/McopySerial.cpp b/ino/lib/McopySerial/McopySerial.cpp index 7644b5d..d764af3 100644 --- a/ino/lib/McopySerial/McopySerial.cpp +++ b/ino/lib/McopySerial/McopySerial.cpp @@ -3,23 +3,20 @@ #include "McopySerial.h" McopySerial::McopySerial () { - + //create mcopy serial } -void McopySerial::on() - void McopySerial::begin () { Serial.begin(baud); } -void McopySerial::loop () { +char McopySerial::loop () { if (Serial.available()) { cmdChar = (char) Serial.read(); - } - if (cmdChar != 'z') { - //cmd(cmdChar); + } else { cmdChar = 'z'; } + return cmdChar; } void McopySerial::setBaud (int baudRate) { diff --git a/ino/lib/McopySerial/McopySerial.h b/ino/lib/McopySerial/McopySerial.h index ea1f495..1b29d1b 100644 --- a/ino/lib/McopySerial/McopySerial.h +++ b/ino/lib/McopySerial/McopySerial.h @@ -3,8 +3,6 @@ #include "Arduino.h" -typedef void (*mcopy_callback)(void); - class McopySerial { private: @@ -13,14 +11,60 @@ class McopySerial { volatile char cmdChar = 'z'; 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'; + /* END CMD FLAGS */ + McopySerial(); void begin(); void setBaud(int baudRate); - void loop(); + char loop(); void debug (bool state); void log (String message); + }; -#endif \ No newline at end of file +#endif diff --git a/ino/mcopy_cam_canon/McopySerial.cpp b/ino/mcopy_cam_canon/McopySerial.cpp index 7644b5d..d764af3 100644 --- a/ino/mcopy_cam_canon/McopySerial.cpp +++ b/ino/mcopy_cam_canon/McopySerial.cpp @@ -3,23 +3,20 @@ #include "McopySerial.h" McopySerial::McopySerial () { - + //create mcopy serial } -void McopySerial::on() - void McopySerial::begin () { Serial.begin(baud); } -void McopySerial::loop () { +char McopySerial::loop () { if (Serial.available()) { cmdChar = (char) Serial.read(); - } - if (cmdChar != 'z') { - //cmd(cmdChar); + } else { cmdChar = 'z'; } + return cmdChar; } void McopySerial::setBaud (int baudRate) { diff --git a/ino/mcopy_cam_canon/McopySerial.h b/ino/mcopy_cam_canon/McopySerial.h index ea1f495..1b29d1b 100644 --- a/ino/mcopy_cam_canon/McopySerial.h +++ b/ino/mcopy_cam_canon/McopySerial.h @@ -3,8 +3,6 @@ #include "Arduino.h" -typedef void (*mcopy_callback)(void); - class McopySerial { private: @@ -13,14 +11,60 @@ class McopySerial { volatile char cmdChar = 'z'; 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'; + /* END CMD FLAGS */ + McopySerial(); void begin(); void setBaud(int baudRate); - void loop(); + char loop(); void debug (bool state); void log (String message); + }; -#endif \ No newline at end of file +#endif diff --git a/ino/mcopy_cam_canon/mcopy_cam_canon.ino b/ino/mcopy_cam_canon/mcopy_cam_canon.ino index e25ce57..1b820f2 100644 --- a/ino/mcopy_cam_canon/mcopy_cam_canon.ino +++ b/ino/mcopy_cam_canon/mcopy_cam_canon.ino @@ -33,14 +33,14 @@ volatile bool ledState; const String name_remote = "mcopy"; CanonBLERemote canon_ble(name_remote); TickTwo blinker(blink, 500); -//McopySerial mc; +McopySerial mc; volatile boolean connected = false; volatile long now; volatile long last = -1; -volatile byte cmd_char; +volatile byte cmd; void blink(){ digitalWrite(LED, ledState); @@ -81,14 +81,12 @@ void connectBLE () { void loop() { now = millis(); - if (Serial.available()) { - /* read the most recent byte */ - cmd_char = (char)Serial.read(); - } - if (cmd_char == 'c' && last + 1000 < now) { + cmd = mc.loop(); + + if (cmd == 'c' && last + 1000 < now) { shutter(); - cmd_char = 'z'; } + // Shutter if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){ shutter(); diff --git a/scripts/ino.sh b/scripts/ino.sh index acb9160..e9564a1 100644 --- a/scripts/ino.sh +++ b/scripts/ino.sh @@ -1,5 +1,19 @@ #!/bin/bash -#sync libs +#sync libs' + +if [ -f "$(which jq)" ]; then + HEADER=ino/lib/McopySerial/McopySerial.h + TMP_FILE=$(mktemp) + + 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}" + + awk '/END CMD/,EOF { print $0 }' "${HEADER}" >> "${TMP_FILE}" + + cp "${TMP_FILE}" "${HEADER}" + rm -f "${TMP_FILE}" +fi cp ino/lib/McopySerial/McopySerial.* ino/mcopy_cam_canon/ \ No newline at end of file