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