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.
This commit is contained in:
parent
5c6b9191e5
commit
4e0149e752
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
#include "McopySerial.h"
|
#include "McopySerial.h"
|
||||||
|
|
||||||
McopySerial::McopySerial ( char identity) {
|
McopySerial::McopySerial () {}
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::begin () {
|
void McopySerial::begin (char identity) {
|
||||||
|
id = identity;
|
||||||
Serial.begin(baud);
|
Serial.begin(baud);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.setTimeout(serialDelay);
|
Serial.setTimeout(serialDelay);
|
||||||
|
@ -24,7 +23,7 @@ char McopySerial::loop () {
|
||||||
|
|
||||||
void McopySerial::_internal () {
|
void McopySerial::_internal () {
|
||||||
if (cmdChar == DEBUG) {
|
if (cmdChar == DEBUG) {
|
||||||
debugOn = !debugOn;
|
debug(!debugOn);
|
||||||
} else if (cmdChar == CONNECT) {
|
} else if (cmdChar == CONNECT) {
|
||||||
_connect();
|
_connect();
|
||||||
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
||||||
|
@ -42,16 +41,9 @@ void McopySerial::_identify () {
|
||||||
log("identify()");
|
log("identify()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::setBaud (int baudRate) {
|
|
||||||
baud = baudRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::setIdentity (char identity) {
|
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::debug (bool state) {
|
void McopySerial::debug (bool state) {
|
||||||
debugOn = state;
|
debugOn = state;
|
||||||
|
log("debug()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::confirm (char cmd) {
|
void McopySerial::confirm (char cmd) {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#ifndef MCOPY_SERIAL
|
#ifndef MCOPY_SERIAL
|
||||||
#define MCOPY_SERIAL
|
#define MCOPY_SERIAL
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
|
||||||
class McopySerial {
|
class McopySerial {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int serialDelay = 5;
|
|
||||||
|
|
||||||
volatile int baud = 57600;
|
const uint16_t serialDelay = 5;
|
||||||
|
const uint16_t baud = 57600;
|
||||||
|
|
||||||
volatile bool debugOn = false;
|
volatile bool debugOn = false;
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
volatile char id;
|
volatile char id;
|
||||||
|
@ -20,57 +21,55 @@ class McopySerial {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* CMD FLAGS */
|
/* CMD FLAGS */
|
||||||
static const char BLACK = 'b';
|
const char BLACK = 'b';
|
||||||
static const char CAMERA = 'c';
|
const char CAMERA = 'c';
|
||||||
static const char CAMERA_BACKWARD = 'f';
|
const char CAMERA_BACKWARD = 'f';
|
||||||
static const char CAMERA_CAPPER_IDENTIFIER = '8';
|
const char CAMERA_CAPPER_IDENTIFIER = '8';
|
||||||
static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
||||||
static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
||||||
static const char CAMERA_EXPOSURE = 'G';
|
const char CAMERA_EXPOSURE = 'G';
|
||||||
static const char CAMERA_FORWARD = 'e';
|
const char CAMERA_FORWARD = 'e';
|
||||||
static const char CAMERA_IDENTIFIER = 'k';
|
const char CAMERA_IDENTIFIER = 'k';
|
||||||
static const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
||||||
static const char CAMERA_SECOND = '3';
|
const char CAMERA_SECOND = '3';
|
||||||
static const char CAMERA_SECOND_BACKWARD = '2';
|
const char CAMERA_SECOND_BACKWARD = '2';
|
||||||
static const char CAMERA_SECOND_FORWARD = '1';
|
const char CAMERA_SECOND_FORWARD = '1';
|
||||||
static const char CAMERA_SECOND_IDENTIFIER = 'y';
|
const char CAMERA_SECOND_IDENTIFIER = 'y';
|
||||||
static const char CAMERA_TIMED = 'n';
|
const char CAMERA_TIMED = 'n';
|
||||||
static const char CAMERAS = '4';
|
const char CAMERAS = '4';
|
||||||
static const char CAMERAS_IDENTIFIER = 'a';
|
const char CAMERAS_IDENTIFIER = 'a';
|
||||||
static const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
||||||
static const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
||||||
static const char CAPPER_IDENTIFIER = 'C';
|
const char CAPPER_IDENTIFIER = 'C';
|
||||||
static const char CAPPER_OFF = 'B';
|
const char CAPPER_OFF = 'B';
|
||||||
static const char CAPPER_ON = 'A';
|
const char CAPPER_ON = 'A';
|
||||||
static const char CONNECT = 'i';
|
const char CONNECT = 'i';
|
||||||
static const char DEBUG = 'd';
|
const char DEBUG = 'd';
|
||||||
static const char ERROR = 'E';
|
const char ERROR = 'E';
|
||||||
static const char LIGHT = 'l';
|
const char LIGHT = 'l';
|
||||||
static const char LIGHT_IDENTIFIER = 'o';
|
const char LIGHT_IDENTIFIER = 'o';
|
||||||
static const char MCOPY_IDENTIFIER = 'm';
|
const char MCOPY_IDENTIFIER = 'm';
|
||||||
static const char PROJECTOR = 'p';
|
const char PROJECTOR = 'p';
|
||||||
static const char PROJECTOR_BACKWARD = 'h';
|
const char PROJECTOR_BACKWARD = 'h';
|
||||||
static const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
||||||
static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
||||||
static const char PROJECTOR_FORWARD = 'g';
|
const char PROJECTOR_FORWARD = 'g';
|
||||||
static const char PROJECTOR_IDENTIFIER = 'j';
|
const char PROJECTOR_IDENTIFIER = 'j';
|
||||||
static const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
||||||
static const char PROJECTOR_SECOND = 'w';
|
const char PROJECTOR_SECOND = 'w';
|
||||||
static const char PROJECTOR_SECOND_BACKWARD = 'v';
|
const char PROJECTOR_SECOND_BACKWARD = 'v';
|
||||||
static const char PROJECTOR_SECOND_FORWARD = 'u';
|
const char PROJECTOR_SECOND_FORWARD = 'u';
|
||||||
static const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
||||||
static const char PROJECTORS = 'x';
|
const char PROJECTORS = 'x';
|
||||||
static const char PROJECTORS_IDENTIFIER = 'd';
|
const char PROJECTORS_IDENTIFIER = 'd';
|
||||||
static const char STATE = 'H';
|
const char STATE = 'H';
|
||||||
static const char TAKEUP_BACKWARD = 'F';
|
const char TAKEUP_BACKWARD = 'F';
|
||||||
static const char TAKEUP_FORWARD = 'D';
|
const char TAKEUP_FORWARD = 'D';
|
||||||
/* END CMD FLAGS */
|
/* END CMD FLAGS */
|
||||||
|
|
||||||
McopySerial(char identity);
|
McopySerial();
|
||||||
|
|
||||||
void begin();
|
void begin(char identity);
|
||||||
void setBaud(int baudRate);
|
|
||||||
void setIdentity(char identity);
|
|
||||||
char loop();
|
char loop();
|
||||||
void confirm(char cmd);
|
void confirm(char cmd);
|
||||||
String getString();
|
String getString();
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
#include "McopySerial.h"
|
#include "McopySerial.h"
|
||||||
|
|
||||||
McopySerial::McopySerial ( char identity) {
|
McopySerial::McopySerial () {}
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::begin () {
|
void McopySerial::begin (char identity) {
|
||||||
|
id = identity;
|
||||||
Serial.begin(baud);
|
Serial.begin(baud);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.setTimeout(serialDelay);
|
Serial.setTimeout(serialDelay);
|
||||||
|
@ -24,7 +23,7 @@ char McopySerial::loop () {
|
||||||
|
|
||||||
void McopySerial::_internal () {
|
void McopySerial::_internal () {
|
||||||
if (cmdChar == DEBUG) {
|
if (cmdChar == DEBUG) {
|
||||||
debugOn = !debugOn;
|
debug(!debugOn);
|
||||||
} else if (cmdChar == CONNECT) {
|
} else if (cmdChar == CONNECT) {
|
||||||
_connect();
|
_connect();
|
||||||
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
||||||
|
@ -42,16 +41,9 @@ void McopySerial::_identify () {
|
||||||
log("identify()");
|
log("identify()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::setBaud (int baudRate) {
|
|
||||||
baud = baudRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::setIdentity (char identity) {
|
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::debug (bool state) {
|
void McopySerial::debug (bool state) {
|
||||||
debugOn = state;
|
debugOn = state;
|
||||||
|
log("debug()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::confirm (char cmd) {
|
void McopySerial::confirm (char cmd) {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#ifndef MCOPY_SERIAL
|
#ifndef MCOPY_SERIAL
|
||||||
#define MCOPY_SERIAL
|
#define MCOPY_SERIAL
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
|
||||||
class McopySerial {
|
class McopySerial {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int serialDelay = 5;
|
|
||||||
|
|
||||||
volatile int baud = 57600;
|
const uint16_t serialDelay = 5;
|
||||||
|
const uint16_t baud = 57600;
|
||||||
|
|
||||||
volatile bool debugOn = false;
|
volatile bool debugOn = false;
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
volatile char id;
|
volatile char id;
|
||||||
|
@ -20,57 +21,55 @@ class McopySerial {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* CMD FLAGS */
|
/* CMD FLAGS */
|
||||||
static const char BLACK = 'b';
|
const char BLACK = 'b';
|
||||||
static const char CAMERA = 'c';
|
const char CAMERA = 'c';
|
||||||
static const char CAMERA_BACKWARD = 'f';
|
const char CAMERA_BACKWARD = 'f';
|
||||||
static const char CAMERA_CAPPER_IDENTIFIER = '8';
|
const char CAMERA_CAPPER_IDENTIFIER = '8';
|
||||||
static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
||||||
static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
||||||
static const char CAMERA_EXPOSURE = 'G';
|
const char CAMERA_EXPOSURE = 'G';
|
||||||
static const char CAMERA_FORWARD = 'e';
|
const char CAMERA_FORWARD = 'e';
|
||||||
static const char CAMERA_IDENTIFIER = 'k';
|
const char CAMERA_IDENTIFIER = 'k';
|
||||||
static const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
||||||
static const char CAMERA_SECOND = '3';
|
const char CAMERA_SECOND = '3';
|
||||||
static const char CAMERA_SECOND_BACKWARD = '2';
|
const char CAMERA_SECOND_BACKWARD = '2';
|
||||||
static const char CAMERA_SECOND_FORWARD = '1';
|
const char CAMERA_SECOND_FORWARD = '1';
|
||||||
static const char CAMERA_SECOND_IDENTIFIER = 'y';
|
const char CAMERA_SECOND_IDENTIFIER = 'y';
|
||||||
static const char CAMERA_TIMED = 'n';
|
const char CAMERA_TIMED = 'n';
|
||||||
static const char CAMERAS = '4';
|
const char CAMERAS = '4';
|
||||||
static const char CAMERAS_IDENTIFIER = 'a';
|
const char CAMERAS_IDENTIFIER = 'a';
|
||||||
static const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
||||||
static const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
||||||
static const char CAPPER_IDENTIFIER = 'C';
|
const char CAPPER_IDENTIFIER = 'C';
|
||||||
static const char CAPPER_OFF = 'B';
|
const char CAPPER_OFF = 'B';
|
||||||
static const char CAPPER_ON = 'A';
|
const char CAPPER_ON = 'A';
|
||||||
static const char CONNECT = 'i';
|
const char CONNECT = 'i';
|
||||||
static const char DEBUG = 'd';
|
const char DEBUG = 'd';
|
||||||
static const char ERROR = 'E';
|
const char ERROR = 'E';
|
||||||
static const char LIGHT = 'l';
|
const char LIGHT = 'l';
|
||||||
static const char LIGHT_IDENTIFIER = 'o';
|
const char LIGHT_IDENTIFIER = 'o';
|
||||||
static const char MCOPY_IDENTIFIER = 'm';
|
const char MCOPY_IDENTIFIER = 'm';
|
||||||
static const char PROJECTOR = 'p';
|
const char PROJECTOR = 'p';
|
||||||
static const char PROJECTOR_BACKWARD = 'h';
|
const char PROJECTOR_BACKWARD = 'h';
|
||||||
static const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
||||||
static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
||||||
static const char PROJECTOR_FORWARD = 'g';
|
const char PROJECTOR_FORWARD = 'g';
|
||||||
static const char PROJECTOR_IDENTIFIER = 'j';
|
const char PROJECTOR_IDENTIFIER = 'j';
|
||||||
static const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
||||||
static const char PROJECTOR_SECOND = 'w';
|
const char PROJECTOR_SECOND = 'w';
|
||||||
static const char PROJECTOR_SECOND_BACKWARD = 'v';
|
const char PROJECTOR_SECOND_BACKWARD = 'v';
|
||||||
static const char PROJECTOR_SECOND_FORWARD = 'u';
|
const char PROJECTOR_SECOND_FORWARD = 'u';
|
||||||
static const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
||||||
static const char PROJECTORS = 'x';
|
const char PROJECTORS = 'x';
|
||||||
static const char PROJECTORS_IDENTIFIER = 'd';
|
const char PROJECTORS_IDENTIFIER = 'd';
|
||||||
static const char STATE = 'H';
|
const char STATE = 'H';
|
||||||
static const char TAKEUP_BACKWARD = 'F';
|
const char TAKEUP_BACKWARD = 'F';
|
||||||
static const char TAKEUP_FORWARD = 'D';
|
const char TAKEUP_FORWARD = 'D';
|
||||||
/* END CMD FLAGS */
|
/* END CMD FLAGS */
|
||||||
|
|
||||||
McopySerial(char identity);
|
McopySerial();
|
||||||
|
|
||||||
void begin();
|
void begin(char identity);
|
||||||
void setBaud(int baudRate);
|
|
||||||
void setIdentity(char identity);
|
|
||||||
char loop();
|
char loop();
|
||||||
void confirm(char cmd);
|
void confirm(char cmd);
|
||||||
String getString();
|
String getString();
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
#include "McopySerial.h"
|
#include "McopySerial.h"
|
||||||
|
|
||||||
McopySerial::McopySerial ( char identity) {
|
McopySerial::McopySerial () {}
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::begin () {
|
void McopySerial::begin (char identity) {
|
||||||
|
id = identity;
|
||||||
Serial.begin(baud);
|
Serial.begin(baud);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.setTimeout(serialDelay);
|
Serial.setTimeout(serialDelay);
|
||||||
|
@ -24,7 +23,7 @@ char McopySerial::loop () {
|
||||||
|
|
||||||
void McopySerial::_internal () {
|
void McopySerial::_internal () {
|
||||||
if (cmdChar == DEBUG) {
|
if (cmdChar == DEBUG) {
|
||||||
debugOn = !debugOn;
|
debug(!debugOn);
|
||||||
} else if (cmdChar == CONNECT) {
|
} else if (cmdChar == CONNECT) {
|
||||||
_connect();
|
_connect();
|
||||||
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
||||||
|
@ -42,16 +41,9 @@ void McopySerial::_identify () {
|
||||||
log("identify()");
|
log("identify()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::setBaud (int baudRate) {
|
|
||||||
baud = baudRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::setIdentity (char identity) {
|
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::debug (bool state) {
|
void McopySerial::debug (bool state) {
|
||||||
debugOn = state;
|
debugOn = state;
|
||||||
|
log("debug()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::confirm (char cmd) {
|
void McopySerial::confirm (char cmd) {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#ifndef MCOPY_SERIAL
|
#ifndef MCOPY_SERIAL
|
||||||
#define MCOPY_SERIAL
|
#define MCOPY_SERIAL
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
|
||||||
class McopySerial {
|
class McopySerial {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int serialDelay = 5;
|
|
||||||
|
|
||||||
volatile int baud = 57600;
|
const uint16_t serialDelay = 5;
|
||||||
|
const uint16_t baud = 57600;
|
||||||
|
|
||||||
volatile bool debugOn = false;
|
volatile bool debugOn = false;
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
volatile char id;
|
volatile char id;
|
||||||
|
@ -20,57 +21,55 @@ class McopySerial {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* CMD FLAGS */
|
/* CMD FLAGS */
|
||||||
static const char BLACK = 'b';
|
const char BLACK = 'b';
|
||||||
static const char CAMERA = 'c';
|
const char CAMERA = 'c';
|
||||||
static const char CAMERA_BACKWARD = 'f';
|
const char CAMERA_BACKWARD = 'f';
|
||||||
static const char CAMERA_CAPPER_IDENTIFIER = '8';
|
const char CAMERA_CAPPER_IDENTIFIER = '8';
|
||||||
static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
||||||
static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
||||||
static const char CAMERA_EXPOSURE = 'G';
|
const char CAMERA_EXPOSURE = 'G';
|
||||||
static const char CAMERA_FORWARD = 'e';
|
const char CAMERA_FORWARD = 'e';
|
||||||
static const char CAMERA_IDENTIFIER = 'k';
|
const char CAMERA_IDENTIFIER = 'k';
|
||||||
static const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
||||||
static const char CAMERA_SECOND = '3';
|
const char CAMERA_SECOND = '3';
|
||||||
static const char CAMERA_SECOND_BACKWARD = '2';
|
const char CAMERA_SECOND_BACKWARD = '2';
|
||||||
static const char CAMERA_SECOND_FORWARD = '1';
|
const char CAMERA_SECOND_FORWARD = '1';
|
||||||
static const char CAMERA_SECOND_IDENTIFIER = 'y';
|
const char CAMERA_SECOND_IDENTIFIER = 'y';
|
||||||
static const char CAMERA_TIMED = 'n';
|
const char CAMERA_TIMED = 'n';
|
||||||
static const char CAMERAS = '4';
|
const char CAMERAS = '4';
|
||||||
static const char CAMERAS_IDENTIFIER = 'a';
|
const char CAMERAS_IDENTIFIER = 'a';
|
||||||
static const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
||||||
static const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
||||||
static const char CAPPER_IDENTIFIER = 'C';
|
const char CAPPER_IDENTIFIER = 'C';
|
||||||
static const char CAPPER_OFF = 'B';
|
const char CAPPER_OFF = 'B';
|
||||||
static const char CAPPER_ON = 'A';
|
const char CAPPER_ON = 'A';
|
||||||
static const char CONNECT = 'i';
|
const char CONNECT = 'i';
|
||||||
static const char DEBUG = 'd';
|
const char DEBUG = 'd';
|
||||||
static const char ERROR = 'E';
|
const char ERROR = 'E';
|
||||||
static const char LIGHT = 'l';
|
const char LIGHT = 'l';
|
||||||
static const char LIGHT_IDENTIFIER = 'o';
|
const char LIGHT_IDENTIFIER = 'o';
|
||||||
static const char MCOPY_IDENTIFIER = 'm';
|
const char MCOPY_IDENTIFIER = 'm';
|
||||||
static const char PROJECTOR = 'p';
|
const char PROJECTOR = 'p';
|
||||||
static const char PROJECTOR_BACKWARD = 'h';
|
const char PROJECTOR_BACKWARD = 'h';
|
||||||
static const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
||||||
static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
||||||
static const char PROJECTOR_FORWARD = 'g';
|
const char PROJECTOR_FORWARD = 'g';
|
||||||
static const char PROJECTOR_IDENTIFIER = 'j';
|
const char PROJECTOR_IDENTIFIER = 'j';
|
||||||
static const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
||||||
static const char PROJECTOR_SECOND = 'w';
|
const char PROJECTOR_SECOND = 'w';
|
||||||
static const char PROJECTOR_SECOND_BACKWARD = 'v';
|
const char PROJECTOR_SECOND_BACKWARD = 'v';
|
||||||
static const char PROJECTOR_SECOND_FORWARD = 'u';
|
const char PROJECTOR_SECOND_FORWARD = 'u';
|
||||||
static const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
||||||
static const char PROJECTORS = 'x';
|
const char PROJECTORS = 'x';
|
||||||
static const char PROJECTORS_IDENTIFIER = 'd';
|
const char PROJECTORS_IDENTIFIER = 'd';
|
||||||
static const char STATE = 'H';
|
const char STATE = 'H';
|
||||||
static const char TAKEUP_BACKWARD = 'F';
|
const char TAKEUP_BACKWARD = 'F';
|
||||||
static const char TAKEUP_FORWARD = 'D';
|
const char TAKEUP_FORWARD = 'D';
|
||||||
/* END CMD FLAGS */
|
/* END CMD FLAGS */
|
||||||
|
|
||||||
McopySerial(char identity);
|
McopySerial();
|
||||||
|
|
||||||
void begin();
|
void begin(char identity);
|
||||||
void setBaud(int baudRate);
|
|
||||||
void setIdentity(char identity);
|
|
||||||
char loop();
|
char loop();
|
||||||
void confirm(char cmd);
|
void confirm(char cmd);
|
||||||
String getString();
|
String getString();
|
||||||
|
|
|
@ -60,22 +60,19 @@ volatile long proj_avg = -1;
|
||||||
|
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
|
|
||||||
McopySerial mc(McopySerial::PROJECTOR_IDENTIFIER);
|
McopySerial mc;
|
||||||
|
|
||||||
void setup () {
|
void setup () {
|
||||||
mc.begin();
|
|
||||||
pins();
|
pins();
|
||||||
proj_dir = false;
|
mc.begin(mc.PROJECTOR_IDENTIFIER);
|
||||||
cmdChar = 'p';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop () {
|
void loop () {
|
||||||
now = millis();
|
now = millis();
|
||||||
|
|
||||||
if (proj_running) {
|
if (proj_running) {
|
||||||
proj_microswitch();
|
proj_microswitch();
|
||||||
} else {
|
} else {
|
||||||
//cmdChar = mc.loop();
|
cmdChar = mc.loop();
|
||||||
cmd(cmdChar);
|
cmd(cmdChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,13 +87,13 @@ void pins () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd (char val) {
|
void cmd (char val) {
|
||||||
if (val == McopySerial::PROJECTOR_FORWARD) {
|
if (val == mc.PROJECTOR_FORWARD) {
|
||||||
proj_direction(true);
|
proj_direction(true);
|
||||||
} else if (val == McopySerial::PROJECTOR_BACKWARD) {
|
} else if (val == mc.PROJECTOR_BACKWARD) {
|
||||||
proj_direction(false);
|
proj_direction(false);
|
||||||
} else if (val == McopySerial::PROJECTOR) {
|
} else if (val == mc.PROJECTOR) {
|
||||||
proj_start();
|
proj_start();
|
||||||
} else if (val == McopySerial::STATE) {
|
} else if (val == mc.STATE) {
|
||||||
state();
|
state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +116,7 @@ void proj_stop () {
|
||||||
digitalWrite(PROJECTOR_FWD, HIGH);
|
digitalWrite(PROJECTOR_FWD, HIGH);
|
||||||
digitalWrite(PROJECTOR_BWD, HIGH);
|
digitalWrite(PROJECTOR_BWD, HIGH);
|
||||||
|
|
||||||
mc.confirm(McopySerial::PROJECTOR);
|
mc.confirm(mc.PROJECTOR);
|
||||||
mc.log("projector()");
|
mc.log("projector()");
|
||||||
proj_running = false;
|
proj_running = false;
|
||||||
|
|
||||||
|
@ -129,10 +126,10 @@ void proj_stop () {
|
||||||
void proj_direction (boolean state) {
|
void proj_direction (boolean state) {
|
||||||
proj_dir = state;
|
proj_dir = state;
|
||||||
if (state) {
|
if (state) {
|
||||||
mc.confirm(McopySerial::PROJECTOR_FORWARD);
|
mc.confirm(mc.PROJECTOR_FORWARD);
|
||||||
mc.log("proj_direction -> true");
|
mc.log("proj_direction -> true");
|
||||||
} else {
|
} else {
|
||||||
mc.confirm(McopySerial::PROJECTOR_BACKWARD);
|
mc.confirm(mc.PROJECTOR_BACKWARD);
|
||||||
mc.log("proj_direction -> false");
|
mc.log("proj_direction -> false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,8 +168,8 @@ void update_timing (int timing) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void state () {
|
void state () {
|
||||||
String stateString = String(McopySerial::CAMERA_EXPOSURE);
|
String stateString = String(mc.CAMERA_EXPOSURE);
|
||||||
stateString += String(proj_avg);
|
stateString += String(proj_avg);
|
||||||
stateString += String(McopySerial::STATE);
|
stateString += String(mc.STATE);
|
||||||
mc.print(stateString);
|
mc.print(stateString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
#include "McopySerial.h"
|
#include "McopySerial.h"
|
||||||
|
|
||||||
McopySerial::McopySerial ( char identity) {
|
McopySerial::McopySerial () {}
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::begin () {
|
void McopySerial::begin (char identity) {
|
||||||
|
id = identity;
|
||||||
Serial.begin(baud);
|
Serial.begin(baud);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
Serial.setTimeout(serialDelay);
|
Serial.setTimeout(serialDelay);
|
||||||
|
@ -24,7 +23,7 @@ char McopySerial::loop () {
|
||||||
|
|
||||||
void McopySerial::_internal () {
|
void McopySerial::_internal () {
|
||||||
if (cmdChar == DEBUG) {
|
if (cmdChar == DEBUG) {
|
||||||
debugOn = !debugOn;
|
debug(!debugOn);
|
||||||
} else if (cmdChar == CONNECT) {
|
} else if (cmdChar == CONNECT) {
|
||||||
_connect();
|
_connect();
|
||||||
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
||||||
|
@ -42,16 +41,9 @@ void McopySerial::_identify () {
|
||||||
log("identify()");
|
log("identify()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::setBaud (int baudRate) {
|
|
||||||
baud = baudRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::setIdentity (char identity) {
|
|
||||||
id = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McopySerial::debug (bool state) {
|
void McopySerial::debug (bool state) {
|
||||||
debugOn = state;
|
debugOn = state;
|
||||||
|
log("debug()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void McopySerial::confirm (char cmd) {
|
void McopySerial::confirm (char cmd) {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#ifndef MCOPY_SERIAL
|
#ifndef MCOPY_SERIAL
|
||||||
#define MCOPY_SERIAL
|
#define MCOPY_SERIAL
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
|
||||||
class McopySerial {
|
class McopySerial {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int serialDelay = 5;
|
|
||||||
|
|
||||||
volatile int baud = 57600;
|
const uint16_t serialDelay = 5;
|
||||||
|
const uint16_t baud = 57600;
|
||||||
|
|
||||||
volatile bool debugOn = false;
|
volatile bool debugOn = false;
|
||||||
volatile char cmdChar = 'z';
|
volatile char cmdChar = 'z';
|
||||||
volatile char id;
|
volatile char id;
|
||||||
|
@ -20,57 +21,55 @@ class McopySerial {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* CMD FLAGS */
|
/* CMD FLAGS */
|
||||||
static const char BLACK = 'b';
|
const char BLACK = 'b';
|
||||||
static const char CAMERA = 'c';
|
const char CAMERA = 'c';
|
||||||
static const char CAMERA_BACKWARD = 'f';
|
const char CAMERA_BACKWARD = 'f';
|
||||||
static const char CAMERA_CAPPER_IDENTIFIER = '8';
|
const char CAMERA_CAPPER_IDENTIFIER = '8';
|
||||||
static const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
const char CAMERA_CAPPER_PROJECTOR_IDENTIFIER = '9';
|
||||||
static const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
const char CAMERA_CAPPER_PROJECTORS_IDENTIFIER = '0';
|
||||||
static const char CAMERA_EXPOSURE = 'G';
|
const char CAMERA_EXPOSURE = 'G';
|
||||||
static const char CAMERA_FORWARD = 'e';
|
const char CAMERA_FORWARD = 'e';
|
||||||
static const char CAMERA_IDENTIFIER = 'k';
|
const char CAMERA_IDENTIFIER = 'k';
|
||||||
static const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
const char CAMERA_PROJECTORS_IDENTIFIER = '5';
|
||||||
static const char CAMERA_SECOND = '3';
|
const char CAMERA_SECOND = '3';
|
||||||
static const char CAMERA_SECOND_BACKWARD = '2';
|
const char CAMERA_SECOND_BACKWARD = '2';
|
||||||
static const char CAMERA_SECOND_FORWARD = '1';
|
const char CAMERA_SECOND_FORWARD = '1';
|
||||||
static const char CAMERA_SECOND_IDENTIFIER = 'y';
|
const char CAMERA_SECOND_IDENTIFIER = 'y';
|
||||||
static const char CAMERA_TIMED = 'n';
|
const char CAMERA_TIMED = 'n';
|
||||||
static const char CAMERAS = '4';
|
const char CAMERAS = '4';
|
||||||
static const char CAMERAS_IDENTIFIER = 'a';
|
const char CAMERAS_IDENTIFIER = 'a';
|
||||||
static const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
const char CAMERAS_PROJECTOR_IDENTIFIER = '6';
|
||||||
static const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
const char CAMERAS_PROJECTORS_IDENTIFIER = '7';
|
||||||
static const char CAPPER_IDENTIFIER = 'C';
|
const char CAPPER_IDENTIFIER = 'C';
|
||||||
static const char CAPPER_OFF = 'B';
|
const char CAPPER_OFF = 'B';
|
||||||
static const char CAPPER_ON = 'A';
|
const char CAPPER_ON = 'A';
|
||||||
static const char CONNECT = 'i';
|
const char CONNECT = 'i';
|
||||||
static const char DEBUG = 'd';
|
const char DEBUG = 'd';
|
||||||
static const char ERROR = 'E';
|
const char ERROR = 'E';
|
||||||
static const char LIGHT = 'l';
|
const char LIGHT = 'l';
|
||||||
static const char LIGHT_IDENTIFIER = 'o';
|
const char LIGHT_IDENTIFIER = 'o';
|
||||||
static const char MCOPY_IDENTIFIER = 'm';
|
const char MCOPY_IDENTIFIER = 'm';
|
||||||
static const char PROJECTOR = 'p';
|
const char PROJECTOR = 'p';
|
||||||
static const char PROJECTOR_BACKWARD = 'h';
|
const char PROJECTOR_BACKWARD = 'h';
|
||||||
static const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
const char PROJECTOR_CAMERA_IDENTIFIER = 's';
|
||||||
static const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
const char PROJECTOR_CAMERA_LIGHT_IDENTIFIER = 'r';
|
||||||
static const char PROJECTOR_FORWARD = 'g';
|
const char PROJECTOR_FORWARD = 'g';
|
||||||
static const char PROJECTOR_IDENTIFIER = 'j';
|
const char PROJECTOR_IDENTIFIER = 'j';
|
||||||
static const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
const char PROJECTOR_LIGHT_IDENTIFIER = 'q';
|
||||||
static const char PROJECTOR_SECOND = 'w';
|
const char PROJECTOR_SECOND = 'w';
|
||||||
static const char PROJECTOR_SECOND_BACKWARD = 'v';
|
const char PROJECTOR_SECOND_BACKWARD = 'v';
|
||||||
static const char PROJECTOR_SECOND_FORWARD = 'u';
|
const char PROJECTOR_SECOND_FORWARD = 'u';
|
||||||
static const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
const char PROJECTOR_SECOND_IDENTIFIER = 't';
|
||||||
static const char PROJECTORS = 'x';
|
const char PROJECTORS = 'x';
|
||||||
static const char PROJECTORS_IDENTIFIER = 'd';
|
const char PROJECTORS_IDENTIFIER = 'd';
|
||||||
static const char STATE = 'H';
|
const char STATE = 'H';
|
||||||
static const char TAKEUP_BACKWARD = 'F';
|
const char TAKEUP_BACKWARD = 'F';
|
||||||
static const char TAKEUP_FORWARD = 'D';
|
const char TAKEUP_FORWARD = 'D';
|
||||||
/* END CMD FLAGS */
|
/* END CMD FLAGS */
|
||||||
|
|
||||||
McopySerial(char identity);
|
McopySerial();
|
||||||
|
|
||||||
void begin();
|
void begin(char identity);
|
||||||
void setBaud(int baudRate);
|
|
||||||
void setIdentity(char identity);
|
|
||||||
char loop();
|
char loop();
|
||||||
void confirm(char cmd);
|
void confirm(char cmd);
|
||||||
String getString();
|
String getString();
|
||||||
|
|
|
@ -8,7 +8,7 @@ if [ -f "$(which jq)" ]; then
|
||||||
|
|
||||||
awk '{print} /CMD FLAGS/ {exit}' "${HEADER}" > "${TMP_FILE}"
|
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}"
|
awk '/END CMD/,EOF { print $0 }' "${HEADER}" >> "${TMP_FILE}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue