From 6596e1b76c01ad158809ade5f94d86dfd345be44 Mon Sep 17 00:00:00 2001 From: uwekaditz Date: Mon, 18 Apr 2022 21:26:35 +0200 Subject: [PATCH] ADD: Setting and support for user defined contrast: oledframedcmd,display,user,contrast,precharge,comdetect ADD: oledframedcmd,display,user,contrast,precharge,comdetect (contrast, precharge and comdetect are integers) CHG: setting for low contrast modified, low was invisible! --- docs/source/Plugin/P036_commands.repl | 4 ++++ src/_P036_FrameOLED.ino | 24 ++++++++++++++++++++++ src/src/PluginStructs/P036_data_struct.cpp | 2 +- src/src/PluginStructs/P036_data_struct.h | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/source/Plugin/P036_commands.repl b/docs/source/Plugin/P036_commands.repl index 237d3a638..4a1e8256c 100644 --- a/docs/source/Plugin/P036_commands.repl +++ b/docs/source/Plugin/P036_commands.repl @@ -12,6 +12,7 @@ * ``low`` will dim the display to low. * ``med`` will dim the display to medium. * ``high`` will set the brightness to maximum. + * ``user`` will set the contrast, precharge and comdetect to user defined values. "," OLED displays will age quite fast, so it is not adviced to run them continously at max brightness. @@ -21,6 +22,9 @@ The display controller itself does support more brightness levels, but these are chosen to give noticable change in brightness levels and also to help in choosing the best values for the 2 brightness control registers. As there are 2 brightness control registers, there is some overlap in their range, but some combinations may lead to issues like coil whining noise or sometimes not even working displays as not all of these displays are wired to support both controls to be used. + + For the parameter of the user setting refer to the data sheet of the display. + An example for very low brightness with an user setting is ````. " " ``oledframedcmd,,`` diff --git a/src/_P036_FrameOLED.ino b/src/_P036_FrameOLED.ino index ba8f91f05..ecab610c2 100644 --- a/src/_P036_FrameOLED.ino +++ b/src/_P036_FrameOLED.ino @@ -14,6 +14,9 @@ // Added to the main repository with some optimizations and some limitations. // Al long as the device is not selected, no RAM is waisted. // +// @uwekaditz: 2022-04-18 +// ADD: Setting and support for user defined contrast: oledframedcmd,display,user,contrast,precharge,comdetect (contrast, precharge and comdetect are integers) +// CHG: setting for low contrast modified, low was invisible! // @uwekaditz: 2022-04-16 // MSG: code reduced by 530 bytes to fit the build size for 'esp8266, normal_ESP8266_1M' (equal code put into functions) // @uwekaditz: 2022-04-15 @@ -1120,6 +1123,27 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string) # endif // ifdef P036_SEND_EVENTS P036_SetDisplayOn(1); // Save the fact that the display is now ON } + if ((para1 == F("user")) && + (event->Par2 >= 0) && + (event->Par3 >= 0) && + (event->Par4 >= 0)) { + String contrast = parseString(string, 4); + String precharge = parseString(string, 5); + String comdetect = parseString(string, 5); + success = true; + P036_data->display->setContrast(contrast.toInt(),precharge.toInt(),comdetect.toInt()); + # ifdef P036_SEND_EVENTS + + if (sendEvents) { + P036_SendEvent(event, P036_EVENT_CONTRAST, 3); + + if (!P036_DisplayIsOn) { + P036_SendEvent(event, P036_EVENT_DISPLAY, 1); + } + } + # endif // ifdef P036_SEND_EVENTS + P036_SetDisplayOn(1); // Save the fact that the display is now ON + } } else if ((subcommand == F("frame")) && (event->Par2 >= 0) && (event->Par2 <= P036_data->MaxFramesToDisplay + 1)) { diff --git a/src/src/PluginStructs/P036_data_struct.cpp b/src/src/PluginStructs/P036_data_struct.cpp index 5048ab53c..4a983f793 100644 --- a/src/src/PluginStructs/P036_data_struct.cpp +++ b/src/src/PluginStructs/P036_data_struct.cpp @@ -230,7 +230,7 @@ void P036_data_struct::setContrast(uint8_t OLED_contrast) { display->displayOff(); return; case P36_CONTRAST_LOW: - contrast = 10; precharge = 5; comdetect = 0; + contrast = P36_CONTRAST_LOW; precharge = 5; comdetect = 64; break; case P36_CONTRAST_MED: contrast = P36_CONTRAST_MED; precharge = 0x1F; comdetect = 64; diff --git a/src/src/PluginStructs/P036_data_struct.h b/src/src/PluginStructs/P036_data_struct.h index 2149cad7e..91b814927 100644 --- a/src/src/PluginStructs/P036_data_struct.h +++ b/src/src/PluginStructs/P036_data_struct.h @@ -43,7 +43,7 @@ # define P036_IndicatorHeight 8 # define P36_CONTRAST_OFF 0x01 -# define P36_CONTRAST_LOW 0x40 +# define P36_CONTRAST_LOW 0x70 # define P36_CONTRAST_MED 0xCF # define P36_CONTRAST_HIGH 0xFF