Next/Prev/Brighter/Darker/Toggle als Commandos akzeptiert

This commit is contained in:
starcalc 2019-07-18 20:09:16 +02:00
parent 9e98c886f7
commit 8faa7c7f1c
1 changed files with 46 additions and 9 deletions

View File

@ -35,6 +35,7 @@ int pass = 0;
bool stopAfterCompletion;
int effect = 0;
int curBrightness = 255;
void StripComplete() {
if (stopAfterCompletion)
@ -112,6 +113,12 @@ bool onSetVU(const HomieRange& range, const String& value) {
bool onSetBrightness(const HomieRange& range, const String& value) {
long brightness = value.toInt();
setBrightness(brightness);
homieNode.setProperty("brightness").send(value);
curBrightness = brightness;
}
bool setBrightness(long brightness) {
if (brightness < 0 || brightness > 255) {
return false;
}
@ -119,7 +126,6 @@ bool onSetBrightness(const HomieRange& range, const String& value) {
matrix.setBrightness(brightness);
strip.show();
matrix.show();
homieNode.setProperty("brightness").send(value);
}
bool onSetPixels(const HomieRange& range, const String& value) {
@ -285,7 +291,15 @@ void loopHandler() {
matrix.Update();
}
bool onSetNext(const HomieRange& range, const String& value) {
bool NextPrev(bool next=false) {
if (next) {
effect++;
if (effect>10) { effect=0; }
} else {
effect--;
if (effect<0) { effect=10; }
}
switch (effect)
{
case 0:
@ -333,15 +347,36 @@ bool onSetNext(const HomieRange& range, const String& value) {
matrix.ScrollText("CTDO");
break;
}
effect++;
if (effect>10) { effect=0; }
homieNode.setProperty("next").send(value);
}
bool onSetCommand(const HomieRange& range, const String& value) {
if (value == "next")
{
NextPrev(true);
} else if (value == "prev") {
NextPrev(false);
} else if (value == "darker") {
curBrightness -= 40;
if (curBrightness < 0) { curBrightness = 0; }
setBrightness(curBrightness);
} else if (value == "brighter") {
curBrightness += 40;
if (curBrightness > 255) { curBrightness = 255; }
setBrightness(curBrightness);
} else if (value == "toggle") {
if (curBrightness>0) { curBrightness = 0; } else { curBrightness = 255; }
setBrightness(curBrightness);
}
homieNode.setProperty("command").send(value);
}
void setup() {
Serial.begin(115200);
Homie_setFirmware("pixelboxtest", "1.1.0");
Homie_setFirmware("pixelbox", "1.2.0");
Homie.setLoopFunction(loopHandler);
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
@ -351,7 +386,7 @@ void setup() {
homieNode.advertise("clear").settable(onSetClear);
homieNode.advertise("length").settable(onSetLength);
homieNode.advertise("icon").settable(onSetIcon);
homieNode.advertise("next").settable(onSetNext);
homieNode.advertise("command").settable(onSetCommand);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels);
homieNode.advertiseRange("vu", 0, sqrt(NUMPIXELS)-1).settable(onSetVU);
@ -362,12 +397,11 @@ void setup() {
// strip.setBrightness(10); // DEBUG!
strip.show();
stopAfterCompletion = false; // Default
strip.Plasma(); // Default effect
effect = 0;
Homie.setup();
ArduinoOTA.setHostname("pixelboxtest");
ArduinoOTA.setHostname("pixelbox");
ArduinoOTA.onStart([]() {
strip.clear();
strip.setBrightness(64);
@ -383,6 +417,9 @@ void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
strip.Plasma(); // Default effect
}
void loop() {