#if IR #include #include #include #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); bool avrOn = false; uint8_t readCommand() { uint8_t lastCommand = 0; decode_results results; 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; } irrecv.resume(); // Receive the next value } return lastCommand; } void command(const char c[]) { avrOn = true; tCheckWifi.cancel(); Wifi::reconnect(); Display::displayText(c); } void loop() { if (uint8_t lastCommand = readCommand()) { switch (lastCommand) { case 0x9F: avrOn = false; tCheckWifi.restartDelayed(); Display::displayText("Off"); Mqtt::commands.push(lastCommand); break; case 0x12: Display::displayText("Slp"); Mqtt::commands.push(lastCommand); break; case 0xC1: Display::displayText("Mute"); Mqtt::commands.push(lastCommand); break; case 0xC4: command("Play"); Mqtt::commands.push(lastCommand); break; case 0xC7: avrOn ? Display::displayText(" Up") : Display::changeBrightness(true); break; case 0xC8: avrOn ? Display::displayText(" Dn") : Display::changeBrightness(false); break; case 0xD0: command("Stop"); Mqtt::commands.push(lastCommand); break; case 0xC0: command("On"); Mqtt::commands.push(lastCommand); break; case 0x84: Display::displayTemp(Bmp::data.readTemp()); break; default: Display::displayValue(lastCommand); Mqtt::commands.push(lastCommand); break; } } } void setup() { irrecv.enableIRIn(); // Start the receiver } } #else namespace Ir { bool avrOn = false; void setup() {} void loop() {} } #endif