106 lines
2.6 KiB
C++
106 lines
2.6 KiB
C++
#if IR
|
|
|
|
#include <AsyncMqttClient.h>
|
|
#include <IRremoteESP8266.h>
|
|
#include <IRrecv.h>
|
|
#include "display.h"
|
|
|
|
#define IR_INPUT_PIN D6
|
|
|
|
#define MQTT_HOST IPAddress(192, 168, 5, 138)
|
|
#define MQTT_PORT 1883
|
|
|
|
namespace Ir {
|
|
|
|
void loop();
|
|
Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true);
|
|
|
|
IRrecv irrecv(IR_INPUT_PIN);
|
|
decode_results results;
|
|
bool avrOn = false;
|
|
|
|
uint8_t lastCommand = 0x9F;
|
|
|
|
bool readCommand() {
|
|
bool newCommand = false;
|
|
if (irrecv.decode(&results)) {
|
|
if (results.decode_type == NEC && results.command != 0) {
|
|
Serial.print(F(" C=0x"));
|
|
Serial.print(results.command, HEX);
|
|
Serial.println();
|
|
lastCommand = results.command;
|
|
Mqtt::commands.push(results.command);
|
|
newCommand = true;
|
|
}
|
|
irrecv.resume(); // Receive the next value
|
|
}
|
|
return newCommand;
|
|
}
|
|
|
|
void command(const char c[]) {
|
|
avrOn = true;
|
|
Wifi::reconnect();
|
|
Display::displayText(c);
|
|
}
|
|
|
|
void loop() {
|
|
if (readCommand()) {
|
|
switch (lastCommand)
|
|
{
|
|
case 0x9F:
|
|
avrOn = false;
|
|
tCheckWifi.enable();
|
|
Display::displayText("Off");
|
|
break;
|
|
case 0x12:
|
|
command("Slp");
|
|
break;
|
|
case 0xC4:
|
|
command("Play");
|
|
break;
|
|
case 0xD0:
|
|
command("Fire");
|
|
break;
|
|
case 0xC0:
|
|
avrOn = true;
|
|
Wifi::reconnect();
|
|
Display::displayFloat(Bmp::bmp.readTemperature());
|
|
break;
|
|
default:
|
|
Display::displayValue(lastCommand);
|
|
break;
|
|
}
|
|
}
|
|
if (Mqtt::commands.getCurrent() == 0xC7) {
|
|
if (!avrOn) {
|
|
Display::displayText("B Up");
|
|
Display::changeBrightness(true);
|
|
} else {
|
|
Display::displayText(" Up");
|
|
}
|
|
Mqtt::commands.pop();
|
|
}
|
|
if (Mqtt::commands.getCurrent() == 0xC8) {
|
|
if (!avrOn) {
|
|
Display::displayText("B Dn");
|
|
Display::changeBrightness(false);
|
|
} else {
|
|
Display::displayText(" Dn");
|
|
}
|
|
Mqtt::commands.pop();
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
irrecv.enableIRIn(); // Start the receiver
|
|
}
|
|
}
|
|
|
|
#else
|
|
namespace Ir {
|
|
bool avrOn = false;
|
|
|
|
void setup() {}
|
|
void loop() {}
|
|
}
|
|
#endif |