From 4e0149e752182a18a5b2eee44e367f884a6a3d44 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 21 Mar 2023 20:35:00 -0400 Subject: [PATCH] Fixed issue with baud being stored as const overflowed. Silly mistake. Also storing command chars as public const variables to shorten code and allow for mc.COMMAND rather than McopySerial::COMMAND. Cleans up example code a lot. --- ino/components/mcopy_light/McopySerial.cpp | 18 +--- ino/components/mcopy_light/McopySerial.h | 101 ++++++++++----------- ino/lib/McopySerial/McopySerial.cpp | 18 +--- ino/lib/McopySerial/McopySerial.h | 101 ++++++++++----------- ino/mcopy_JKMM100/McopySerial.cpp | 18 +--- ino/mcopy_JKMM100/McopySerial.h | 101 ++++++++++----------- ino/mcopy_JKMM100/mcopy_JKMM100.ino | 27 +++--- ino/mcopy_cam_canon/McopySerial.cpp | 18 +--- ino/mcopy_cam_canon/McopySerial.h | 101 ++++++++++----------- scripts/ino.sh | 2 +- 10 files changed, 233 insertions(+), 272 deletions(-) diff --git a/ino/components/mcopy_light/McopySerial.cpp b/ino/components/mcopy_light/McopySerial.cpp index b876653..d1af619 100644 --- a/ino/components/mcopy_light/McopySerial.cpp +++ b/ino/components/mcopy_light/McopySerial.cpp @@ -2,11 +2,10 @@ #include "McopySerial.h" -McopySerial::McopySerial ( char identity) { - id = identity; -} +McopySerial::McopySerial () {} -void McopySerial::begin () { +void McopySerial::begin (char identity) { + id = identity; Serial.begin(baud); Serial.flush(); Serial.setTimeout(serialDelay); @@ -24,7 +23,7 @@ char McopySerial::loop () { void McopySerial::_internal () { if (cmdChar == DEBUG) { - debugOn = !debugOn; + debug(!debugOn); } else if (cmdChar == CONNECT) { _connect(); } else if (cmdChar == MCOPY_IDENTIFIER) { @@ -42,16 +41,9 @@ void McopySerial::_identify () { log("identify()"); } -void McopySerial::setBaud (int baudRate) { - baud = baudRate; -} - -void McopySerial::setIdentity (char identity) { - id = identity; -} - void McopySerial::debug (bool state) { debugOn = state; + log("debug()"); } void McopySerial::confirm (char cmd) { diff --git a/ino/components/mcopy_light/McopySerial.h b/ino/components/mcopy_light/McopySerial.h index db2f9ba..f02c089 100644 --- a/ino/components/mcopy_light/McopySerial.h +++ b/ino/components/mcopy_light/McopySerial.h @@ -1,14 +1,15 @@ #ifndef MCOPY_SERIAL #define MCOPY_SERIAL -#include "Arduino.h" +#include class McopySerial { private: - const int serialDelay = 5; - volatile int baud = 57600; + const uint16_t serialDelay = 5; + const uint16_t baud = 57600; + volatile bool debugOn = false; volatile char cmdChar = 'z'; volatile char id; @@ -20,57 +21,55 @@ class McopySerial { public: /* CMD FLAGS */ - 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_EXPOSURE = 'G'; - 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 ERROR = 'E'; - 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 STATE = 'H'; - static const char TAKEUP_BACKWARD = 'F'; - static const char TAKEUP_FORWARD = 'D'; + const char BLACK = 'b'; + const char CAMERA = 'c'; + const char CAMERA_BACKWARD = 'f'; + const char CAMERA_CAPPER_IDENTIFIER = '8'; + const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + const char CAMERA_EXPOSURE = 'G'; + const char CAMERA_FORWARD = 'e'; + const char CAMERA_IDENTIFIER = 'k'; + const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + const char CAMERA_SECOND = '3'; + const char CAMERA_SECOND_BACKWARD = '2'; + const char CAMERA_SECOND_FORWARD = '1'; + const char CAMERA_SECOND_IDENTIFIER = 'y'; + const char CAMERA_TIMED = 'n'; + const char CAMERAS = '4'; + const char CAMERAS_IDENTIFIER = 'a'; + const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + const char CAPPER_IDENTIFIER = 'C'; + const char CAPPER_OFF = 'B'; + const char CAPPER_ON = 'A'; + const char CONNECT = 'i'; + const char DEBUG = 'd'; + const char ERROR = 'E'; + const char LIGHT = 'l'; + const char LIGHT_IDENTIFIER = 'o'; + const char MCOPY_IDENTIFIER = 'm'; + const char PROJECTOR = 'p'; + const char PROJECTOR_BACKWARD = 'h'; + const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + const char PROJECTOR_FORWARD = 'g'; + const char PROJECTOR_IDENTIFIER = 'j'; + const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + const char PROJECTOR_SECOND = 'w'; + const char PROJECTOR_SECOND_BACKWARD = 'v'; + const char PROJECTOR_SECOND_FORWARD = 'u'; + const char PROJECTOR_SECOND_IDENTIFIER = 't'; + const char PROJECTORS = 'x'; + const char PROJECTORS_IDENTIFIER = 'd'; + const char STATE = 'H'; + const char TAKEUP_BACKWARD = 'F'; + const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(char identity); + McopySerial(); - void begin(); - void setBaud(int baudRate); - void setIdentity(char identity); + void begin(char identity); char loop(); void confirm(char cmd); String getString(); diff --git a/ino/lib/McopySerial/McopySerial.cpp b/ino/lib/McopySerial/McopySerial.cpp index b876653..d1af619 100644 --- a/ino/lib/McopySerial/McopySerial.cpp +++ b/ino/lib/McopySerial/McopySerial.cpp @@ -2,11 +2,10 @@ #include "McopySerial.h" -McopySerial::McopySerial ( char identity) { - id = identity; -} +McopySerial::McopySerial () {} -void McopySerial::begin () { +void McopySerial::begin (char identity) { + id = identity; Serial.begin(baud); Serial.flush(); Serial.setTimeout(serialDelay); @@ -24,7 +23,7 @@ char McopySerial::loop () { void McopySerial::_internal () { if (cmdChar == DEBUG) { - debugOn = !debugOn; + debug(!debugOn); } else if (cmdChar == CONNECT) { _connect(); } else if (cmdChar == MCOPY_IDENTIFIER) { @@ -42,16 +41,9 @@ void McopySerial::_identify () { log("identify()"); } -void McopySerial::setBaud (int baudRate) { - baud = baudRate; -} - -void McopySerial::setIdentity (char identity) { - id = identity; -} - void McopySerial::debug (bool state) { debugOn = state; + log("debug()"); } void McopySerial::confirm (char cmd) { diff --git a/ino/lib/McopySerial/McopySerial.h b/ino/lib/McopySerial/McopySerial.h index db2f9ba..f02c089 100644 --- a/ino/lib/McopySerial/McopySerial.h +++ b/ino/lib/McopySerial/McopySerial.h @@ -1,14 +1,15 @@ #ifndef MCOPY_SERIAL #define MCOPY_SERIAL -#include "Arduino.h" +#include class McopySerial { private: - const int serialDelay = 5; - volatile int baud = 57600; + const uint16_t serialDelay = 5; + const uint16_t baud = 57600; + volatile bool debugOn = false; volatile char cmdChar = 'z'; volatile char id; @@ -20,57 +21,55 @@ class McopySerial { public: /* CMD FLAGS */ - 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_EXPOSURE = 'G'; - 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 ERROR = 'E'; - 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 STATE = 'H'; - static const char TAKEUP_BACKWARD = 'F'; - static const char TAKEUP_FORWARD = 'D'; + const char BLACK = 'b'; + const char CAMERA = 'c'; + const char CAMERA_BACKWARD = 'f'; + const char CAMERA_CAPPER_IDENTIFIER = '8'; + const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + const char CAMERA_EXPOSURE = 'G'; + const char CAMERA_FORWARD = 'e'; + const char CAMERA_IDENTIFIER = 'k'; + const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + const char CAMERA_SECOND = '3'; + const char CAMERA_SECOND_BACKWARD = '2'; + const char CAMERA_SECOND_FORWARD = '1'; + const char CAMERA_SECOND_IDENTIFIER = 'y'; + const char CAMERA_TIMED = 'n'; + const char CAMERAS = '4'; + const char CAMERAS_IDENTIFIER = 'a'; + const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + const char CAPPER_IDENTIFIER = 'C'; + const char CAPPER_OFF = 'B'; + const char CAPPER_ON = 'A'; + const char CONNECT = 'i'; + const char DEBUG = 'd'; + const char ERROR = 'E'; + const char LIGHT = 'l'; + const char LIGHT_IDENTIFIER = 'o'; + const char MCOPY_IDENTIFIER = 'm'; + const char PROJECTOR = 'p'; + const char PROJECTOR_BACKWARD = 'h'; + const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + const char PROJECTOR_FORWARD = 'g'; + const char PROJECTOR_IDENTIFIER = 'j'; + const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + const char PROJECTOR_SECOND = 'w'; + const char PROJECTOR_SECOND_BACKWARD = 'v'; + const char PROJECTOR_SECOND_FORWARD = 'u'; + const char PROJECTOR_SECOND_IDENTIFIER = 't'; + const char PROJECTORS = 'x'; + const char PROJECTORS_IDENTIFIER = 'd'; + const char STATE = 'H'; + const char TAKEUP_BACKWARD = 'F'; + const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(char identity); + McopySerial(); - void begin(); - void setBaud(int baudRate); - void setIdentity(char identity); + void begin(char identity); char loop(); void confirm(char cmd); String getString(); diff --git a/ino/mcopy_JKMM100/McopySerial.cpp b/ino/mcopy_JKMM100/McopySerial.cpp index b876653..d1af619 100644 --- a/ino/mcopy_JKMM100/McopySerial.cpp +++ b/ino/mcopy_JKMM100/McopySerial.cpp @@ -2,11 +2,10 @@ #include "McopySerial.h" -McopySerial::McopySerial ( char identity) { - id = identity; -} +McopySerial::McopySerial () {} -void McopySerial::begin () { +void McopySerial::begin (char identity) { + id = identity; Serial.begin(baud); Serial.flush(); Serial.setTimeout(serialDelay); @@ -24,7 +23,7 @@ char McopySerial::loop () { void McopySerial::_internal () { if (cmdChar == DEBUG) { - debugOn = !debugOn; + debug(!debugOn); } else if (cmdChar == CONNECT) { _connect(); } else if (cmdChar == MCOPY_IDENTIFIER) { @@ -42,16 +41,9 @@ void McopySerial::_identify () { log("identify()"); } -void McopySerial::setBaud (int baudRate) { - baud = baudRate; -} - -void McopySerial::setIdentity (char identity) { - id = identity; -} - void McopySerial::debug (bool state) { debugOn = state; + log("debug()"); } void McopySerial::confirm (char cmd) { diff --git a/ino/mcopy_JKMM100/McopySerial.h b/ino/mcopy_JKMM100/McopySerial.h index db2f9ba..f02c089 100644 --- a/ino/mcopy_JKMM100/McopySerial.h +++ b/ino/mcopy_JKMM100/McopySerial.h @@ -1,14 +1,15 @@ #ifndef MCOPY_SERIAL #define MCOPY_SERIAL -#include "Arduino.h" +#include class McopySerial { private: - const int serialDelay = 5; - volatile int baud = 57600; + const uint16_t serialDelay = 5; + const uint16_t baud = 57600; + volatile bool debugOn = false; volatile char cmdChar = 'z'; volatile char id; @@ -20,57 +21,55 @@ class McopySerial { public: /* CMD FLAGS */ - 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_EXPOSURE = 'G'; - 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 ERROR = 'E'; - 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 STATE = 'H'; - static const char TAKEUP_BACKWARD = 'F'; - static const char TAKEUP_FORWARD = 'D'; + const char BLACK = 'b'; + const char CAMERA = 'c'; + const char CAMERA_BACKWARD = 'f'; + const char CAMERA_CAPPER_IDENTIFIER = '8'; + const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + const char CAMERA_EXPOSURE = 'G'; + const char CAMERA_FORWARD = 'e'; + const char CAMERA_IDENTIFIER = 'k'; + const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + const char CAMERA_SECOND = '3'; + const char CAMERA_SECOND_BACKWARD = '2'; + const char CAMERA_SECOND_FORWARD = '1'; + const char CAMERA_SECOND_IDENTIFIER = 'y'; + const char CAMERA_TIMED = 'n'; + const char CAMERAS = '4'; + const char CAMERAS_IDENTIFIER = 'a'; + const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + const char CAPPER_IDENTIFIER = 'C'; + const char CAPPER_OFF = 'B'; + const char CAPPER_ON = 'A'; + const char CONNECT = 'i'; + const char DEBUG = 'd'; + const char ERROR = 'E'; + const char LIGHT = 'l'; + const char LIGHT_IDENTIFIER = 'o'; + const char MCOPY_IDENTIFIER = 'm'; + const char PROJECTOR = 'p'; + const char PROJECTOR_BACKWARD = 'h'; + const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + const char PROJECTOR_FORWARD = 'g'; + const char PROJECTOR_IDENTIFIER = 'j'; + const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + const char PROJECTOR_SECOND = 'w'; + const char PROJECTOR_SECOND_BACKWARD = 'v'; + const char PROJECTOR_SECOND_FORWARD = 'u'; + const char PROJECTOR_SECOND_IDENTIFIER = 't'; + const char PROJECTORS = 'x'; + const char PROJECTORS_IDENTIFIER = 'd'; + const char STATE = 'H'; + const char TAKEUP_BACKWARD = 'F'; + const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(char identity); + McopySerial(); - void begin(); - void setBaud(int baudRate); - void setIdentity(char identity); + void begin(char identity); char loop(); void confirm(char cmd); String getString(); diff --git a/ino/mcopy_JKMM100/mcopy_JKMM100.ino b/ino/mcopy_JKMM100/mcopy_JKMM100.ino index 3731d05..732d335 100644 --- a/ino/mcopy_JKMM100/mcopy_JKMM100.ino +++ b/ino/mcopy_JKMM100/mcopy_JKMM100.ino @@ -60,22 +60,19 @@ volatile long proj_avg = -1; volatile char cmdChar = 'z'; -McopySerial mc(McopySerial::PROJECTOR_IDENTIFIER); +McopySerial mc; void setup () { - mc.begin(); pins(); - proj_dir = false; - cmdChar = 'p'; + mc.begin(mc.PROJECTOR_IDENTIFIER); } void loop () { now = millis(); - if (proj_running) { proj_microswitch(); } else { - //cmdChar = mc.loop(); + cmdChar = mc.loop(); cmd(cmdChar); } } @@ -90,13 +87,13 @@ void pins () { } void cmd (char val) { - if (val == McopySerial::PROJECTOR_FORWARD) { + if (val == mc.PROJECTOR_FORWARD) { proj_direction(true); - } else if (val == McopySerial::PROJECTOR_BACKWARD) { + } else if (val == mc.PROJECTOR_BACKWARD) { proj_direction(false); - } else if (val == McopySerial::PROJECTOR) { + } else if (val == mc.PROJECTOR) { proj_start(); - } else if (val == McopySerial::STATE) { + } else if (val == mc.STATE) { state(); } } @@ -119,7 +116,7 @@ void proj_stop () { digitalWrite(PROJECTOR_FWD, HIGH); digitalWrite(PROJECTOR_BWD, HIGH); - mc.confirm(McopySerial::PROJECTOR); + mc.confirm(mc.PROJECTOR); mc.log("projector()"); proj_running = false; @@ -129,10 +126,10 @@ void proj_stop () { void proj_direction (boolean state) { proj_dir = state; if (state) { - mc.confirm(McopySerial::PROJECTOR_FORWARD); + mc.confirm(mc.PROJECTOR_FORWARD); mc.log("proj_direction -> true"); } else { - mc.confirm(McopySerial::PROJECTOR_BACKWARD); + mc.confirm(mc.PROJECTOR_BACKWARD); mc.log("proj_direction -> false"); } } @@ -171,8 +168,8 @@ void update_timing (int timing) { } void state () { - String stateString = String(McopySerial::CAMERA_EXPOSURE); + String stateString = String(mc.CAMERA_EXPOSURE); stateString += String(proj_avg); - stateString += String(McopySerial::STATE); + stateString += String(mc.STATE); mc.print(stateString); } diff --git a/ino/mcopy_cam_canon/McopySerial.cpp b/ino/mcopy_cam_canon/McopySerial.cpp index b876653..d1af619 100644 --- a/ino/mcopy_cam_canon/McopySerial.cpp +++ b/ino/mcopy_cam_canon/McopySerial.cpp @@ -2,11 +2,10 @@ #include "McopySerial.h" -McopySerial::McopySerial ( char identity) { - id = identity; -} +McopySerial::McopySerial () {} -void McopySerial::begin () { +void McopySerial::begin (char identity) { + id = identity; Serial.begin(baud); Serial.flush(); Serial.setTimeout(serialDelay); @@ -24,7 +23,7 @@ char McopySerial::loop () { void McopySerial::_internal () { if (cmdChar == DEBUG) { - debugOn = !debugOn; + debug(!debugOn); } else if (cmdChar == CONNECT) { _connect(); } else if (cmdChar == MCOPY_IDENTIFIER) { @@ -42,16 +41,9 @@ void McopySerial::_identify () { log("identify()"); } -void McopySerial::setBaud (int baudRate) { - baud = baudRate; -} - -void McopySerial::setIdentity (char identity) { - id = identity; -} - void McopySerial::debug (bool state) { debugOn = state; + log("debug()"); } void McopySerial::confirm (char cmd) { diff --git a/ino/mcopy_cam_canon/McopySerial.h b/ino/mcopy_cam_canon/McopySerial.h index db2f9ba..f02c089 100644 --- a/ino/mcopy_cam_canon/McopySerial.h +++ b/ino/mcopy_cam_canon/McopySerial.h @@ -1,14 +1,15 @@ #ifndef MCOPY_SERIAL #define MCOPY_SERIAL -#include "Arduino.h" +#include class McopySerial { private: - const int serialDelay = 5; - volatile int baud = 57600; + const uint16_t serialDelay = 5; + const uint16_t baud = 57600; + volatile bool debugOn = false; volatile char cmdChar = 'z'; volatile char id; @@ -20,57 +21,55 @@ class McopySerial { public: /* CMD FLAGS */ - 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_EXPOSURE = 'G'; - 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 ERROR = 'E'; - 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 STATE = 'H'; - static const char TAKEUP_BACKWARD = 'F'; - static const char TAKEUP_FORWARD = 'D'; + const char BLACK = 'b'; + const char CAMERA = 'c'; + const char CAMERA_BACKWARD = 'f'; + const char CAMERA_CAPPER_IDENTIFIER = '8'; + const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9'; + const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0'; + const char CAMERA_EXPOSURE = 'G'; + const char CAMERA_FORWARD = 'e'; + const char CAMERA_IDENTIFIER = 'k'; + const char CAMERA_PROJECTORS_IDENTIFIER = '5'; + const char CAMERA_SECOND = '3'; + const char CAMERA_SECOND_BACKWARD = '2'; + const char CAMERA_SECOND_FORWARD = '1'; + const char CAMERA_SECOND_IDENTIFIER = 'y'; + const char CAMERA_TIMED = 'n'; + const char CAMERAS = '4'; + const char CAMERAS_IDENTIFIER = 'a'; + const char CAMERAS_PROJECTOR_IDENTIFIER = '6'; + const char CAMERAS_PROJECTORS_IDENTIFIER = '7'; + const char CAPPER_IDENTIFIER = 'C'; + const char CAPPER_OFF = 'B'; + const char CAPPER_ON = 'A'; + const char CONNECT = 'i'; + const char DEBUG = 'd'; + const char ERROR = 'E'; + const char LIGHT = 'l'; + const char LIGHT_IDENTIFIER = 'o'; + const char MCOPY_IDENTIFIER = 'm'; + const char PROJECTOR = 'p'; + const char PROJECTOR_BACKWARD = 'h'; + const char PROJECTOR_CAMERA_IDENTIFIER = 's'; + const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r'; + const char PROJECTOR_FORWARD = 'g'; + const char PROJECTOR_IDENTIFIER = 'j'; + const char PROJECTOR_LIGHT_IDENTIFIER = 'q'; + const char PROJECTOR_SECOND = 'w'; + const char PROJECTOR_SECOND_BACKWARD = 'v'; + const char PROJECTOR_SECOND_FORWARD = 'u'; + const char PROJECTOR_SECOND_IDENTIFIER = 't'; + const char PROJECTORS = 'x'; + const char PROJECTORS_IDENTIFIER = 'd'; + const char STATE = 'H'; + const char TAKEUP_BACKWARD = 'F'; + const char TAKEUP_FORWARD = 'D'; /* END CMD FLAGS */ - McopySerial(char identity); + McopySerial(); - void begin(); - void setBaud(int baudRate); - void setIdentity(char identity); + void begin(char identity); char loop(); void confirm(char cmd); String getString(); diff --git a/scripts/ino.sh b/scripts/ino.sh index 9f412d9..5a290ef 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 | " static const char \($k) = '"'"'\(.[$k])'"'"';"' | awk '{print "\t"$1" "$2" "$3" "toupper($4)" "$5" "$6}' >> "${TMP_FILE}" + cat ./data/cfg.json | jq -r '.arduino.cmd | keys[] as $k | " const char \($k) = '"'"'\(.[$k])'"'"';"' | awk '{print "\t"$1" "$2" "toupper($3)" "$4" "$5}' >> "${TMP_FILE}" awk '/END CMD/,EOF { print $0 }' "${HEADER}" >> "${TMP_FILE}"