Bugfix for applying WIN API in JSON request.

Added preset cycling in rotary encoder.
Removed custom font from 4LD in favor of built-in.
This commit is contained in:
Blaz Kristan 2022-01-03 22:23:03 +01:00
parent e8b2d80037
commit b6059939b4
4 changed files with 177 additions and 132 deletions

View File

@ -236,6 +236,7 @@ const uint8_t u8x8_font_benji_custom_icons_6x6[2308] U8X8_FONT_SECTION("u8x8_fon
"\3\3\1\0\0\0\60x\374\374x\60\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\14\36\77\77\36\14\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0";
*/
class FourLineDisplayUsermod : public Usermod {
@ -484,7 +485,6 @@ class FourLineDisplayUsermod : public Usermod {
// Check if values which are shown on display changed from the last time.
if (forceRedraw) {
knownHour = 99;
needRedraw = true;
clear();
} else if ((bri == 0 && powerON) || (bri > 0 && !powerON)) { //trigger power icon
@ -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;
}

View File

@ -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,6 +668,11 @@ public:
int8_t newCLKpin = top[FPSTR(_CLK_pin)] | pinB;
int8_t newSWpin = top[FPSTR(_SW_pin)] | pinC;
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));
@ -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();
}
/*
@ -724,3 +719,5 @@ 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";

View File

@ -39,9 +39,17 @@ void handlePresets()
errorFlag = readObjectFromFileUsingId(filename, presetToApply, fileDoc) ? ERR_NONE : ERR_FS_PLOAD;
}
fdo = fileDoc->as<JsonObject>();
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;
}

View File

@ -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