From a7a642332fc118a241c077583ac549a145d63764 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Tue, 2 Mar 2021 12:47:46 +0100 Subject: [PATCH] test (Joerg) --- RX_FSK/RX_FSK.ino | 70 ++++++++++++++++++++++++++-- RX_FSK/data/config.txt | 1 + RX_FSK/version.h | 2 +- libraries/SondeLib/Sonde.cpp | 3 ++ libraries/SondeLib/Sonde.h | 1 + libraries/SondeLib/TFT22_ILI9225.cpp | 11 +++-- libraries/SondeLib/TFT22_ILI9225.h | 4 +- 7 files changed, 84 insertions(+), 8 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index d6f2eb4..d940a13 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -108,6 +108,7 @@ int readLine(Stream &stream, char *buffer, int maxlen) { return n; } + // Replaces placeholder with LED state value String processor(const String& var) { Serial.println(var); @@ -564,6 +565,7 @@ struct st_configitems config_list[] = { {"tft_rs", "TFT RS", 0, &sonde.config.tft_rs}, {"tft_cs", "TFT CS", 0, &sonde.config.tft_cs}, {"tft_orient", "TFT orientation (0/1/2/3), OLED flip: 3", 0, &sonde.config.tft_orient}, + {"tft_modeflip", "TFT modeflip (usually 0)", 0, &sonde.config.tft_modeflip}, {"button_pin", "Button input port", -4, &sonde.config.button_pin}, {"button2_pin", "Button 2 input port", -4, &sonde.config.button2_pin}, {"button2_axp", "Use AXP192 PWR as Button 2", 0, &sonde.config.button2_axp}, @@ -790,6 +792,55 @@ const char *handleControlPost(AsyncWebServerRequest *request) { return ""; } +int streamEditForm(int &state, File &file, String filename, char *buffer, size_t maxlen, size_t index) { + Serial.printf("streamEdit: state=%d max:%d idx:%d\n", state, maxlen, index); + int i=0; + switch(state) { + case 0: // header + { + // we optimistically assume that on first invocation, maxlen is large enough to handle the header..... + strncpy(buffer, "Editor

Edit: ", maxlen); + i = strlen(buffer); + strncpy(buffer+i, filename.c_str(), maxlen-i); + i += strlen(buffer+i); + strncpy(buffer+i, "

", maxlen); + state++; + return strlen(buffer); + case 3: // end + return 0; + } + return 0; +} + // bad idea. prone to buffer overflow. use at your own risk... const char *createEditForm(String filename) { Serial.println("Creating edit form"); @@ -999,14 +1050,27 @@ void SetupAsyncServer() { }); server.on("/edit.html", HTTP_GET, [](AsyncWebServerRequest * request) { - request->send(200, "text/html", createEditForm(request->getParam(0)->value())); + // new version: + // Open file + // store file object in request->_tempObject + //request->send(200, "text/html", createEditForm(request->getParam(0)->value())); + const String filename = request->getParam(0)->value(); + File file = SPIFFS.open("/" + filename, "r"); + int state = 0; + request->send("text/html", 0, [state,file,filename](uint8_t *buffer, size_t maxLen, size_t index) mutable -> size_t { + Serial.printf("******* send callback: %d %d %d\n", state, maxLen, index); + return streamEditForm(state, file, filename, (char *)buffer, maxLen, index); + }); }); server.on("/edit.html", HTTP_POST, [](AsyncWebServerRequest * request) { const char *ret = handleEditPost(request); if (ret == NULL) request->send(200, "text/html", "ERROR

Something went wrong. Uploaded file is empty.

"); - else - request->send(200, "text/html", createEditForm(request->getParam(0)->value())); + else { + String f = request->getParam(0)->value(); + request->redirect("/edit.html?file="+f); + //request->send(200, "text/html", createEditForm(request->getParam(0)->value())); + } }, NULL, [](AsyncWebServerRequest * request, uint8_t *data, size_t len, size_t index, size_t total) { diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index bda55a1..e3bcc5e 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -25,6 +25,7 @@ #tft_rs=2 #tft_cs=0 tft_orient=1 +#tft_modeflip=0 #gps_rxd=-1 #gps_txd=-1 # Show AFC value (for RS41 and M10/M20, maybe also DFM, but not useful for RS92) diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 31a1153..479d805 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20210226"; +const char *version_id = "devel20210302"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=10; diff --git a/libraries/SondeLib/Sonde.cpp b/libraries/SondeLib/Sonde.cpp index 0c9c590..57648d8 100644 --- a/libraries/SondeLib/Sonde.cpp +++ b/libraries/SondeLib/Sonde.cpp @@ -87,6 +87,7 @@ void Sonde::defaultConfig() { config.button2_axp = 0; config.norx_timeout = 20; config.screenfile = 1; + config.tft_modeflip = 0; if(initlevels[16]==0) { config.oled_sda = 4; config.oled_scl = 15; @@ -258,6 +259,8 @@ void Sonde::setConfig(const char *cfg) { config.tft_cs = atoi(val); } else if(strcmp(cfg,"tft_orient")==0) { config.tft_orient = atoi(val); + } else if(strcmp(cfg,"tft_modeflip")==0) { + config.tft_modeflip = atoi(val); } else if(strcmp(cfg,"gps_rxd")==0) { config.gps_rxd = atoi(val); } else if(strcmp(cfg,"gps_txd")==0) { diff --git a/libraries/SondeLib/Sonde.h b/libraries/SondeLib/Sonde.h index 189df28..4ba8640 100644 --- a/libraries/SondeLib/Sonde.h +++ b/libraries/SondeLib/Sonde.h @@ -186,6 +186,7 @@ typedef struct st_rdzconfig { int tft_rs; // TFT RS pin int tft_cs; // TFT CS pin int tft_orient; // TFT orientation (default: 1) + int tft_modeflip; // Hack for Joerg's strange display int gps_rxd; // GPS module RXD pin. We expect 9600 baud NMEA data. int gps_txd; // GPS module TXD pin // software configuration diff --git a/libraries/SondeLib/TFT22_ILI9225.cpp b/libraries/SondeLib/TFT22_ILI9225.cpp index 1bd3762..145d7d6 100644 --- a/libraries/SondeLib/TFT22_ILI9225.cpp +++ b/libraries/SondeLib/TFT22_ILI9225.cpp @@ -342,10 +342,12 @@ void TFT22_ILI9225::begin() endWrite(); delay(50); +#define OCTLFLIP(m) ((m&0xff)<<8) +#define EMODEFLIP(m) ((m>>8)<<3) startWrite(); - _writeRegister(ILI9225_DRIVER_OUTPUT_CTRL, 0x011C); // set the display line number and display direction + _writeRegister(ILI9225_DRIVER_OUTPUT_CTRL, OCTLFLIP(_modeFlip) ^ 0x011C); // set the display line number and display direction _writeRegister(ILI9225_LCD_AC_DRIVING_CTRL, 0x0100); // set 1 line inversion - _writeRegister(ILI9225_ENTRY_MODE, 0x1038); // set GRAM write direction and BGR=1. + _writeRegister(ILI9225_ENTRY_MODE, EMODEFLIP(_modeFlip) ^ 0x1038); // set GRAM write direction and BGR=1. _writeRegister(ILI9225_DISP_CTRL1, 0x0000); // Display off _writeRegister(ILI9225_BLANK_PERIOD_CTRL1, 0x0808); // set the back porch and front porch _writeRegister(ILI9225_FRAME_CYCLE_CTRL, 0x1100); // set the clocks number per line @@ -482,7 +484,7 @@ void TFT22_ILI9225::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y startWrite(); // autoincrement mode if ( _orientation > 0 ) mode = modeTab[_orientation-1][mode]; - _writeRegister(ILI9225_ENTRY_MODE, 0x1000 | ( mode<<3) ); + _writeRegister(ILI9225_ENTRY_MODE, EMODEFLIP(_modeFlip) ^ (0x1000 | ( mode<<3)) ); _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR1,x1); _writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR2,x0); @@ -582,6 +584,9 @@ void TFT22_ILI9225::setDisplay(boolean flag) { } } +void TFT22_ILI9225::setModeFlip(uint8_t m) { + _modeFlip = m; +} void TFT22_ILI9225::setOrientation(uint8_t orientation) { diff --git a/libraries/SondeLib/TFT22_ILI9225.h b/libraries/SondeLib/TFT22_ILI9225.h index 2cdab23..7286173 100644 --- a/libraries/SondeLib/TFT22_ILI9225.h +++ b/libraries/SondeLib/TFT22_ILI9225.h @@ -393,6 +393,8 @@ class TFT22_ILI9225 { void getGFXCharExtent(uint8_t c, int16_t *gw, int16_t *gh, int16_t *xa); + void setModeFlip(uint8_t m); + private: void _spiWrite(uint8_t v); @@ -436,7 +438,7 @@ class TFT22_ILI9225 { int8_t _rst, _rs, _cs, _sdi, _clk, _led; #endif - uint8_t _orientation, _brightness; + uint8_t _orientation, _brightness, _modeflip; // correspondig modes if orientation changed: const autoIncMode_t modeTab [3][8] = {