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