UDP-Pakete akzeptieren für komplette Bilder und für VU-Meter

This commit is contained in:
starcalc 2017-07-07 00:20:36 +02:00
parent 5c0f6b1061
commit 12d8c14cc1
1 changed files with 6 additions and 36 deletions

View File

@ -55,38 +55,6 @@ bool onSetPixel(const HomieRange& range, const String& value) {
homieNode.setProperty("pixel_" + String(range.index)).send(value);
}
bool onSetVU(const HomieRange& range, const String& value) {
strip.Stop(); // Do not show any "effects" anymore
strip.clear(); // All pixels to black
String remaining = value;
String current;
int i = 0;
do
{
if (remaining.length() == 1)
{
current = remaining.substring(0,1);
} else {
current = remaining.substring(0,2);
}
int currentvalue = (int) strtol(&current[0], NULL, 10);
// White peak
strip.setPixelColor(strip.numToPos(56+i-currentvalue*8), 16777215); // White dot
// Shaded bar "below" the peak
if (currentvalue>0)
{
for (int j=currentvalue-1;j>-1;j--)
{
strip.setPixelColor(strip.numToPos(56+i-j*8), 4276545); // Greyscale
}
}
i++;
remaining = remaining.substring(2);
} while (remaining.length()>0); // TODO: Not bigger than strip
strip.show();
homieNode.setProperty("VU_" + String(range.index)).send(value);
}
bool onSetBrightness(const HomieRange& range, const String& value) {
long brightness = value.toInt();
if (brightness < 0 || brightness > 255) {
@ -219,7 +187,7 @@ void loopHandler() {
void setup() {
Serial.begin(115200);
Homie_setFirmware("pixelbox", "1.0.0");
Homie_setFirmware("pixelprojektor", "1.0.0");
Homie.setLoopFunction(loopHandler);
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
@ -230,19 +198,19 @@ void setup() {
homieNode.advertise("length").settable(onSetLength);
homieNode.advertise("icon").settable(onSetIcon);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels);
homieNode.advertiseRange("vu", 0, sqrt(NUMPIXELS)-1).settable(onSetVU);
Homie.setup();
strip.begin();
strip.clear();
// strip.setBrightness(64);
strip.setBrightness(255); // HEEELLLLLLL :)
// strip.setBrightness(255); // HEEELLLLLLL :)
strip.setBrightness(10); // DEBUG!
strip.show();
stopAfterCompletion = false; // Default
// strip.Plasma(); // Default effect
ArduinoOTA.setHostname("pixelbox");
ArduinoOTA.setHostname("pixelprojektor");
ArduinoOTA.onStart([]() {
strip.clear();
strip.setBrightness(64);
@ -261,3 +229,5 @@ void loop() {
Homie.loop();
ArduinoOTA.handle();
}