diff --git a/_P208_Nokia_LCD_5110.ino b/_P208_Nokia_LCD_5110.ino index e5facfd..db420eb 100644 --- a/_P208_Nokia_LCD_5110.ino +++ b/_P208_Nokia_LCD_5110.ino @@ -2,17 +2,18 @@ //################################## Plugin 208: NOKIA 5110 lcd ######################################### //####################################################################################################### #include "_Plugin_Helper.h" + #ifdef USES_P208 // Working: -// - support different digit-size's. +// - support different digit-size's // - Display Text via: -// 1. ESPEasy-Webinterface (Line-1-Line-x) +// 1. ESPEasy-Webinterface (Line-1...Line-x) // 2. http-request: // - BackLight on via httpcmd (http://ESP-IP/control?cmd=pcd8544cmd,blOn) // - BackLight off via httpcmd (http://ESP-IP/control?cmd=pcd8544cmd,blOff) // - Clear Display via httpcmd (http://ESP-IP/control?cmd=pcd8544cmd,clear) -// - Send Text via httpcmd (http://ESP-IP/control?cmd=pcd8544,1,Hello World!) // 1 : line# +// - Send Text via httpcmd (http://ESP-IP/control?cmd=pcd8544,1,Hello World!;2,this is line two;3, this is line three) // 1,2,3 are the linenumbers. Maximum linnumber is: "lcd_lines_max" // Send Text via http-request only works for the empty lines in ESPEasy-Webinterface! // - Pin connections: // SPI interface: @@ -20,16 +21,16 @@ // RST - => LCD_pin_1 reset connected to Vcc with 10k resistor // CE GPIO-5 => LCD_pin_2 chip select // DC GPIO-32 => LCD_pin_3 Data/Command select -// DIN GPIO-23 => LCD_pin_4 Serial data -// CLK GPIO-18 => LCD_pin_5 Serial clock out -// In hardware tab; -// - enable SPI; -// - Select VSPI:CLK=GPIO-18, MISO=GPIO-19, MOSI=GPIO-23 +// DIN GPIO-23 => LCD_pin_4 Serial data (Hardware-tab: SPI interface, VSPI-MOSI) +// CLK GPIO-18 => LCD_pin_5 Serial clock out (Hardware-tab: SPI interface, VSPI-CLK) +// In hardware tab; +// - enable SPI; +// - Select VSPI:CLK=GPIO-18, MISO=GPIO-19, MOSI=GPIO-23 // (MISO not used) // // - Tested on // - Hardware ESP32 -// - ESPEasy-mega-20210223 +// - ESPEasy_ESP32_mega-20211224 // ToDo: // - different digit-size within a line.... @@ -37,7 +38,7 @@ // // Hardware note: // It's often seen that pins are connected via (10k) risistors. -// Sometimes a screen will not work with these risistors. In that case, connect the display without resistors. +// Sometimes a screen will not work with these risistors. In that case, connect the display without resistors. // That works well. However, I have no long-term experience with this. #define PLUGIN_208 @@ -49,13 +50,14 @@ #include #include -#define lcd_lines 6 -#define Digits_per_template_line 48 // This value must be used at the function "displayText" declaration! +#define Digits_per_template_line 48 // This value must be also used at the function "P208_displayText" declaration! #define digits_per_display_line 14 +#define lcd_lines_max 6 Adafruit_PCD8544 *lcd3 = nullptr; -char html_input [lcd_lines][digits_per_display_line]; +bool sentlog ; // yes/no send info to espeasylog +char html_input [lcd_lines_max][digits_per_display_line]; boolean Plugin_208(byte function, struct EventStruct *event, String& string){ boolean success = false; @@ -98,7 +100,7 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){ case PLUGIN_WEBFORM_LOAD:{ addFormNumericBox(F("Display Contrast(50-100):"), F("plugin_208_contrast"), PCONFIG(1)); - + int optionValues3[4] = { 0, 1, 2, 3 }; String options3[4] = { F("0"), F("90"), F("180"), F("270") }; addFormSelector(F("Display Rotation"), F("plugin_208_rotation"), 4, options3, optionValues3, PCONFIG(2)); @@ -109,17 +111,19 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){ int optionValues5[3] = { 1,2,3 }; String options5[3] = { F("normal"), F("large"), F("x-large") }; - addFormSelector(F("Char.size line-1"), F("plugin_208_charsize_line_1"), 3, options5, optionValues5, PCONFIG(3)); - addFormSelector(F("Char.size line-2"), F("plugin_208_charsize_line_2"), 3, options5, optionValues5, PCONFIG(4)); - addFormSelector(F("Char.size line-3"), F("plugin_208_charsize_line_3"), 3, options5, optionValues5, PCONFIG(5)); + addFormSelector(F("Char.size line-1"), F("plugin_208_charsize_line_1"), 3, options5, optionValues5, PCONFIG(3)); + addFormSelector(F("Char.size line-2"), F("plugin_208_charsize_line_2"), 3, options5, optionValues5, PCONFIG(4)); + addFormSelector(F("Char.size line-3"), F("plugin_208_charsize_line_3"), 3, options5, optionValues5, PCONFIG(5)); - char deviceTemplate [lcd_lines][Digits_per_template_line]; + char deviceTemplate [lcd_lines_max][Digits_per_template_line]; LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); - for (byte varNr = 0; varNr < lcd_lines; varNr++) + for (byte varNr = 0; varNr < lcd_lines_max; varNr++) { addFormTextBox(String(F("Line ")) + (varNr + 1), String(F("Plugin_208_template")) + (varNr + 1), deviceTemplate[varNr], 80); } success = true; + addFormCheckBox(F("debuginfo to log"), F("plugin_208_debuglog"), PCONFIG_LONG(0)); + break; } @@ -132,9 +136,10 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){ PCONFIG(5)= getFormItemInt(F("plugin_208_charsize_line_3")); PCONFIG(6)= getFormItemInt(F("plugin_208_GPIO_CE")); PCONFIG(7)= getFormItemInt(F("plugin_208_GPIO_DC")); - - char deviceTemplate[lcd_lines][Digits_per_template_line]; - for (byte varNr = 0; varNr < lcd_lines; varNr++) + PCONFIG_LONG(0)= isFormItemChecked(F("plugin_208_debuglog")) ? 1 : 0; + sentlog = PCONFIG_LONG(0) == 1; + char deviceTemplate[lcd_lines_max][Digits_per_template_line]; + for (byte varNr = 0; varNr < lcd_lines_max; varNr++) { char argc[25]; String arg = F("Plugin_208_template"); @@ -157,6 +162,7 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){ byte plugin1 = PCONFIG(2); // rotation byte plugin2 = PCONFIG(1); // contrast byte plugin4 = PCONFIG(0); // backlight_onoff + sentlog = PCONFIG_LONG(0) == 1; UserVar[event->BaseVarIndex+2]=plugin1; UserVar[event->BaseVarIndex+1]=plugin2; UserVar[event->BaseVarIndex]=! plugin4; @@ -164,85 +170,129 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){ lcd3->setContrast(30); lcd3->setContrast(plugin2); lcd3->setRotation(plugin1); - char deviceTemplate[lcd_lines][Digits_per_template_line]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); - displayText(deviceTemplate, event); - //displayText((byte**)&deviceTemplate, event); + P208_displayText(event); lcd3->display(); - setBacklight(event); + setBacklight(event); success = true; break; } case PLUGIN_READ:{ - char deviceTemplate[lcd_lines][Digits_per_template_line]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); - displayText(deviceTemplate, event); - //displayText((byte**)&deviceTemplate, event); + P208_displayText(event); success = false; break; } case PLUGIN_WRITE:{ - String tmpString = string; + String tmpString = string; + String tmpstringAll = string; String StringToDisplay; String line_content_ist; String line_content_soll; + String log; + int semicolonpositionnext; + int semicolonposition =-1; + bool semicolonfound = true; + int commaposition; + int line_number_int; + String line_number_string; int argIndex = tmpString.indexOf(','); + //char htmlinput [lcd_lines_max] [1] [digits_per_display_line]; // max Aantal displayregels, rownumber, rowcontent soll + + P208_log("Html input1: "+tmpstringAll); if (argIndex){ - tmpString = tmpString.substring(0, argIndex); + //tmpstringAll = string; + tmpString = string.substring(0, argIndex); if (tmpString.equalsIgnoreCase(F("PCD8544"))){ - if (event->Par1 <= 6 ){ // event->Par1 = row. - success = true; - argIndex = string.lastIndexOf(','); - char deviceTemplate [lcd_lines][Digits_per_template_line]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); - String linedefinition = deviceTemplate[event->Par1-1]; - if (!linedefinition.length()){ // only if value is not definde in plugin-webform - line_content_ist = html_input[event->Par1-1]; - line_content_soll = string.substring(argIndex + 1); - if (line_content_soll.length() < line_content_ist.length() ) { - for(int i=line_content_soll.length(); i < line_content_ist.length(); i++){ + success = true; + P208_log("Html input2: "+string); + do{ + tmpString = string.substring(argIndex+1,string.length()); + P208_log ("tmpString: "+ tmpString); + semicolonpositionnext = tmpString.indexOf(';',semicolonposition+1); // + P208_log ("Parameter: "+tmpString); + log = "semicolonpositionnext: "; + log += semicolonpositionnext; + P208_log (log); + if (semicolonpositionnext < 0){ // not found + semicolonpositionnext = tmpString.length(); + semicolonfound = false; + P208_log ("semicolonpositionnext < 0"); + } + line_number_string = tmpString.charAt(semicolonposition+1); + line_number_int = line_number_string.toInt(); // row + line_content_soll = tmpString.substring(semicolonposition+3,semicolonpositionnext); // contentsoll + + P208_log ("row/content: " + line_number_string + "/"+ line_content_soll); + + if (line_number_int <= lcd_lines_max ){ + char deviceTemplate [lcd_lines_max][Digits_per_template_line]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); + String linedefinition = deviceTemplate[line_number_int-1]; + if (linedefinition.length()>0){ // only if value is not defined in plugin-webform + P208_log ("Unable to display text from html. Line in use by form-definition!"); + }else{ + // clear Old content thats not overwritten bij istcontent + line_content_ist = html_input[line_number_int-1]; + if (line_content_soll.length() < line_content_ist.length() ) { + for(int i=line_content_soll.length(); i < line_content_ist.length(); i++){ line_content_soll += " "; + } } + P208_log("Display: " + line_content_soll); + strncpy(html_input[line_number_int-1], line_content_soll.c_str(), sizeof(deviceTemplate[line_number_int-1])); } - //addLog(LOG_LEVEL_INFO, "5:"+ line_content_soll); - strncpy(html_input[event->Par1-1], line_content_soll.c_str(), sizeof(deviceTemplate[event->Par1-1])); } + semicolonposition = semicolonpositionnext; } + while (semicolonfound); } + if (tmpString.equalsIgnoreCase(F("PCD8544CMD"))){ success = true; - argIndex = string.lastIndexOf(','); - tmpString = string.substring(argIndex + 1); + commaposition = string.lastIndexOf(','); + tmpString = string.substring(commaposition + 1); if (tmpString.equalsIgnoreCase(F("Clear"))){ - addLog(LOG_LEVEL_INFO, F("Clear Display")); + P208_log("Clear Display"); lcd3->clearDisplay(); lcd3->display(); } if (tmpString.equalsIgnoreCase(F("blOn"))){ success = true; PCONFIG(0) = 1; - setBacklight(event); + setBacklight(event); } if (tmpString.equalsIgnoreCase(F("blOff"))){ success = true; PCONFIG(0) = 0; - setBacklight(event); + setBacklight(event); } - break; - } + break; + } } } } // switch (function) return success; } +//void P208_log (String message) { +// addLog(LOG_LEVEL_INFO, "P208: " + message); +//} +void P208_log(const String & message) { + String log; + if (sentlog ){ + log.reserve(message.length() + 6); + log += F("P208: "); + log += message; + addLog(LOG_LEVEL_INFO, log); + } +} + void setBacklight(struct EventStruct *event) { if (Settings.TaskDevicePin3[event->TaskIndex] != -1){ pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT); - digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], PCONFIG(0)); + digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], PCONFIG(0)); portStatusStruct newStatus; const uint32_t key = createKey(1, Settings.TaskDevicePin3[event->TaskIndex]); // WARNING: operator [] creates an entry in the map if key does not exist @@ -254,18 +304,21 @@ void setBacklight(struct EventStruct *event) { } } -boolean displayText(char deviceTemplate[][48], struct EventStruct *event ){ // 48 must be equal to "#define Digits_per_template_line" -//boolean displayText( char &deviceTemplate, struct EventStruct *event ){ // 48 must be equal to "#define Digits_per_template_line" + +boolean P208_displayText(struct EventStruct *event ){ // 48 must be equal to "#define Digits_per_template_line" String log = F("PCD8544: "); - String string ; + String logstring ; lcd3->clearDisplay(); lcd3->setTextColor(BLACK); lcd3->setCursor(0,0); - for (byte x = 0; x < lcd_lines; x++) + char deviceTemplate[lcd_lines_max][Digits_per_template_line]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate)); + + for (byte x = 0; x < lcd_lines_max; x++) { if (x <= 3){ - lcd3->setTextSize(PCONFIG(3+x)); + lcd3->setTextSize(PCONFIG(3+x)); }else{ lcd3->setTextSize(1); } @@ -275,7 +328,7 @@ boolean displayText(char deviceTemplate[][48], struct EventStruct *event ){ // 4 newString = parseTemplate(tmpString, false); }else{ // webformline is empty use html input - newString = html_input[x]; + newString = html_input[x]; // 1e time html_input[x] has trailing spaces to delete old digits from the previous html_input[x] displayed on de LCD // Remove trailing spaces in html_input[x] for the next time while (newString.endsWith(" ")) { @@ -287,10 +340,12 @@ boolean displayText(char deviceTemplate[][48], struct EventStruct *event ){ // 4 strncpy(html_input[x], newString.c_str(), len); } lcd3->println(newString); - string+=newString+"\\"; + logstring += newString; + logstring += F(" ; "); } - log += String(F("displayed text: \"")) + String(string) + String(F("\"")); - addLog(LOG_LEVEL_INFO, log); + log += F("displayed text: "); + log += logstring ; + P208_log(log); lcd3->display(); return true; }