Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved issue https://github.com/letscontrolit/ESPEasy/issues/1844; #183

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 118 additions & 63 deletions _P208_Nokia_LCD_5110.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,43 @@
//################################## 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:
// Example of tested configuration:
// 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....
// - Choice of usable fonts on web-webform.
//
// 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
Expand All @@ -49,13 +50,14 @@

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

Expand All @@ -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");
Expand All @@ -157,92 +162,137 @@ 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;
lcd3->begin();
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when compiling on current mega branch, please use addLogMove macro when appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not use the current ESPmega (ESPEasy-mega-20220328) because of build errors......
I'm using ESPEasy_ESP32_mega-20211224 without build errors....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What build errors do you have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnamed

Copy link

@tonhuisman tonhuisman Apr 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to replay the scenario you have most likely taken:

  • Downloaded the ESPEasy-20220328 sources zip-file from the Releases page
  • Unzipped that file using the 7-zip tool (I always avoid using the Windows explorer .zip extracter, as that thing has been dangerously broken since the first ever release around Windows XP!)
  • Got the _P208_Nokia_LCD_5110.ino from this PR
  • Opened the unzipped folder using VSCode with PlatformIO installed
  • Added Adafruit PCD8544 Nokia 5110 LCD library to lib_deps in both platformio_esp32_envs.ini and platformio_esp82xx_base.ini (don't forget to add a comma after the last entry already there)
  • Added #define USES_P208 to the #ifdef PLUGIN_BUILD_NORMAL section of define_plugin_sets.h to include the plugin (a bit hacky, I know 👼)
  • Clicked Build for the normal_ESP8266_4M1M PIO configuration: successful on first execution
  • Clicked Build for the normal_ESP32_4M316k PIO configuration: successful after a few retries (PIO is known to sometimes have issues when switching configuration like this)

Not sure what the difference is with what you did, but it should be mostly the same, possibly you unpacked the sources-zip using the default Windows tool?

}
}

void setBacklight(struct EventStruct *event) {
JoostDkr marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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);
}
Expand All @@ -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(" ")) {
Expand All @@ -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;
}
Expand Down