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-05 00:25:50 +00:00
|
|
|
McopySerial::McopySerial () {
|
2023-03-10 02:01:20 +00:00
|
|
|
//create mcopy serial
|
2023-03-04 23:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::begin () {
|
2023-03-05 00:25:50 +00:00
|
|
|
Serial.begin(baud);
|
|
|
|
}
|
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:08:36 +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:08:36 +00:00
|
|
|
void McopySerial::internal () {
|
|
|
|
if (cmdChar == DEBUG) {
|
|
|
|
debugOn = !debugOn;
|
|
|
|
cmdChar = 'z';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-05 00:25:50 +00:00
|
|
|
void McopySerial::setBaud (int baudRate) {
|
|
|
|
baud = baudRate;
|
2023-03-04 23:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::debug (bool state) {
|
|
|
|
debugOn = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void McopySerial::log (String message) {
|
|
|
|
if (debugOn) {
|
|
|
|
Serial.println(message);
|
|
|
|
}
|
|
|
|
}
|