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 4 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
84 changes: 53 additions & 31 deletions _P208_Nokia_LCD_5110.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifdef USES_P208

// Working:
// - support different digit-size's.
// - support different digit-size's
// - Display Text via:
// 1. ESPEasy-Webinterface (Line-1-Line-x)
// 2. http-request:
Expand All @@ -20,24 +20,24 @@
// 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 @@ -55,6 +55,7 @@

Adafruit_PCD8544 *lcd3 = nullptr;

bool sentlog ; // yes/no send info to espeasylog
char html_input [lcd_lines][digits_per_display_line];

boolean Plugin_208(byte function, struct EventStruct *event, String& string){
Expand Down Expand Up @@ -98,7 +99,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,9 +110,9 @@ 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];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
Expand All @@ -120,6 +121,8 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){
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(8));

break;
}

Expand All @@ -132,7 +135,8 @@ 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"));

PCONFIG(8)= isFormItemChecked(F("plugin_208_debuglog")) ? 1 : 0;
JoostDkr marked this conversation as resolved.
Show resolved Hide resolved
sentlog = PCONFIG(8) == 1;
char deviceTemplate[lcd_lines][Digits_per_template_line];
for (byte varNr = 0; varNr < lcd_lines; varNr++)
{
Expand All @@ -157,6 +161,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(8) == 1;
UserVar[event->BaseVarIndex+2]=plugin1;
UserVar[event->BaseVarIndex+1]=plugin2;
UserVar[event->BaseVarIndex]=! plugin4;
Expand All @@ -169,7 +174,7 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){
displayText(deviceTemplate, event);
//displayText((byte**)&deviceTemplate, event);
lcd3->display();
setBacklight(event);
setBacklight(event);
success = true;
break;
}
Expand All @@ -193,21 +198,23 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){
if (argIndex){
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("PCD8544"))){
if (event->Par1 <= 6 ){ // event->Par1 = row.
success = true;
success = true;
if (event->Par1 <= 6 ){ // event->Par1 = row.
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
if (linedefinition.length()){ // only if value is not defined in plugin-webform
myLog ("Unable to display text. Line in use by form-definition!");
}else{
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++){
line_content_soll += " ";
}
}
//addLog(LOG_LEVEL_INFO, "5:"+ line_content_soll);
}
//myLog(line_content_soll);
strncpy(html_input[event->Par1-1], line_content_soll.c_str(), sizeof(deviceTemplate[event->Par1-1]));
}
}
Expand All @@ -217,32 +224,45 @@ boolean Plugin_208(byte function, struct EventStruct *event, String& string){
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
if (tmpString.equalsIgnoreCase(F("Clear"))){
addLog(LOG_LEVEL_INFO, F("Clear Display"));
myLog("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 myLog (String message) {
// addLog(LOG_LEVEL_INFO, "P208: " + message);
//}
void myLog(const String & message) {
JoostDkr marked this conversation as resolved.
Show resolved Hide resolved
String log;
if (sentlog){

Choose a reason for hiding this comment

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

  • The order of these 2 lines could be swapped
  • You could also check in the if wether the log-level is set (when compiling against a current ESPEasy mega):
    if (sentlog && logLevelActiveFor(LOG_LEVEL_INFO)) {

that would save a few cpu cycles and a bit of memory

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

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 @@ -257,15 +277,15 @@ void setBacklight(struct EventStruct *event) {
boolean displayText(char deviceTemplate[][48], struct EventStruct *event ){ // 48 must be equal to "#define Digits_per_template_line"
JoostDkr marked this conversation as resolved.
Show resolved Hide resolved
//boolean displayText( char &deviceTemplate, 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++)
{
if (x <= 3){
lcd3->setTextSize(PCONFIG(3+x));
lcd3->setTextSize(PCONFIG(3+x));
}else{
lcd3->setTextSize(1);
}
Expand All @@ -275,7 +295,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 +307,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 ;
myLog(log);
lcd3->display();
return true;
}
Expand Down