2023-03-09 02:28:09 +00:00
|
|
|
/// mcopy Serial Library
|
|
|
|
|
2023-03-05 00:04:55 +00:00
|
|
|
#include "McopySerial.h"
|
2023-03-04 23:52:51 +00:00
|
|
|
|
2023-03-22 00:35:00 +00:00
|
|
|
McopySerial::McopySerial () {}
|
2023-03-04 23:52:51 +00:00
|
|
|
|
2023-03-22 00:35:00 +00:00
|
|
|
void McopySerial::begin (char identity) {
|
|
|
|
id = identity;
|
2023-03-05 00:25:50 +00:00
|
|
|
Serial.begin(baud);
|
2023-03-10 02:51:29 +00:00
|
|
|
Serial.flush();
|
2023-03-20 23:45:32 +00:00
|
|
|
Serial.setTimeout(serialDelay);
|
2023-03-05 00:25:50 +00:00
|
|
|
}
|
2023-03-04 23:52:51 +00:00
|
|
|
|
2023-03-10 02:01:20 +00:00
|
|
|
char McopySerial::loop () {
|
2023-03-09 02:28:09 +00:00
|
|
|
if (Serial.available()) {
|
|
|
|
cmdChar = (char) Serial.read();
|
2023-03-10 02:26:31 +00:00
|
|
|
_internal();
|
2023-03-10 02:01:20 +00:00
|
|
|
} else {
|
2023-03-09 02:28:09 +00:00
|
|
|
cmdChar = 'z';
|
|
|
|
}
|
2023-03-10 02:01:20 +00:00
|
|
|
return cmdChar;
|
2023-03-09 02:28:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 02:26:31 +00:00
|
|
|
void McopySerial::_internal () {
|
2023-03-10 02:08:36 +00:00
|
|
|
if (cmdChar == DEBUG) {
|
2023-03-22 00:35:00 +00:00
|
|
|
debug(!debugOn);
|
2023-03-10 02:26:31 +00:00
|
|
|
} else if (cmdChar == CONNECT) {
|
|
|
|
_connect();
|
|
|
|
} else if (cmdChar == MCOPY_IDENTIFIER) {
|
|
|
|
_identify();
|
2023-03-10 02:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 02:26:31 +00:00
|
|
|
void McopySerial::_connect () {
|
|
|
|
Serial.println(CONNECT);
|
|
|
|
log("connect()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::_identify () {
|
|
|
|
Serial.println(id);
|
|
|
|
log("identify()");
|
|
|
|
}
|
|
|
|
|
2023-03-04 23:52:51 +00:00
|
|
|
void McopySerial::debug (bool state) {
|
|
|
|
debugOn = state;
|
2023-03-22 00:35:00 +00:00
|
|
|
log("debug()");
|
2023-03-04 23:52:51 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 02:51:29 +00:00
|
|
|
void McopySerial::confirm (char cmd) {
|
|
|
|
Serial.println(cmd);
|
|
|
|
}
|
|
|
|
|
2023-03-04 23:52:51 +00:00
|
|
|
void McopySerial::log (String message) {
|
|
|
|
if (debugOn) {
|
|
|
|
Serial.println(message);
|
|
|
|
}
|
2023-03-18 21:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String McopySerial::getString () {
|
|
|
|
while (Serial.available() == 0) {
|
|
|
|
//Wait for value string
|
|
|
|
}
|
|
|
|
return Serial.readString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::print (String message) {
|
|
|
|
Serial.println(message);
|
2023-03-04 23:52:51 +00:00
|
|
|
}
|