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"
|
#include "wifi.h"
|
||||||
|
|
||||||
namespace Board {
|
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) {
|
void turnOffLed(uint8_t led) {
|
||||||
digitalWrite(led, HIGH);
|
digitalWrite(led, HIGH);
|
||||||
}
|
}
|
||||||
@ -21,6 +29,7 @@ namespace Board {
|
|||||||
// turnOffLed(BLUE_LED);
|
// turnOffLed(BLUE_LED);
|
||||||
Wifi::setup();
|
Wifi::setup();
|
||||||
Ota::setup();
|
Ota::setup();
|
||||||
|
tReadCommand.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#include <SerialReader.h>
|
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
|
||||||
#define RESET_PIN 10
|
#define RESET_PIN 10
|
||||||
@ -6,12 +5,10 @@
|
|||||||
#define RECEIVE_PIN 2
|
#define RECEIVE_PIN 2
|
||||||
|
|
||||||
namespace Board {
|
namespace Board {
|
||||||
SerialReader<200> serialReader;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
Serial.begin(9600);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void readCommand() {
|
void readCommand() {
|
||||||
@ -32,12 +29,8 @@ namespace Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void publishResponse(JsonDocument& jsonDoc) {
|
void publishResponse(JsonDocument& jsonDoc) {
|
||||||
serializeJson(jsonDoc, Serial);
|
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleJsonError(JsonDocument& jsonError) {
|
void handleJsonError(JsonDocument& jsonError) {
|
||||||
serializeJson(jsonError, Serial);
|
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
#include <SerialReader.h>
|
||||||
#include "Dht.h"
|
#include "Dht.h"
|
||||||
#include "Protocol_1.h"
|
#include "Protocol_1.h"
|
||||||
#include "Protocol_2.h"
|
#include "Protocol_2.h"
|
||||||
|
|
||||||
RCSwitch mySwitch;
|
RCSwitch mySwitch;
|
||||||
|
SerialReader<200> serialReader;
|
||||||
void runJsonCommand(char* cmd);
|
void runJsonCommand(char* cmd);
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -19,6 +21,8 @@ void setup() {
|
|||||||
mySwitch.enableTransmit(SEND_PIN);
|
mySwitch.enableTransmit(SEND_PIN);
|
||||||
mySwitch.setRepeatTransmit(10);
|
mySwitch.setRepeatTransmit(10);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
Dht::setup();
|
Dht::setup();
|
||||||
Board::setup();
|
Board::setup();
|
||||||
|
|
||||||
@ -52,6 +56,8 @@ void readRcSwitch() {
|
|||||||
p->toJson(value, jsonDoc);
|
p->toJson(value, jsonDoc);
|
||||||
delete p;
|
delete p;
|
||||||
if (!jsonDoc.isNull()) {
|
if (!jsonDoc.isNull()) {
|
||||||
|
serializeJson(jsonDoc, Serial);
|
||||||
|
Serial.println();
|
||||||
Board::publishResponse(jsonDoc);
|
Board::publishResponse(jsonDoc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -63,6 +69,8 @@ void handleJsonError(DeserializationError err, const char* cmd) {
|
|||||||
JsonObject error = jsonError.createNestedObject("error");
|
JsonObject error = jsonError.createNestedObject("error");
|
||||||
error["msg"] = err.c_str();
|
error["msg"] = err.c_str();
|
||||||
error["orig_cmd"] = cmd;
|
error["orig_cmd"] = cmd;
|
||||||
|
serializeJson(jsonError, Serial);
|
||||||
|
Serial.println();
|
||||||
Board::handleJsonError(jsonError);
|
Board::handleJsonError(jsonError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +83,8 @@ void runJsonCommand(char* cmd) {
|
|||||||
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
||||||
p->fromJson(rcSwitch, mySwitch);
|
p->fromJson(rcSwitch, mySwitch);
|
||||||
delete p;
|
delete p;
|
||||||
|
serializeJson(jsonDoc, Serial);
|
||||||
|
Serial.println();
|
||||||
Board::publishResponse(jsonDoc);
|
Board::publishResponse(jsonDoc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -83,7 +93,7 @@ void runJsonCommand(char* cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Board::loop();
|
|
||||||
readRcSwitch();
|
readRcSwitch();
|
||||||
|
Board::loop();
|
||||||
Dht::read();
|
Dht::read();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user