From b6059939b48fbe50d8430f20960f7746e5e86210 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 3 Jan 2022 22:23:03 +0100 Subject: [PATCH] Bugfix for applying WIN API in JSON request. Added preset cycling in rotary encoder. Removed custom font from 4LD in favor of built-in. --- .../usermod_v2_four_line_display_ALT.h | 141 +++++++++++------ .../usermod_v2_rotary_encoder_ui_ALT.h | 149 +++++++++--------- wled00/presets.cpp | 17 +- wled00/wled.h | 2 +- 4 files changed, 177 insertions(+), 132 deletions(-) diff --git a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h index ca17af36f..b0c6d9489 100644 --- a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h +++ b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h @@ -115,11 +115,11 @@ typedef enum { Glyphs: 1/1 BBX Build Mode: 3 * 4 = custom palette -*/ +* / const uint8_t u8x8_font_benji_custom_icons_1x1[13] U8X8_FONT_SECTION("u8x8_font_benji_custom_icons_1x1") = "\4\4\1\1 0 && !powerON)) { //trigger power icon - powerON = !powerON; - drawStatusIcons(); - return; + powerON = !powerON; + drawStatusIcons(); + return; } else if (knownnightlight != nightlightActive) { //trigger moon icon - knownnightlight = nightlightActive; - drawStatusIcons(); - if (knownnightlight) { - String timer = PSTR("Timer On"); - center(timer,LINE_BUFFER_SIZE-1); - overlay(timer.c_str(), 3000, 6); - lastRedraw = millis(); - } - return; + knownnightlight = nightlightActive; + drawStatusIcons(); + if (knownnightlight) { + String timer = PSTR("Timer On"); + center(timer,LINE_BUFFER_SIZE-1); + overlay(timer.c_str(), 3000, 6); + lastRedraw = millis(); + } + return; } else if (wificonnected != interfacesInited) { //trigger wifi icon - wificonnected = interfacesInited; - drawStatusIcons(); - return; + wificonnected = interfacesInited; + drawStatusIcons(); + return; } else if (knownMode != effectCurrent) { - knownMode = effectCurrent; - if (displayTurnedOff) needRedraw = true; - else { showCurrentEffectOrPalette(knownMode, JSON_mode_names, 3); return; } + knownMode = effectCurrent; + if (displayTurnedOff) needRedraw = true; + else { showCurrentEffectOrPalette(knownMode, JSON_mode_names, 3); return; } } else if (knownPalette != effectPalette) { - knownPalette = effectPalette; - if (displayTurnedOff) needRedraw = true; - else { showCurrentEffectOrPalette(knownPalette, JSON_palette_names, 2); return; } + knownPalette = effectPalette; + if (displayTurnedOff) needRedraw = true; + else { showCurrentEffectOrPalette(knownPalette, JSON_palette_names, 2); return; } } else if (knownBrightness != bri) { - if (displayTurnedOff && nightlightActive) { needRedraw = false; knownBrightness = bri; } - else if (displayTurnedOff) needRedraw = true; - else { updateBrightness(); return; } + if (displayTurnedOff && nightlightActive) { needRedraw = false; knownBrightness = bri; } + else if (displayTurnedOff) needRedraw = true; + else { updateBrightness(); return; } } else if (knownEffectSpeed != effectSpeed) { - if (displayTurnedOff) needRedraw = true; - else { updateSpeed(); return; } + if (displayTurnedOff) needRedraw = true; + else { updateSpeed(); return; } } else if (knownEffectIntensity != effectIntensity) { - if (displayTurnedOff) needRedraw = true; - else { updateIntensity(); return; } + if (displayTurnedOff) needRedraw = true; + else { updateIntensity(); return; } } if (!needRedraw) { @@ -606,17 +606,17 @@ class FourLineDisplayUsermod : public Usermod { void draw2x2GlyphIcons() { if (lineHeight == 2) { - drawGlyph(1, 0, 1, u8x8_font_benji_custom_icons_2x2, true);//brightness icon - drawGlyph(5, 0, 2, u8x8_font_benji_custom_icons_2x2, true);//speed icon - drawGlyph(9, 0, 3, u8x8_font_benji_custom_icons_2x2, true);//intensity icon - drawGlyph(14, 2*lineHeight, 4, u8x8_font_benji_custom_icons_2x2, true);//palette icon - drawGlyph(14, 3*lineHeight, 5, u8x8_font_benji_custom_icons_2x2, true);//effect icon + drawGlyph( 1, 0, 0x45, u8x8_font_open_iconic_weather_2x2, true); //brightness icon + drawGlyph( 5, 0, 0x48, u8x8_font_open_iconic_play_2x2, true); //speed icon + drawGlyph( 9, 0, 0x4e, u8x8_font_open_iconic_thing_2x2, true); //intensity icon + drawGlyph(14, 2*lineHeight, 0x48, u8x8_font_open_iconic_thing_2x2, true); //palette icon + drawGlyph(14, 3*lineHeight, 0x46, u8x8_font_open_iconic_thing_2x2, true); //effect icon } else { - drawGlyph(2, 0, 69, u8x8_font_open_iconic_weather_1x1); //brightness icon - drawGlyph(6, 0, 72, u8x8_font_open_iconic_play_1x1); //speed icon - drawGlyph(10, 0, 78, u8x8_font_open_iconic_thing_1x1); //intensity icon - drawGlyph(15, 2*lineHeight, 4, u8x8_font_benji_custom_icons_1x1); //palette icon - drawGlyph(15, 3*lineHeight, 70, u8x8_font_open_iconic_thing_1x1); //effect icon + drawGlyph( 2, 0, 0x45, u8x8_font_open_iconic_weather_1x1); //brightness icon + drawGlyph( 6, 0, 0x48, u8x8_font_open_iconic_play_1x1); //speed icon + drawGlyph(10, 0, 0x4e, u8x8_font_open_iconic_thing_1x1); //intensity icon + drawGlyph(15, 2*lineHeight, 0x48, u8x8_font_open_iconic_thing_1x1); //palette icon + drawGlyph(15, 3*lineHeight, 0x46, u8x8_font_open_iconic_thing_1x1); //effect icon } } @@ -724,12 +724,49 @@ class FourLineDisplayUsermod : public Usermod { // Turn the display back on if (!wakeDisplay()) clear(); // Print the overlay - if (glyphType > 0) { - if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_font_benji_custom_icons_6x6, true); - else drawGlyph(7, lineHeight, glyphType, u8x8_font_benji_custom_icons_2x2, true); - if (line1) drawString(0, 3*lineHeight, line1); - } else { - if (line1) drawString(0, lineHeight, line1); + switch (glyphType) { + case 0: + if (lineHeight == 2) drawGlyph(6, 1, 0x4e, u8x8_font_open_iconic_embedded_4x4, true); + else drawGlyph(7, lineHeight, 0x4e, u8x8_font_open_iconic_embedded_2x2, true); + break; + case 1: + if (lineHeight == 2) drawGlyph(6, 1, 0x45, u8x8_font_open_iconic_weather_4x4, true); + else drawGlyph(7, lineHeight, 0x45, u8x8_font_open_iconic_weather_2x2, true); + break; + case 2: + if (lineHeight == 2) drawGlyph(6, 1, 0x48, u8x8_font_open_iconic_play_4x4, true); + else drawGlyph(7, lineHeight, 0x48, u8x8_font_open_iconic_play_2x2, true); + break; + case 3: + if (lineHeight == 2) drawGlyph(6, 1, 0x4e, u8x8_font_open_iconic_thing_4x4, true); + else drawGlyph(7, lineHeight, 0x4e, u8x8_font_open_iconic_thing_2x2, true); + break; + case 4: + if (lineHeight == 2) drawGlyph(6, 1, 0x48, u8x8_font_open_iconic_thing_4x4, true); + else drawGlyph(7, lineHeight, 0x48, u8x8_font_open_iconic_thing_2x2, true); + break; + case 5: + if (lineHeight == 2) drawGlyph(6, 1, 0x46, u8x8_font_open_iconic_thing_4x4, true); + else drawGlyph(7, lineHeight, 0x46, u8x8_font_open_iconic_thing_2x2, true); + break; + case 6: + if (lineHeight == 2) drawGlyph(6, 1, 0x47, u8x8_font_open_iconic_thing_4x4, true); + else drawGlyph(7, lineHeight, 0x47, u8x8_font_open_iconic_thing_2x2, true); + break; + case 7: + if (lineHeight == 2) drawGlyph(6, 1, 0x4b, u8x8_font_open_iconic_embedded_4x4, true); + else drawGlyph(7, lineHeight, 0x4b, u8x8_font_open_iconic_embedded_2x2, true); + break; + case 8: + if (lineHeight == 2) drawGlyph(6, 1, 0x44, u8x8_font_open_iconic_weather_4x4, true); + else drawGlyph(7, lineHeight, 0x44, u8x8_font_open_iconic_weather_2x2, true); + break; + } + + if (line1) { + String buf = line1; + center(buf, getCols()); + drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str()); } overlayUntil = millis() + showHowLong; } diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h index 409f71ce9..8b13485b9 100644 --- a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h +++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h @@ -47,7 +47,7 @@ // The last UI state, remove color and saturation option if diplay not active(too many options) #ifdef USERMOD_FOUR_LINE_DISPLAY - #define LAST_UI_STATE 6 + #define LAST_UI_STATE 7 #else #define LAST_UI_STATE 4 #endif @@ -157,6 +157,9 @@ private: uint8_t knownMode = 0; uint8_t knownPalette = 0; + byte presetHigh = 0; + byte presetLow = 0; + bool initDone = false; bool enabled = true; @@ -166,6 +169,8 @@ private: static const char _DT_pin[]; static const char _CLK_pin[]; static const char _SW_pin[]; + static const char _presetHigh[]; + static const char _presetLow[]; /** * Sort the modes and palettes to the index arrays @@ -331,32 +336,19 @@ public: prev_button_state = button_state; char newState = select_state + 1; - if (newState > LAST_UI_STATE) newState = 0; + if (newState > LAST_UI_STATE || (newState == 7 && presetHigh==0 && presetLow == 0)) newState = 0; bool changedState = true; if (display != nullptr) { switch(newState) { - case 0: - changedState = changeState(PSTR("Brightness"), 1, 0, 1); - break; - case 1: - changedState = changeState(PSTR("Speed"), 1, 4, 2); - break; - case 2: - changedState = changeState(PSTR("Intensity"), 1 ,8, 3); - break; - case 3: - changedState = changeState(PSTR("Color Palette"), 2, 0, 4); - break; - case 4: - changedState = changeState(PSTR("Effect"), 3, 0, 5); - break; - case 5: - changedState = changeState(PSTR("Main Color"), 255, 255, 7); - break; - case 6: - changedState = changeState(PSTR("Saturation"), 255, 255, 8); - break; + case 0: changedState = changeState(PSTR("Brightness"), 1, 0, 1); break; + case 1: changedState = changeState(PSTR("Speed"), 1, 4, 2); break; + case 2: changedState = changeState(PSTR("Intensity"), 1, 8, 3); break; + case 3: changedState = changeState(PSTR("Color Palette"), 2, 0, 4); break; + case 4: changedState = changeState(PSTR("Effect"), 3, 0, 5); break; + case 5: changedState = changeState(PSTR("Main Color"), 255, 255, 6); break; + case 6: changedState = changeState(PSTR("Saturation"), 255, 255, 7); break; + case 7: changedState = changeState(PSTR("Preset"), 255, 255, 8); break; } } if (changedState) { @@ -384,53 +376,27 @@ public: if (Enc_B == LOW) //changes to LOW so that then encoder registers a change at the very end of a pulse { // B is high so clockwise switch(select_state) { - case 0: - changeBrightness(true); - break; - case 1: - changeEffectSpeed(true); - break; - case 2: - changeEffectIntensity(true); - break; - case 3: - changePalette(true); - break; - case 4: - changeEffect(true); - break; - case 5: - changeHue(true); - break; - case 6: - changeSat(true); - break; + case 0: changeBrightness(true); break; + case 1: changeEffectSpeed(true); break; + case 2: changeEffectIntensity(true); break; + case 3: changePalette(true); break; + case 4: changeEffect(true); break; + case 5: changeHue(true); break; + case 6: changeSat(true); break; + case 7: changePreset(true); break; } } else if (Enc_B == HIGH) { // B is low so counter-clockwise switch(select_state) { - case 0: - changeBrightness(false); - break; - case 1: - changeEffectSpeed(false); - break; - case 2: - changeEffectIntensity(false); - break; - case 3: - changePalette(false); - break; - case 4: - changeEffect(false); - break; - case 5: - changeHue(false); - break; - case 6: - changeSat(false); - break; + case 0: changeBrightness(false); break; + case 1: changeEffectSpeed(false); break; + case 2: changeEffectIntensity(false); break; + case 3: changePalette(false); break; + case 4: changeEffect(false); break; + case 5: changeHue(false); break; + case 6: changeSat(false); break; + case 7: changePreset(false); break; } } } @@ -471,10 +437,7 @@ public: display->redraw(true); return false; } - String line = stateName; - //line.trim(); - display->center(line, display->getCols()); - display->overlay(line.c_str(), 750, glyph); + display->overlay(stateName, 750, glyph); display->setMarkLine(markedLine, markedCol); } #endif @@ -575,6 +538,7 @@ public: void changeHue(bool increase){ #ifdef USERMOD_FOUR_LINE_DISPLAY if (display && display->wakeDisplay()) { + display->redraw(true); // Throw away wake up input return; } @@ -593,6 +557,7 @@ public: void changeSat(bool increase){ #ifdef USERMOD_FOUR_LINE_DISPLAY if (display && display->wakeDisplay()) { + display->redraw(true); // Throw away wake up input return; } @@ -607,6 +572,29 @@ public: #endif } + void changePreset(bool increase) { + #ifdef USERMOD_FOUR_LINE_DISPLAY + if (display && display->wakeDisplay()) { + display->redraw(true); + // Throw away wake up input + return; + } + #endif + if (presetHigh && presetLow && presetHigh > presetLow) { + String apireq = F("win&PL=~"); + if (!increase) apireq += '-'; + apireq += F("1&P1="); + apireq += presetLow; + apireq += F("&P2="); + apireq += presetHigh; + handleSet(nullptr, apireq, false); + lampUdated(); + } + #ifdef USERMOD_FOUR_LINE_DISPLAY + display->updateRedrawTime(); + #endif + } + /* * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. @@ -658,6 +646,8 @@ public: top[FPSTR(_DT_pin)] = pinA; top[FPSTR(_CLK_pin)] = pinB; top[FPSTR(_SW_pin)] = pinC; + top[FPSTR(_presetLow)] = presetLow; + top[FPSTR(_presetHigh)] = presetHigh; DEBUG_PRINTLN(F("Rotary Encoder config saved.")); } @@ -678,7 +668,12 @@ public: int8_t newCLKpin = top[FPSTR(_CLK_pin)] | pinB; int8_t newSWpin = top[FPSTR(_SW_pin)] | pinC; - enabled = top[FPSTR(_enabled)] | enabled; + presetHigh = top[FPSTR(_presetHigh)] | presetHigh; + presetLow = top[FPSTR(_presetLow)] | presetLow; + presetHigh = MIN(250,MAX(0,presetHigh)); + presetLow = MIN(250,MAX(0,presetLow)); + + enabled = top[FPSTR(_enabled)] | enabled; DEBUG_PRINT(FPSTR(_name)); if (!initDone) { @@ -705,7 +700,7 @@ public: } } // use "return !top["newestParameter"].isNull();" when updating Usermod with new features - return !top[FPSTR(_enabled)].isNull(); + return !top[FPSTR(_presetHigh)].isNull(); } /* @@ -719,8 +714,10 @@ public: }; // strings to reduce flash memory usage (used more than twice) -const char RotaryEncoderUIUsermod::_name[] PROGMEM = "Rotary-Encoder"; -const char RotaryEncoderUIUsermod::_enabled[] PROGMEM = "enabled"; -const char RotaryEncoderUIUsermod::_DT_pin[] PROGMEM = "DT-pin"; -const char RotaryEncoderUIUsermod::_CLK_pin[] PROGMEM = "CLK-pin"; -const char RotaryEncoderUIUsermod::_SW_pin[] PROGMEM = "SW-pin"; +const char RotaryEncoderUIUsermod::_name[] PROGMEM = "Rotary-Encoder"; +const char RotaryEncoderUIUsermod::_enabled[] PROGMEM = "enabled"; +const char RotaryEncoderUIUsermod::_DT_pin[] PROGMEM = "DT-pin"; +const char RotaryEncoderUIUsermod::_CLK_pin[] PROGMEM = "CLK-pin"; +const char RotaryEncoderUIUsermod::_SW_pin[] PROGMEM = "SW-pin"; +const char RotaryEncoderUIUsermod::_presetHigh[] PROGMEM = "preset-high"; +const char RotaryEncoderUIUsermod::_presetLow[] PROGMEM = "preset-low"; diff --git a/wled00/presets.cpp b/wled00/presets.cpp index a1760709f..4e7a78140 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -39,9 +39,17 @@ void handlePresets() errorFlag = readObjectFromFileUsingId(filename, presetToApply, fileDoc) ? ERR_NONE : ERR_FS_PLOAD; } fdo = fileDoc->as(); - fdo.remove("ps"); //remove load request for presets to prevent recursive crash - deserializeState(fdo, callModeToApply, presetToApply); + //HTTP API commands + const char* httpwin = fdo["win"]; + if (httpwin) { + String apireq = "win&"; + apireq += httpwin; + handleSet(nullptr, apireq, false); + } else { + fdo.remove("ps"); //remove load request for presets to prevent recursive crash + deserializeState(fdo, CALL_MODE_NO_NOTIFY, presetToApply); + } #if defined(ARDUINO_ARCH_ESP32) //Aircoookie recommended not to delete buffer @@ -54,7 +62,10 @@ void handlePresets() releaseJSONBufferLock(); // will also clear fileDoc if (!errorFlag && presetToApply < 255) currentPreset = presetToApply; - if (callModeToApply == CALL_MODE_BUTTON_PRESET) errorFlag = ERR_NONE; //ignore error on button press + + colorUpdated(callModeToApply); + updateInterfaces(callModeToApply); + presetToApply = 0; //clear request for preset callModeToApply = 0; } diff --git a/wled00/wled.h b/wled00/wled.h index 557afee10..9f0de0e53 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2201012 +#define VERSION 2201031 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG