2023-04-11 04:38:06 +00:00
|
|
|
/// mcopy Serial Library
|
|
|
|
|
|
|
|
#include "McopySerial.h"
|
|
|
|
|
|
|
|
McopySerial::McopySerial () {}
|
|
|
|
|
|
|
|
void McopySerial::begin (char identity) {
|
|
|
|
id = identity;
|
|
|
|
Serial.begin(baud);
|
|
|
|
Serial.flush();
|
|
|
|
Serial.setTimeout(serialDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
char McopySerial::loop () {
|
|
|
|
if (Serial.available()) {
|
|
|
|
cmdChar = (char) Serial.read();
|
|
|
|
_internal();
|
|
|
|
} else {
|
|
|
|
cmdChar = 'z';
|
|
|
|
}
|
|
|
|
return cmdChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::_internal () {
|
|
|
|
if (cmdChar == DEBUG) {
|
|
|
|
debug(!debugOn);
|
|
|
|
} else if (cmdChar == CONNECT) {
|
|
|
|
_connect();
|
|
|
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
|
|
|
_identify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::_connect () {
|
2023-04-21 02:37:37 +00:00
|
|
|
connected = true;
|
2023-04-11 04:38:06 +00:00
|
|
|
Serial.println(CONNECT);
|
|
|
|
log("connect()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::_identify () {
|
2023-04-21 02:37:37 +00:00
|
|
|
identified = true;
|
2023-04-11 04:38:06 +00:00
|
|
|
Serial.println(id);
|
|
|
|
log("identify()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::debug (bool state) {
|
|
|
|
debugOn = state;
|
|
|
|
log("debug()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::confirm (char cmd) {
|
|
|
|
Serial.println(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::log (String message) {
|
|
|
|
if (debugOn) {
|
|
|
|
Serial.println(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String McopySerial::getString () {
|
|
|
|
while (Serial.available() == 0) {
|
|
|
|
//Wait for value string
|
|
|
|
}
|
|
|
|
return Serial.readString();
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:40:56 +00:00
|
|
|
void McopySerial::sendString (String str) {
|
|
|
|
Serial.println(str);
|
|
|
|
}
|
|
|
|
|
2023-04-11 04:38:06 +00:00
|
|
|
void McopySerial::print (String message) {
|
|
|
|
Serial.println(message);
|
|
|
|
}
|