keep serial logic common
RX pin does not work as RC recevier for huzzah
This commit is contained in:
parent
6a2450d94f
commit
14a984195f
@ -10,6 +10,14 @@ Scheduler ts;
|
||||
#include "wifi.h"
|
||||
|
||||
namespace Board {
|
||||
|
||||
Task tReadCommand(TASK_IMMEDIATE, TASK_FOREVER, [](){
|
||||
if (serialReader.readLine(Serial) > 0) {
|
||||
char* cmd = serialReader.getBuffer();
|
||||
runJsonCommand(cmd);
|
||||
}
|
||||
}, &ts);
|
||||
|
||||
void turnOffLed(uint8_t led) {
|
||||
digitalWrite(led, HIGH);
|
||||
}
|
||||
@ -21,6 +29,7 @@ namespace Board {
|
||||
// turnOffLed(BLUE_LED);
|
||||
Wifi::setup();
|
||||
Ota::setup();
|
||||
tReadCommand.enable();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#include <SerialReader.h>
|
||||
#include "output.h"
|
||||
|
||||
#define RESET_PIN 10
|
||||
@ -6,12 +5,10 @@
|
||||
#define RECEIVE_PIN 2
|
||||
|
||||
namespace Board {
|
||||
SerialReader<200> serialReader;
|
||||
|
||||
void setup() {
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void readCommand() {
|
||||
@ -32,12 +29,8 @@ namespace Board {
|
||||
}
|
||||
|
||||
void publishResponse(JsonDocument& jsonDoc) {
|
||||
serializeJson(jsonDoc, Serial);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void handleJsonError(JsonDocument& jsonError) {
|
||||
serializeJson(jsonError, Serial);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
#include <Arduino.h>
|
||||
#include <RCSwitch.h>
|
||||
#include <SerialReader.h>
|
||||
#include "Dht.h"
|
||||
#include "Protocol_1.h"
|
||||
#include "Protocol_2.h"
|
||||
|
||||
RCSwitch mySwitch;
|
||||
SerialReader<200> serialReader;
|
||||
void runJsonCommand(char* cmd);
|
||||
|
||||
#if defined(ESP8266)
|
||||
@ -19,6 +21,8 @@ void setup() {
|
||||
mySwitch.enableTransmit(SEND_PIN);
|
||||
mySwitch.setRepeatTransmit(10);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
Dht::setup();
|
||||
Board::setup();
|
||||
|
||||
@ -52,6 +56,8 @@ void readRcSwitch() {
|
||||
p->toJson(value, jsonDoc);
|
||||
delete p;
|
||||
if (!jsonDoc.isNull()) {
|
||||
serializeJson(jsonDoc, Serial);
|
||||
Serial.println();
|
||||
Board::publishResponse(jsonDoc);
|
||||
}
|
||||
#endif
|
||||
@ -63,6 +69,8 @@ void handleJsonError(DeserializationError err, const char* cmd) {
|
||||
JsonObject error = jsonError.createNestedObject("error");
|
||||
error["msg"] = err.c_str();
|
||||
error["orig_cmd"] = cmd;
|
||||
serializeJson(jsonError, Serial);
|
||||
Serial.println();
|
||||
Board::handleJsonError(jsonError);
|
||||
}
|
||||
|
||||
@ -75,6 +83,8 @@ void runJsonCommand(char* cmd) {
|
||||
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
||||
p->fromJson(rcSwitch, mySwitch);
|
||||
delete p;
|
||||
serializeJson(jsonDoc, Serial);
|
||||
Serial.println();
|
||||
Board::publishResponse(jsonDoc);
|
||||
}
|
||||
} else {
|
||||
@ -83,7 +93,7 @@ void runJsonCommand(char* cmd) {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Board::loop();
|
||||
readRcSwitch();
|
||||
Board::loop();
|
||||
Dht::read();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user