esp-wemos-audioswitcher/firmware_esp/firmware_esp.ino

68 lines
1.3 KiB
C++

#include <Homie.h>
#include <ArduinoOTA.h>
long lastTickMillis;
HomieNode volumeNode("volume", "volume");
HomieNode switchNode("switches", "switch");
bool nodeInputHandlerVolume(const HomieRange& range, const String& value) {
Homie.getLogger() << "VOL " << range.index << " set to " << value << endl;
int r = value.toInt();
if(r >= 0 && r <= 127) {
volumeNode.setProperty("output").setRange(range).send(value);
return true;
}
return false;
}
bool nodeInputHandlerVolume(const HomieRange& range, const String& value) {
Homie.getLogger() << "VOL " << range.index << " set to " << value << endl;
switchNode.setProperty("switch").setRange(range).send(value);
return true;
}
void setup() {
Serial.begin(115200);
Serial << endl << endl;
Homie_setFirmware("audiocontroller", "1.0.0");
volumeNode.advertiseRange("volume", 1, 4).settable(nodeInputHandlerVolume);
switchNode.advertiseRange("switch", 1, 4).settable(nodeInputHandlerVolume);
Homie.setup();
Homie.getLogger() << "started" << endl;
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
ArduinoOTA.begin();
}
void loop() {
Homie.loop();
ArduinoOTA.handle();
long currentMillis = millis();
if(currentMillis - lastTickMillis >= 100) {
lastTickMillis = currentMillis;
}
}