So I'd like to present modified OLED plugin (in BETA stage) to support Nokia 3310 LCD (PCD8544). (Its not finish) and if some one can help to make it better - is welcome.
Its use (Adafruit-PCD8544 and Adafruit GFX library - version for ESP8266 ) with small modification in Adafruit-GFX library to support 14 characters in line (please modify line 82 from "wrap = true" to "wrap = false").
It's not clean, more garbage from OLED-plugin but I have not much time to make it clean - maybe someone ? And maybe remove Adafruit library and build in direct in PCD8544 plugin like OLED-plugin
Hiere is that code:
Code: Select all
//#######################################################################################################
//#################################### Plugin 208: LCD PCD8544 display #################################
//#######################################################################################################
// Sample templates
// Temp: [DHT11#Temperature] Hum:[DHT11#humidity]
// DS Temp:[Dallas1#Temperature#R]
// Lux:[Lux#Lux#R]
// Baro:[Baro#Pressure#R]
#define PLUGIN_208
#define PLUGIN_ID_208 208
#define PLUGIN_NAME_208 "Display - LCD PCD8544"
#define PLUGIN_VALUENAME1_208 "PCD8544"
byte Plugin_208_PCD8544_address = 0x3c;
boolean Plugin_208(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte displayTimer = 0;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_208;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].SendDataOption = false;
Device[deviceCount].TimerOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_208);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_208));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
char deviceTemplate[6][64];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
for (byte varNr = 0; varNr < 6; varNr++)
{
string += F("<TR><TD>Line ");
string += varNr + 1;
string += F(":<TD><input type='text' size='64' maxlength='64' name='Plugin_208_template");
string += varNr + 1;
string += F("' value='");
string += deviceTemplate[varNr];
string += F("'>");
}
string += F("<TR><TD>Display button:<TD>");
addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);
char tmpString[128];
sprintf_P(tmpString, PSTR("<TR><TD>Display Timeout:<TD><input type='text' name='plugin_208_timer' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
string += tmpString;
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
String plugin3 = WebServer.arg("plugin_208_timer");
Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin3.toInt();
char deviceTemplate[6][64];
for (byte varNr = 0; varNr < 6; varNr++)
{
char argc[25];
String arg = F("Plugin_208_template");
arg += varNr + 1;
arg.toCharArray(argc, 25);
String tmpString = WebServer.arg(argc);
strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
}
Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value
SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
success = true;
break;
}
case PLUGIN_INIT:
{
Plugin_208_StartUp_PCD8544();
displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
pinMode(Settings.TaskDevicePin3[event->TaskIndex], INPUT_PULLUP);
success = true;
break;
}
case PLUGIN_TEN_PER_SECOND:
{
if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
{
if (!digitalRead(Settings.TaskDevicePin3[event->TaskIndex]))
{
// Plugin_208_displayOn(); // DISPLAY ON
display.display();
displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
}
}
break;
}
case PLUGIN_ONCE_A_SECOND:
{
if ( displayTimer > 0)
{
displayTimer--;
if (displayTimer == 0)
Plugin_208_displayOff(); // DISPLAY OFF
}
break;
}
case PLUGIN_READ:
{
display.clearDisplay();
//display.begin();
//display.setContrast(50);
//display.setTextSize(1);
char deviceTemplate[6][64];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
for (byte x = 0; x < 6; x++)
{
String tmpString = deviceTemplate[x];
if (tmpString.length())
{
String newString = parseTemplate(tmpString, 14);
display.setCursor(0,x*8);
display.print(newString);
}
}
display.display();
success = false;
break;
}
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("PCD8544")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
Plugin_208_sendStrXY(tmpString.c_str(), event->Par1 - 1, event->Par2 - 1);
}
if (tmpString.equalsIgnoreCase(F("PCD8544CMD")))
{
success = true;
argIndex = string.lastIndexOf(',');
tmpString = string.substring(argIndex + 1);
if (tmpString.equalsIgnoreCase(F("Off")))
Plugin_208_displayOff();
else if (tmpString.equalsIgnoreCase(F("On")))
Plugin_208_displayOn();
else if (tmpString.equalsIgnoreCase(F("Clear")))
Plugin_208_clear_display();
}
break;
}
}
return success;
}
static void Plugin_208_reset_display(void)
{
Plugin_208_displayOff();
Plugin_208_clear_display();
Plugin_208_displayOn();
}
void Plugin_208_StartUp_PCD8544()
{
display.begin();
display.setContrast(50);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("ESPEasy");;
}
void Plugin_208_displayOn(void)
{
display.clearDisplay();
display.display();
}
void Plugin_208_displayOff(void)
{
display.clearDisplay();
display.display();
}
static void Plugin_208_clear_display(void)
{
display.clearDisplay();
display.display();
}
// Set the cursor position in a 14 COL * 6 ROW map.
static void Plugin_208_setXY(unsigned char row, unsigned char col)
{
display.setCursor(row,col);
}
// Prints a string regardless the cursor position.
static void Plugin_208_sendStr(unsigned char *string)
{
display.println(*string);
}
// Prints a string in coordinates X Y, being multiples of 6.
// This means we have 14 COLS (0-13) and 6 ROWS (0-5).
static void Plugin_208_sendStrXY(const char *string, int X, int Y)
{
Plugin_208_setXY(X, Y);
display.println(*string);
}
Please use it as STARTPOINT - ALFA version but it work for me now.
BR
Adam
PS. Hope it will good start point.