diff --git a/docs/source/Plugin/P116.rst b/docs/source/Plugin/P116.rst index 9be499937..f0e806012 100644 --- a/docs/source/Plugin/P116.rst +++ b/docs/source/Plugin/P116.rst @@ -139,6 +139,7 @@ Available options: * *ST7735 128 x 128px* Allows about 12 lines of text in the smallest font scaling setting (the 13th line will be distorted, as the bottom 2 pixellines aren't available) * *ST7735 128 x 160px* Allows 16 lines of text in the smallest font scaling setting. * *ST7735 80 x 160px* Allows 16 lines of text in the smallest font scaling setting. +* *ST7735 80 x 160px (Color inverted)* Special color inverted configuration as used in f.e. M5Stack StickC. * *ST7789 240 x 320px* Allows 32 lines of text in the smallest font scaling setting. Predefined text only goes to 24, extra lines can be displayed from rules or external commands. * *ST7789 240 x 240px* Allows 24 lines of text in the smallest font scaling setting. * *ST7789 240 x 280px* Allows 28 lines of text in the smallest font scaling setting. Predefined text only goes to 24, extra lines can be displayed from rules or external commands. diff --git a/docs/source/Plugin/P116_TFTDisplayModelOptions.png b/docs/source/Plugin/P116_TFTDisplayModelOptions.png index a578b2146..a17199a9c 100644 Binary files a/docs/source/Plugin/P116_TFTDisplayModelOptions.png and b/docs/source/Plugin/P116_TFTDisplayModelOptions.png differ diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp index bfab90aef..2ddd4e242 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.cpp @@ -234,6 +234,15 @@ void Adafruit_ST7735::initR(uint8_t options) { displayInit(Rcmd2green160x80); _colstart = 24; _rowstart = 0; + } else if (options == INITR_GREENTAB160x80) { + _height = ST7735_TFTWIDTH_80; + _width = ST7735_TFTHEIGHT_160; + displayInit(Rcmd2green160x80); + const uint8_t data = 0x00; + sendCommand(ST77XX_INVON, &data, 0); + sendCommand(ST77XX_INVON, &data, 0); // Write twice... + _colstart = 26; + _rowstart = 1; } else { // colstart, rowstart left at default '0' values displayInit(Rcmd2red); diff --git a/lib/Adafruit_ST77xx/Adafruit_ST7735.h b/lib/Adafruit_ST77xx/Adafruit_ST7735.h index da1320a35..6d138bce3 100644 --- a/lib/Adafruit_ST77xx/Adafruit_ST7735.h +++ b/lib/Adafruit_ST77xx/Adafruit_ST7735.h @@ -13,6 +13,7 @@ #define INITR_144GREENTAB 0x01 #define INITR_MINI160x80 0x04 #define INITR_HALLOWING 0x05 +#define INITR_GREENTAB160x80 0x06 // Some register settings #define ST7735_MADCTL_BGR 0x08 diff --git a/src/_P087_SerialProxy.ino b/src/_P087_SerialProxy.ino index 7faa8e852..a2b9c5876 100644 --- a/src/_P087_SerialProxy.ino +++ b/src/_P087_SerialProxy.ino @@ -8,6 +8,13 @@ // Interact with a device connected to serial // Allows to redirect data to a controller // +/** + * Changelog: + * 2022-07-08 tonhuisman: Allow baudrate lowest value to 300 (from 2400) + * Don't trim off pre/post white-space from string to send + * 2022-07-07 tonhuisman: Add selection for serial protocol configuration (databits, parity, nr. of stopbits) + * 2022-07 First recorded changelog + **/ #include "src/PluginStructs/P087_data_struct.h" @@ -21,6 +28,7 @@ #define P087_BAUDRATE PCONFIG_LONG(0) #define P087_BAUDRATE_LABEL PCONFIG_LABEL(0) +#define P087_SERIAL_CONFIG PCONFIG_LONG(1) #define P087_QUERY_VALUE 0 // Temp placement holder until we know what selectors are needed. #define P087_NR_OUTPUT_OPTIONS 1 @@ -131,8 +139,10 @@ boolean Plugin_087(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_SHOW_SERIAL_PARAMS: { - addFormNumericBox(F("Baudrate"), P087_BAUDRATE_LABEL, P087_BAUDRATE, 2400, 115200); + addFormNumericBox(F("Baudrate"), P087_BAUDRATE_LABEL, P087_BAUDRATE, 300, 115200); addUnit(F("baud")); + uint8_t serialConfChoice = serialHelper_convertOldSerialConfig(P087_SERIAL_CONFIG); + serialHelper_serialconfig_webformLoad(event, serialConfChoice); break; } @@ -148,7 +158,8 @@ boolean Plugin_087(uint8_t function, struct EventStruct *event, String& string) } case PLUGIN_WEBFORM_SAVE: { - P087_BAUDRATE = getFormItemInt(P087_BAUDRATE_LABEL); + P087_BAUDRATE = getFormItemInt(P087_BAUDRATE_LABEL); + P087_SERIAL_CONFIG = serialHelper_serialconfig_webformSave(); P087_data_struct *P087_data = static_cast(getPluginTaskData(event->TaskIndex)); @@ -178,7 +189,7 @@ boolean Plugin_087(uint8_t function, struct EventStruct *event, String& string) return success; } - if (P087_data->init(port, serial_rx, serial_tx, P087_BAUDRATE)) { + if (P087_data->init(port, serial_rx, serial_tx, P087_BAUDRATE, static_cast(P087_SERIAL_CONFIG))) { LoadCustomTaskSettings(event->TaskIndex, P087_data->_lines, P87_Nlines, 0); P087_data->post_init(); success = true; @@ -230,7 +241,7 @@ boolean Plugin_087(uint8_t function, struct EventStruct *event, String& string) static_cast(getPluginTaskData(event->TaskIndex)); if ((nullptr != P087_data)) { - String param1 = parseStringKeepCase(string, 2); + String param1 = parseStringKeepCase(string, 2, ',', false); // Don't trim off white-space parseSystemVariables(param1, false); P087_data->sendString(param1); addLogMove(LOG_LEVEL_INFO, param1); diff --git a/src/_P116_ST77xx.ino b/src/_P116_ST77xx.ino index 6ec2bc1ff..444577d85 100644 --- a/src/_P116_ST77xx.ino +++ b/src/_P116_ST77xx.ino @@ -8,6 +8,7 @@ // History: +// 2022-07-06 tonhuisman: Add support for ST7735sv M5Stack StickC (Inverted colors) // 2021-11-16 tonhuisman: P116: Change state from Development to Testing // 2021-11-08 tonhuisman: Add support for function PLUGIN_GET_DISPLAY_PARAMETERS for retrieving the display parameters // as implemented by FT6206 touchscreen plugin. Added ST77xx_type_toResolution @@ -121,6 +122,7 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) ST77xx_type_toString(ST77xx_type_e::ST7735s_128x128), ST77xx_type_toString(ST77xx_type_e::ST7735s_128x160), ST77xx_type_toString(ST77xx_type_e::ST7735s_80x160), + ST77xx_type_toString(ST77xx_type_e::ST7735s_80x160_M5), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x320), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x240), ST77xx_type_toString(ST77xx_type_e::ST7789vw_240x280), @@ -131,6 +133,7 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string) static_cast(ST77xx_type_e::ST7735s_128x128), static_cast(ST77xx_type_e::ST7735s_128x160), static_cast(ST77xx_type_e::ST7735s_80x160), + static_cast(ST77xx_type_e::ST7735s_80x160_M5), static_cast(ST77xx_type_e::ST7789vw_240x320), static_cast(ST77xx_type_e::ST7789vw_240x240), static_cast(ST77xx_type_e::ST7789vw_240x280), diff --git a/src/src/Helpers/StringConverter.cpp b/src/src/Helpers/StringConverter.cpp index 4d54491c8..efa2a38e3 100644 --- a/src/src/Helpers/StringConverter.cpp +++ b/src/src/Helpers/StringConverter.cpp @@ -640,31 +640,33 @@ String to_internal_string(const String& input, char replaceSpace) { IndexFind = 1 => command. // FIXME TD-er: parseString* should use index starting at 0. \*********************************************************************************************/ -String parseString(const String& string, uint8_t indexFind, char separator) { - String result = parseStringKeepCase(string, indexFind, separator); +String parseString(const String& string, uint8_t indexFind, char separator, bool trimResult) { + String result = parseStringKeepCase(string, indexFind, separator, trimResult); result.toLowerCase(); return result; } -String parseStringKeepCase(const String& string, uint8_t indexFind, char separator) { +String parseStringKeepCase(const String& string, uint8_t indexFind, char separator, bool trimResult) { String result; if (!GetArgv(string.c_str(), result, indexFind, separator)) { return EMPTY_STRING; } - result.trim(); + if (trimResult) { + result.trim(); + } return stripQuotes(result); } -String parseStringToEnd(const String& string, uint8_t indexFind, char separator) { - String result = parseStringToEndKeepCase(string, indexFind, separator); +String parseStringToEnd(const String& string, uint8_t indexFind, char separator, bool trimResult) { + String result = parseStringToEndKeepCase(string, indexFind, separator, trimResult); result.toLowerCase(); return result; } -String parseStringToEndKeepCase(const String& string, uint8_t indexFind, char separator) { +String parseStringToEndKeepCase(const String& string, uint8_t indexFind, char separator, bool trimResult) { // Loop over the arguments to find the first and last pos of the arguments. int pos_begin = string.length(); int pos_end = pos_begin; @@ -691,24 +693,27 @@ String parseStringToEndKeepCase(const String& string, uint8_t indexFind, char se } String result = string.substring(pos_begin, pos_end); - result.trim(); + if (trimResult) { + result.trim(); + } return stripQuotes(result); } String tolerantParseStringKeepCase(const char * string, - uint8_t indexFind, - char separator) + uint8_t indexFind, + char separator, + bool trimResult) { - return tolerantParseStringKeepCase(String(string), indexFind, separator); + return tolerantParseStringKeepCase(String(string), indexFind, separator, trimResult); } -String tolerantParseStringKeepCase(const String& string, uint8_t indexFind, char separator) +String tolerantParseStringKeepCase(const String& string, uint8_t indexFind, char separator, bool trimResult) { if (Settings.TolerantLastArgParse()) { - return parseStringToEndKeepCase(string, indexFind, separator); + return parseStringToEndKeepCase(string, indexFind, separator, trimResult); } - return parseStringKeepCase(string, indexFind, separator); + return parseStringKeepCase(string, indexFind, separator, trimResult); } // escapes special characters in strings for use in html-forms diff --git a/src/src/Helpers/StringConverter.h b/src/src/Helpers/StringConverter.h index 0419d246e..c2dc3b1ca 100644 --- a/src/src/Helpers/StringConverter.h +++ b/src/src/Helpers/StringConverter.h @@ -209,28 +209,34 @@ String to_internal_string(const String& input, // FIXME TD-er: parseString* should use index starting at 0. \*********************************************************************************************/ String parseString(const String& string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); String parseStringKeepCase(const String& string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); String parseStringToEnd(const String& string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); String parseStringToEndKeepCase(const String& string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); String tolerantParseStringKeepCase(const char * string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); String tolerantParseStringKeepCase(const String& string, - uint8_t indexFind, - char separator = ','); + uint8_t indexFind, + char separator = ',', + bool trimResult = true); // escapes special characters in strings for use in html-forms bool htmlEscapeChar(char c, diff --git a/src/src/PluginStructs/P087_data_struct.cpp b/src/src/PluginStructs/P087_data_struct.cpp index b37c55126..0b24300b9 100644 --- a/src/src/PluginStructs/P087_data_struct.cpp +++ b/src/src/PluginStructs/P087_data_struct.cpp @@ -24,7 +24,7 @@ void P087_data_struct::reset() { } } -bool P087_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, const int16_t serial_tx, unsigned long baudrate) { +bool P087_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, const int16_t serial_tx, unsigned long baudrate, uint8_t config) { if ((serial_rx < 0) && (serial_tx < 0)) { return false; } @@ -32,7 +32,11 @@ bool P087_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, con easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx); if (isInitialized()) { - easySerial->begin(baudrate); + # if defined(ESP8266) + easySerial->begin(baudrate, (SerialConfig)config); + # elif defined(ESP32) + easySerial->begin(baudrate, config); + # endif // if defined(ESP8266) return true; } return false; diff --git a/src/src/PluginStructs/P087_data_struct.h b/src/src/PluginStructs/P087_data_struct.h index ff66e41b8..7c6639feb 100644 --- a/src/src/PluginStructs/P087_data_struct.h +++ b/src/src/PluginStructs/P087_data_struct.h @@ -49,7 +49,8 @@ public: bool init(ESPEasySerialPort port, const int16_t serial_rx, const int16_t serial_tx, - unsigned long baudrate); + unsigned long baudrate, + uint8_t config); // Called after loading the config from the settings. // Will interpret some data and load caches. diff --git a/src/src/PluginStructs/P116_data_struct.cpp b/src/src/PluginStructs/P116_data_struct.cpp index 53b4e194f..726d48c1d 100644 --- a/src/src/PluginStructs/P116_data_struct.cpp +++ b/src/src/PluginStructs/P116_data_struct.cpp @@ -12,6 +12,7 @@ const __FlashStringHelper* ST77xx_type_toString(ST77xx_type_e device) { case ST77xx_type_e::ST7735s_128x128: return F("ST7735 128 x 128px"); case ST77xx_type_e::ST7735s_128x160: return F("ST7735 128 x 160px"); case ST77xx_type_e::ST7735s_80x160: return F("ST7735 80 x 160px"); + case ST77xx_type_e::ST7735s_80x160_M5: return F("ST7735 80 x 160px (Color inverted)"); case ST77xx_type_e::ST7789vw_240x320: return F("ST7789 240 x 320px"); case ST77xx_type_e::ST7789vw_240x240: return F("ST7789 240 x 240px"); case ST77xx_type_e::ST7789vw_240x280: return F("ST7789 240 x 280px"); @@ -35,6 +36,7 @@ void ST77xx_type_toResolution(ST77xx_type_e device, uint16_t& x, uint16_t& y) { x = 128; y = 160; break; + case ST77xx_type_e::ST7735s_80x160_M5: case ST77xx_type_e::ST7735s_80x160: x = 80; y = 160; @@ -140,6 +142,13 @@ bool P116_data_struct::plugin_init(struct EventStruct *event) { initRoptions = INITR_BLACKTAB; // 128x160px } + // fall through + case ST77xx_type_e::ST7735s_80x160_M5: + + if (initRoptions == 0xFF) { + initRoptions = INITR_GREENTAB160x80; // 80x160px ST7735sv, inverted (M5Stack StickC) + } + // fall through case ST77xx_type_e::ST7735s_80x160: { diff --git a/src/src/PluginStructs/P116_data_struct.h b/src/src/PluginStructs/P116_data_struct.h index b26e0ce63..758663f40 100644 --- a/src/src/PluginStructs/P116_data_struct.h +++ b/src/src/PluginStructs/P116_data_struct.h @@ -58,22 +58,23 @@ # else // ifdef ESP32 // Was: for D1 Mini with shield connection - # define P116_TFT_CS 0 // D3 - # define P116_TFT_DC 4 // D2 + # define P116_TFT_CS 0 // D3 + # define P116_TFT_DC 4 // D2 # define P116_TFT_RST -1 // D4 // -1 # define P116_BACKLIGHT_PIN -1 // D6 // 15 // D8 -> Blocks Wemos # endif // ifdef ESP32 enum class ST77xx_type_e : uint8_t { - ST7735s_128x128 = 0, - ST7735s_128x160, - ST7735s_80x160, - ST7789vw_240x320, - ST7789vw_240x240, - ST7789vw_240x280, - ST7789vw_135x240, - ST7796s_320x480, - ST77xx_MAX // must be last value in enum + ST7735s_128x128 = 0, + ST7735s_128x160 = 1u, + ST7735s_80x160 = 2u, + ST7735s_80x160_M5 = 8u, + ST7789vw_240x320 = 3u, + ST7789vw_240x240 = 4u, + ST7789vw_240x280 = 5u, + ST7789vw_135x240 = 6u, + ST7796s_320x480 = 7u, + ST77xx_MAX = 9u // must be last value in enum }; enum class P116_CommandTrigger : uint8_t {