Alt Rotary Encoder & Alt 4LD enhancements.

This commit is contained in:
Blaz Kristan 2021-12-20 20:44:06 +01:00
parent b890b5f0dc
commit 12f2caa8d6
3 changed files with 253 additions and 219 deletions

View File

@ -254,7 +254,6 @@ class FourLineDisplayUsermod : public Usermod {
private:
bool initDone = false;
unsigned long lastTime = 0;
// HW interface & configuration
U8X8 *u8x8 = nullptr; // pointer to U8X8 display object
@ -296,7 +295,7 @@ class FourLineDisplayUsermod : public Usermod {
bool powerON = true;
bool displayTurnedOff = false;
unsigned long lastUpdate = 0;
unsigned long nextUpdate = 0;
unsigned long lastRedraw = 0;
unsigned long overlayUntil = 0;
Line4Type lineType = FLD_LINE_BRIGHTNESS;
@ -401,15 +400,20 @@ class FourLineDisplayUsermod : public Usermod {
// gets called every time WiFi is (re-)connected. Initialize own network
// interfaces here
void connected() {}
void connected() {
knownSsid = apActive ? apSSID : WiFi.SSID(); //apActive ? WiFi.softAPSSID() :
knownIp = apActive ? IPAddress(4, 3, 2, 1) : Network.localIP();
networkOverlay(PSTR("NETWORK INFO"),7000);
}
/**
* Da loop.
*/
void loop() {
if (!enabled || millis() - lastUpdate < (clockMode?1000:refreshRate) || strip.isUpdating()) return;
lastUpdate = millis();
if (!enabled || strip.isUpdating()) return;
unsigned long now = millis();
if (now < nextUpdate) return;
nextUpdate = now + (clockMode?1000:refreshRate);
redraw(false);
}
@ -485,7 +489,6 @@ class FourLineDisplayUsermod : public Usermod {
}
}
// Check if values which are shown on display changed from the last time.
if (forceRedraw) {
needRedraw = true;
@ -493,15 +496,18 @@ class FourLineDisplayUsermod : public Usermod {
powerON = !powerON;
drawStatusIcons();
lastRedraw = millis();
return;
} else if (knownnightlight != nightlightActive) { //trigger moon icon
knownnightlight = nightlightActive;
drawStatusIcons();
if (knownnightlight) overlay(" Timer On", 1000, 6);
if (knownnightlight) overlay(PSTR(" Timer On"), 3000, 6);
lastRedraw = millis();
return;
} else if (wificonnected != interfacesInited) { //trigger wifi icon
wificonnected = interfacesInited;
drawStatusIcons();
lastRedraw = millis();
return;
} else if (knownMode != effectCurrent) {
knownMode = effectCurrent;
if (displayTurnedOff) needRedraw = true;
@ -522,7 +528,6 @@ class FourLineDisplayUsermod : public Usermod {
else updateIntensity();
}
if (!needRedraw) {
// Nothing to change.
// Turn off display after 1 minutes with no change.
@ -547,8 +552,6 @@ class FourLineDisplayUsermod : public Usermod {
}
// Update last known values.
knownSsid = apActive ? apSSID : WiFi.SSID(); //apActive ? WiFi.softAPSSID() :
knownIp = apActive ? IPAddress(4, 3, 2, 1) : Network.localIP();
knownBrightness = bri;
knownMode = effectCurrent;
knownPalette = effectPalette;
@ -578,31 +581,34 @@ class FourLineDisplayUsermod : public Usermod {
void updateBrightness() {
knownBrightness = bri;
if (overlayUntil == 0) {
brightness100 = (((float)(bri)/255)*100);
brightness100 = ((uint16_t)bri*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), brightness100);
drawString(1, lineHeight, lineBuffer);
lastRedraw = millis();}
lastRedraw = millis();
}
}
void updateSpeed() {
knownEffectSpeed = effectSpeed;
if (overlayUntil == 0) {
fxspeed100 = (((float)(effectSpeed)/255)*100);
fxspeed100 = ((uint16_t)effectSpeed*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxspeed100);
drawString(5, lineHeight, lineBuffer);
lastRedraw = millis();}
lastRedraw = millis();
}
}
void updateIntensity() {
knownEffectIntensity = effectIntensity;
if (overlayUntil == 0) {
fxintensity100 = (((float)(effectIntensity)/255)*100);
fxintensity100 = ((uint16_t)effectIntensity*100)/255;
char lineBuffer[4];
sprintf_P(lineBuffer, PSTR("%-3d"), fxintensity100);
drawString(9, lineHeight, lineBuffer);
lastRedraw = millis();}
lastRedraw = millis();
}
}
void draw2x2GlyphIcons() {
@ -657,15 +663,13 @@ class FourLineDisplayUsermod : public Usermod {
uint8_t smallChars1 = 0;
uint8_t smallChars2 = 0;
uint8_t smallChars3 = 0;
uint8_t totalCount = 0;
char singleJsonSymbol;
// Find the mode name in JSON
printedChars = extractModeName(inputEffPal, qstring, lineBuffer, LINE_BUFFER_SIZE-1);
if (lineHeight == 2) { // use this code for 8 line display
if (printedChars < MAX_MODE_LINE_SPACE) { // use big font if the text fits
for (;printedChars < (MAX_MODE_LINE_SPACE-1); printedChars++) {lineBuffer[printedChars]=' '; }
for (;printedChars < (MAX_MODE_LINE_SPACE-1); printedChars++) lineBuffer[printedChars]=' ';
lineBuffer[printedChars] = 0;
drawString(1, row*lineHeight, lineBuffer);
} else { // for long names divide the text into 2 lines and print them small
@ -750,19 +754,32 @@ class FourLineDisplayUsermod : public Usermod {
// Print the overlay
clear();
// First row string
if (line1) drawString(0, 0, line1);
if (line1) {
String l1 = line1;
l1.trim();
center(l1, getCols());
drawString(0, 0, l1.c_str());
}
// Second row with Wifi name
String ssidString = knownSsid.substring(0, getCols() > 1 ? getCols() - 2 : 0); //
drawString(0, lineHeight, ssidString.c_str());
String line = knownSsid.substring(0, getCols() > 1 ? getCols() - 2 : 0);
if (line.length() < getCols()) center(line, getCols());
drawString(0, lineHeight, line.c_str());
// Print `~` char to indicate that SSID is longer, than our display
if (knownSsid.length() > getCols()) {
drawString(getCols() - 1, 0, "~");
}
// Third row with IP and Psssword in AP Mode
drawString(0, lineHeight*2, (knownIp.toString()).c_str());
// Third row with IP and Password in AP Mode
line = knownIp.toString();
center(line, getCols());
drawString(0, lineHeight*2, line.c_str());
if (apActive) {
String appassword = apPass;
drawString(0, lineHeight*3, appassword.c_str());
line = apPass;
center(line, getCols());
drawString(0, lineHeight*3, line.c_str());
} else if (strcmp(serverDescription, "WLED") != 0) {
line = serverDescription;
center(line, getCols());
drawString(0, lineHeight*3, line.c_str());
}
overlayUntil = millis() + showHowLong;
}
@ -793,9 +810,12 @@ class FourLineDisplayUsermod : public Usermod {
*/
void showTime() {
if (type == NONE || !enabled) return;
if (knownMinute != minute(localTime)) { //only redraw clock if it has changed
char lineBuffer[LINE_BUFFER_SIZE];
char lineBuffer[LINE_BUFFER_SIZE];
static byte lastSecond;
byte secondCurrent = second(localTime);
if (knownMinute != minute(localTime)) { //only redraw clock if it has changed
//updateLocalTime();
byte AmPmHour = hour(localTime);
boolean isitAM = true;
@ -804,7 +824,7 @@ class FourLineDisplayUsermod : public Usermod {
if (AmPmHour == 0) AmPmHour = 12;
if (hour(localTime) > 11) isitAM = false;
}
clear();
drawStatusIcons(); //icons power, wifi, timer, etc
sprintf_P(lineBuffer, PSTR("%s %2d "), monthShortStr(month(localTime)), day(localTime));
@ -815,7 +835,13 @@ class FourLineDisplayUsermod : public Usermod {
if (useAMPM) drawString(12, lineHeight*2, (isitAM ? "AM" : "PM"), true); //draw am/pm if using 12 time
knownMinute = minute(localTime);
} else {
if (secondCurrent == lastSecond) return;
}
lastSecond = secondCurrent;
draw2x2String(6, lineHeight*2, secondCurrent%2 ? " " : ":");
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
}
/*

View File

@ -55,7 +55,7 @@ private:
int fadeAmount = 5; // Amount to change every step (brightness)
unsigned long currentTime;
unsigned long loopTime;
unsigned long buttonHoldTIme;
unsigned long buttonHoldTime;
int8_t pinA = ENCODER_DT_PIN; // DT from encoder
int8_t pinB = ENCODER_CLK_PIN; // CLK from encoder
int8_t pinC = ENCODER_SW_PIN; // SW from encoder
@ -63,7 +63,7 @@ private:
unsigned char button_state = HIGH;
unsigned char prev_button_state = HIGH;
bool networkShown = false;
uint16_t currentHue1 = 6425; // default reboot color
uint16_t currentHue1 = 16; // default boot color
byte currentSat1 = 255;
#ifdef USERMOD_FOUR_LINE_DISPLAY
@ -168,10 +168,10 @@ public:
// is not yet initialized when setup is called.
if (!currentEffectAndPaletteInitialized) {
findCurrentEffectAndPalette();}
findCurrentEffectAndPalette();
}
if(modes_alpha_indexes[effectCurrentIndex] != effectCurrent
|| palettes_alpha_indexes[effectPaletteIndex] != effectPalette){
if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
currentEffectAndPaletteInitialized = false;
}
@ -180,7 +180,7 @@ public:
button_state = digitalRead(pinC);
if (prev_button_state != button_state)
{
if (button_state == HIGH && (millis()-buttonHoldTIme < 3000))
if (button_state == HIGH && (millis()-buttonHoldTime < 3000))
{
prev_button_state = button_state;
@ -191,25 +191,25 @@ public:
if (display != nullptr) {
switch(newState) {
case 0:
changedState = changeState(" Brightness", 1, 0, 1);
changedState = changeState(PSTR("Brightness"), 1, 0, 1);
break;
case 1:
changedState = changeState(" Speed", 1, 4, 2);
changedState = changeState(PSTR("Speed"), 1, 4, 2);
break;
case 2:
changedState = changeState(" Intensity", 1 ,8, 3);
changedState = changeState(PSTR("Intensity"), 1 ,8, 3);
break;
case 3:
changedState = changeState(" Color Palette", 2, 0, 4);
changedState = changeState(PSTR("Color Palette"), 2, 0, 4);
break;
case 4:
changedState = changeState(" Effect", 3, 0, 5);
changedState = changeState(PSTR("Effect"), 3, 0, 5);
break;
case 5:
changedState = changeState(" Main Color", 255, 255, 7);
changedState = changeState(PSTR("Main Color"), 255, 255, 7);
break;
case 6:
changedState = changeState(" Saturation", 255, 255, 8);
changedState = changeState(PSTR("Saturation"), 255, 255, 8);
break;
}
}
@ -221,11 +221,15 @@ public:
{
prev_button_state = button_state;
networkShown = false;
if(!prev_button_state)buttonHoldTIme = millis();
if (!prev_button_state) buttonHoldTime = millis();
}
}
if (!prev_button_state && (millis()-buttonHoldTIme > 3000) && !networkShown) displayNetworkInfo(); //long press for network info
if (!prev_button_state && (millis()-buttonHoldTime > 3000) && !networkShown) {
displayNetworkInfo(); //long press for network info
loopTime = currentTime; // Updates loopTime
return;
}
Enc_A = digitalRead(pinA); // Read encoder pins
Enc_B = digitalRead(pinB);
@ -291,7 +295,7 @@ public:
void displayNetworkInfo() {
#ifdef USERMOD_FOUR_LINE_DISPLAY
display->networkOverlay(" NETWORK INFO", 15000);
display->networkOverlay(PSTR("NETWORK INFO"), 10000);
networkShown = true;
#endif
}
@ -320,7 +324,10 @@ public:
// Throw away wake up input
return false;
}
display->overlay(stateName, 750, glyph);
String line = stateName;
//line.trim();
display->center(line, display->getCols());
display->overlay(line.c_str(), 750, glyph);
display->setMarkLine(markedLine, markedCol);
}
#endif
@ -424,10 +431,11 @@ public:
return;
}
#endif
if(increase) currentHue1 += 321;
else currentHue1 -= 321;
colorHStoRGB(currentHue1, currentSat1, col);
if (increase) { if (currentHue1<256) currentHue1 += 4; else currentHue1 = 0; }
else { if (currentHue1>3) currentHue1 -= 4; else currentHue1 = 256; }
colorHStoRGB(currentHue1*255, currentSat1, col);
strip.applyToAllSelected = true;
strip.setColor(0, colorFromRgbw(col));
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
display->updateRedrawTime();
@ -441,15 +449,15 @@ public:
return;
}
#endif
if(increase) currentSat1 = (currentSat1 + 5 <= 255 ? (currentSat1 + 5) : 255);
else currentSat1 = (currentSat1 - 5 >= 0 ? (currentSat1 - 5) : 0);
colorHStoRGB(currentHue1, currentSat1, col);
if (increase) { if (currentSat1<252) currentSat1 += 4; }
else { if (currentSat1>3) currentSat1 -= 4; }
colorHStoRGB(currentHue1*256, currentSat1, col);
strip.applyToAllSelected = true;
strip.setColor(0, colorFromRgbw(col));
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
display->updateRedrawTime();
#endif
}
/*

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2112191
#define VERSION 2112201
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG