switch back to returning pointer in findProtocol - only this works with derived classes
This commit is contained in:
parent
f668beeca2
commit
c2395e8bde
@ -31,16 +31,16 @@ void setup() {
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Protocol& findProtocol(unsigned int protocol) {
|
Protocol* findProtocol(unsigned int protocol) {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case PROTOCOL_1:
|
case PROTOCOL_1:
|
||||||
return protocol1;
|
return &protocol1;
|
||||||
case PROTOCOL_2:
|
case PROTOCOL_2:
|
||||||
return protocol2;
|
return &protocol2;
|
||||||
case PROTOCOL_13:
|
case PROTOCOL_13:
|
||||||
return doorbell;
|
return &doorbell;
|
||||||
default:
|
default:
|
||||||
return fallbackProtocol.setProtocol(protocol);
|
return &fallbackProtocol.setProtocol(protocol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ void readRcSwitch() {
|
|||||||
|
|
||||||
StaticJsonDocument<128> jsonDoc;
|
StaticJsonDocument<128> jsonDoc;
|
||||||
auto p = findProtocol(mySwitch.getReceivedProtocol());
|
auto p = findProtocol(mySwitch.getReceivedProtocol());
|
||||||
p.toJson(value, jsonDoc);
|
p->toJson(value, jsonDoc);
|
||||||
if (!jsonDoc.isNull()) {
|
if (!jsonDoc.isNull()) {
|
||||||
serializeJson(jsonDoc, Serial);
|
serializeJson(jsonDoc, Serial);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@ -84,7 +84,7 @@ void runJsonCommand(char* cmd) {
|
|||||||
if (jsonDoc.containsKey("rcSwitch")) {
|
if (jsonDoc.containsKey("rcSwitch")) {
|
||||||
JsonObjectConst rcSwitch = jsonDoc["rcSwitch"];
|
JsonObjectConst rcSwitch = jsonDoc["rcSwitch"];
|
||||||
auto p = findProtocol(rcSwitch["protocol"]);
|
auto p = findProtocol(rcSwitch["protocol"]);
|
||||||
p.fromJson(rcSwitch, mySwitch);
|
p->fromJson(rcSwitch, mySwitch);
|
||||||
serializeJson(jsonDoc, Serial);
|
serializeJson(jsonDoc, Serial);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Board::publishResponse(jsonDoc);
|
Board::publishResponse(jsonDoc);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user