encapsulate commands into struct
This commit is contained in:
parent
167606a19e
commit
cafe4ec84f
@ -56,11 +56,11 @@ namespace Ir {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!avrOn && Mqtt::getCurrentCommand() == 0xC7) {
|
if (!avrOn && Mqtt::commands.getCurrent() == 0xC7) {
|
||||||
Display::changeBrightness(true);
|
Display::changeBrightness(true);
|
||||||
Mqtt::commands.pop();
|
Mqtt::commands.pop();
|
||||||
}
|
}
|
||||||
if (!avrOn && Mqtt::getCurrentCommand() == 0xC8) {
|
if (!avrOn && Mqtt::commands.getCurrent() == 0xC8) {
|
||||||
Display::changeBrightness(false);
|
Display::changeBrightness(false);
|
||||||
Mqtt::commands.pop();
|
Mqtt::commands.pop();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,24 +11,36 @@ namespace Mqtt {
|
|||||||
|
|
||||||
AsyncMqttClient client;
|
AsyncMqttClient client;
|
||||||
|
|
||||||
std::queue<uint8_t> commands;
|
struct {
|
||||||
|
const char* topic = "esp_clock/sensor/ir/value";
|
||||||
|
std::queue<uint8_t> list;
|
||||||
|
uint8_t getCurrent() {
|
||||||
|
return list.empty() ? 0 : list.front();
|
||||||
|
}
|
||||||
|
void push(uint8_t el) {
|
||||||
|
list.push(el);
|
||||||
|
}
|
||||||
|
void pop() {
|
||||||
|
list.pop();
|
||||||
|
}
|
||||||
|
uint8_t front() {
|
||||||
|
return list.front();
|
||||||
|
}
|
||||||
|
} commands;
|
||||||
|
|
||||||
void publishCommand() {
|
void publishCommand() {
|
||||||
if (!commands.empty() && client.connected()) {
|
if (!commands.list.empty() && client.connected()) {
|
||||||
char message[32];
|
char message[32];
|
||||||
sprintf(message, "%X", commands.front());
|
uint8_t cmd = commands.front();
|
||||||
if (client.publish("esp_clock/sensor/ir/value", 0, true, message) != 0) {
|
sprintf(message, "%X", cmd);
|
||||||
Serial.print(commands.front(), HEX);
|
if (client.publish(commands.topic, 0, true, message) != 0) {
|
||||||
|
Serial.print(cmd, HEX);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
commands.pop();
|
commands.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getCurrentCommand() {
|
|
||||||
return commands.empty() ? 0 : commands.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
client.onConnect([](bool sessionPresent) {
|
client.onConnect([](bool sessionPresent) {
|
||||||
tPublish.enableDelayed();
|
tPublish.enableDelayed();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user