From 8e3bb7f4e0b24ee1df70915066e7c8d69df60a43 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Fri, 6 Aug 2021 22:11:46 +0200 Subject: [PATCH] better support for ILI9341, and minor polishing --- RX_FSK/RX_FSK.ino | 24 ++++------------ RX_FSK/data/config.txt | 8 ++---- RX_FSK/version.h | 4 +-- libraries/SondeLib/Display.cpp | 50 ++++++++++++++++++++-------------- libraries/SondeLib/Display.h | 1 + libraries/SondeLib/Scanner.cpp | 3 +- libraries/SondeLib/Sonde.cpp | 9 ++---- libraries/SondeLib/Sonde.h | 3 +- 8 files changed, 48 insertions(+), 54 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 87eeb56..3fb4856 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -541,10 +541,10 @@ struct st_configitems { struct st_configitems config_list[] = { /* General config settings */ {"", "Software configuration", -5, NULL}, - {"wifi", "Wifi mode (0/1/2/3)", 0, &sonde.config.wifi}, + {"wifi", "Wifi mode (0-Off/1-Client/2-Access Point/3-Debug)", 0, &sonde.config.wifi}, {"debug", "Debug mode (0/1)", 0, &sonde.config.debug}, - {"maxsonde", "Maxsonde", 0, &sonde.config.maxsonde}, - {"screenfile", "Screen config (0=old, 1=OLED, 2/3=ILI9251 l/p, 4/5=ILI9341 l/p", 0, &sonde.config.screenfile}, + {"maxsonde", "Maxsonde (max # QRG entries)", 0, &sonde.config.maxsonde}, + {"screenfile", "Screen config (0=automatic; 1-5=predefined; other=custom)", 0, &sonde.config.screenfile}, {"display", "Display screens (scan,default,...)", -6, sonde.config.display}, /* Spectrum display settings */ {"spectrum", "Show spectrum (-1=no, 0=forever, >0=seconds)", 0, &sonde.config.spectrum}, @@ -554,7 +554,6 @@ struct st_configitems config_list[] = { {"noisefloor", "Spectrum noisefloor", 0, &sonde.config.noisefloor}, /* decoder settings */ {"", "Receiver configuration", -5, NULL}, - {"showafc", "Show AFC value", 0, &sonde.config.showafc}, {"freqofs", "RX frequency offset (Hz)", 0, &sonde.config.freqofs}, {"rs41.agcbw", "RS41 AGC bandwidth", 0, &sonde.config.rs41.agcbw}, {"rs41.rxbw", "RS41 RX bandwidth", 0, &sonde.config.rs41.rxbw}, @@ -608,7 +607,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}, + {"tft_spifreq", "TFT SPI speed", 0, &sonde.config.tft_spifreq}, {"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}, @@ -670,7 +669,7 @@ void addConfigHeading(char *ptr, const char *label) { strcat(ptr, "\n"); } void addConfigInt8List(char *ptr, int idx, const char *label, int8_t *list) { - sprintf(ptr + strlen(ptr), "%s", label); + sprintf(ptr + strlen(ptr), "%s using /screens%d.txt", label, Display::getScreenIndex(sonde.config.screenfile)); for (int i = 0; i < disp.nLayouts; i++) { sprintf(ptr + strlen(ptr), "
%d=%s", i, disp.layouts[i].label); } @@ -1217,7 +1216,7 @@ void SetupAsyncServer() { 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.

"); + request->send(200, "text/html", "ERROR

Something went wrong (probably ESP32 out of memory). Uploaded file is empty.

"); else { String f = request->getParam(0)->value(); request->redirect("/edit.html?file=" + f); @@ -2740,17 +2739,6 @@ void loopWifiScan() { while (WiFi.status() != WL_CONNECTED && cnt < MAXWIFIDELAY) { delay(500); Serial.print("."); -#if 0 - if (cnt == 5) { - // my FritzBox needs this for reconnecting - WiFi.disconnect(true); - delay(500); - WiFi.begin(fetchWifiSSID(index), fetchWifiPw(index)); - Serial.print("Reconnecting to: "); Serial.print(fetchWifiSSID(index)); - Serial.print(" with password "); Serial.println(fetchWifiPw(index)); - delay(500); - } -#endif disp.rdis->drawString(15 * dispxs, lastl + dispys, _scan[cnt & 1]); cnt++; } diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index 4e6e86c..08ef101 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -25,11 +25,9 @@ #tft_rs=2 #tft_cs=0 tft_orient=1 -#tft_modeflip=0 +#tft_spifreq=40000000 #gps_rxd=-1 #gps_txd=-1 -# Show AFC value (for RS41 and M10/M20, maybe also DFM, but not useful for RS92) -showafc=1 # Frequency correction, in Hz # freqofs=0 #-------------------------------# @@ -42,8 +40,8 @@ wifi=3 # TCP/IP KISS TNC in port 14590 for APRSdroid (0=disabled, 1=enabled) kisstnc.active = 1 -# which screens file to use (0: screens.txt, i>0: screens${i}.txt -# 0: old version; 1: for OLED, 2: for TFT; 3: for TFT (portrait mode) +# which screens file to use (0: automated selection based on display type and orientation, i>0: screens${i}.txt +# predefined: 1: for OLED, 2: for ILI9225; 3: for ILI9225 (portrait mode); 4: for ILI9431; 5: for ILI9431 (portrait mode) # screenfile=2 # display configuration. List of "displays" # first entry: "Scanner" display diff --git a/RX_FSK/version.h b/RX_FSK/version.h index c6d9c0b..0ba37d7 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20210728"; +const char *version_id = "devel20210806"; const int SPIFFS_MAJOR=2; -const int SPIFFS_MINOR=11; +const int SPIFFS_MINOR=12; diff --git a/libraries/SondeLib/Display.cpp b/libraries/SondeLib/Display.cpp index 9d68133..35a9caa 100644 --- a/libraries/SondeLib/Display.cpp +++ b/libraries/SondeLib/Display.cpp @@ -26,7 +26,7 @@ extern SemaphoreHandle_t axpSemaphore; struct GpsPos gpsPos; -SPIClass spiDisp(HSPI); +//SPIClass spiDisp(HSPI); const char *sondeTypeStr[NSondeTypes] = { "DFM ", "DFM9", "RS41", "RS92", "M10 ", "M20 ", "DFM6", "MP3H" }; const char *sondeTypeLongStr[NSondeTypes] = { "DFM (all)", "DFM9 (old)", "RS41", "RS92", "M10 ", "M20 ", "DFM6 (old)", "MP3-H1" }; @@ -338,17 +338,17 @@ static int ngfx = sizeof(gfl)/sizeof(GFXfont *); #define TFT_BRIGHTNESS 100 // Initial brightness of TFT backlight (optional) Arduino_DataBus *bus; - + void ILI9225Display::begin() { - Serial.println("ILI9225 init (alt driver)"); + Serial.println("ILI9225/ILI9341 init"); bus = new Arduino_ESP32SPI( sonde.config.tft_rs, sonde.config.tft_cs, sonde.config.oled_scl, sonde.config.oled_sda, -1, HSPI); if(_type == 3) tft = new Arduino_ILI9341(bus, sonde.config.oled_rst); else tft = new Arduino_ILI9225(bus, sonde.config.oled_rst); - Serial.println("ILI9225 init (alt driver): done"); - tft->begin(); + Serial.println("ILI9225/ILI9341 init: done"); + tft->begin(sonde.config.tft_spifreq); tft->fillScreen(BLACK); tft->setRotation(sonde.config.tft_orient); tft->setTextWrap(false); @@ -675,8 +675,6 @@ void Display::init() { delay(100); Serial.println("Display initialized"); rdis->clear(); - delay(3000); - Serial.println("Cleared"); } @@ -908,17 +906,32 @@ int Display::countEntries(File f) { return n; } +int Display::getScreenIndex(int index) { + if(index!=0) return index; + switch(sonde.config.disptype) { + case 1: // ILI9225 + index = 2; // landscape mode (orient=1/3) + if( (sonde.config.tft_orient&0x01)==0 ) index++; // portrait mode (0/2) + break; + case 3: // ILI9341 + index = 4; // landscape mode (orient=1/3) + if( (sonde.config.tft_orient&0x01)==0 ) index++; // portrait mode (0/2) + break; + case 0: case 2: // small OLED display (SD1306/SH1106) + default: + index = 1; break; + } + return index; +} void Display::initFromFile(int index) { File d; - if(index>0) { - char file[20]; - snprintf(file, 20, "/screens%d.txt", index); - Serial.printf("Reading %s\n", file); - d = SPIFFS.open(file, "r"); - if(!d || d.available()==0 ) { Serial.printf("%s not found, using /screens.txt\n", file); } - } - if(!d || d.available()==0 ) d = SPIFFS.open("/screens.txt", "r"); - if(!d) return; + char file[20]; + + index = getScreenIndex(index); // auto selection for index==0 + snprintf(file, 20, "/screens%d.txt", index); + Serial.printf("Reading %s\n", file); + d = SPIFFS.open(file, "r"); + if(!d || d.available()==0 ) { Serial.printf("%s not found\n", file); return; } DispInfo *newlayouts = (DispInfo *)malloc(MAXSCREENS * sizeof(DispInfo)); if(!newlayouts) { @@ -1211,10 +1224,7 @@ void Display::drawFreq(DispEntry *de) { drawString(de, buf); } void Display::drawAFC(DispEntry *de) { - if(!sonde.config.showafc) return; rdis->setFont(de->fmt); - //if(sonde.si()->afc==0) { strcpy(buf, " "); } - //else { snprintf(buf, 15, " %+3.2fk", sonde.si()->afc*0.001); } drawString(de, buf+strlen(buf)-8); } @@ -1227,7 +1237,7 @@ void Display::drawSite(DispEntry *de) { switch(de->extra[0]) { case '#': // currentSonde is index in array starting with 0; - // but we draw "1" for the first entrie and so on... + // but we draw "1" for the first entry and so on... snprintf(buf, 3, "%2d", sonde.currentSonde+1); buf[2]=0; break; diff --git a/libraries/SondeLib/Display.h b/libraries/SondeLib/Display.h index 5db50c6..e2bfece 100644 --- a/libraries/SondeLib/Display.h +++ b/libraries/SondeLib/Display.h @@ -148,6 +148,7 @@ private: return ret; } public: + static int getScreenIndex(int index); void initFromFile(int index); int layoutIdx; diff --git a/libraries/SondeLib/Scanner.cpp b/libraries/SondeLib/Scanner.cpp index d2ddad9..31a5d7e 100644 --- a/libraries/SondeLib/Scanner.cpp +++ b/libraries/SondeLib/Scanner.cpp @@ -24,6 +24,7 @@ struct scancfg { //struct scancfg scanLCD={ 121, 7, 120/6, 120/6/4, 6000.0/120.0/20.0, 20, 120*20, 1 }; struct scancfg scanLCD={ 121, 7, 120/6, 120/6/4, 6000.0/120.0/10.0, 10, 120*10, 2, 40 }; struct scancfg scanTFT={ 210, 16, 210/6, 210/6/5, 6000.0/210.0/10.0, 10, 210*10, 1, 0 }; +struct scancfg scan9341={ 210, 16, 210/6, 210/6/5, 6000.0/210.0/10.0, 10, 210*10, 1, 0 }; struct scancfg &scanconfig = scanTFT; @@ -65,7 +66,7 @@ void Scanner::fillTiles(uint8_t *row, int value) { ///// unused???? uint8_t tiles[16] = { 0x0f,0x0f,0x0f,0x0f,0xf0,0xf0,0xf0,0xf0, 1, 3, 7, 15, 31, 63, 127, 255}; // type 0: lcd, 1: tft, 2: lcd(sh1106) -#define ISTFT (sonde.config.disptype==1) +#define ISTFT (sonde.config.disptype==1 || sonde.config.disptype==3) void Scanner::plotResult() { int yofs = 0; diff --git a/libraries/SondeLib/Sonde.cpp b/libraries/SondeLib/Sonde.cpp index 96da15f..cdfc554 100644 --- a/libraries/SondeLib/Sonde.cpp +++ b/libraries/SondeLib/Sonde.cpp @@ -91,7 +91,7 @@ void Sonde::defaultConfig() { config.button2_axp = 0; config.norx_timeout = 20; config.screenfile = 1; - config.tft_modeflip = 0; + config.tft_spifreq = SPI_DEFAULT_FREQ; if(initlevels[16]==0) { config.oled_sda = 4; config.oled_scl = 15; @@ -185,7 +185,6 @@ void Sonde::defaultConfig() { config.startfreq=400; config.channelbw=10; config.marker=0; - config.showafc=0; config.freqofs=0; config.rs41.agcbw=12500; config.rs41.rxbw=6300; @@ -265,8 +264,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,"tft_spifreq")==0) { + config.tft_spifreq = atoi(val); } else if(strcmp(cfg,"gps_rxd")==0) { config.gps_rxd = atoi(val); } else if(strcmp(cfg,"gps_txd")==0) { @@ -305,8 +304,6 @@ void Sonde::setConfig(const char *cfg) { config.spectrum = atoi(val); } else if(strcmp(cfg,"marker")==0) { config.marker = atoi(val); - } else if(strcmp(cfg,"showafc")==0) { - config.showafc = atoi(val); } else if(strcmp(cfg,"freqofs")==0) { config.freqofs = atoi(val); } else if(strcmp(cfg,"rs41.agcbw")==0) { diff --git a/libraries/SondeLib/Sonde.h b/libraries/SondeLib/Sonde.h index ab41365..022e6dc 100644 --- a/libraries/SondeLib/Sonde.h +++ b/libraries/SondeLib/Sonde.h @@ -209,7 +209,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 tft_spifreq; // SPI transfer speed (default 40M is out of spec for some TFT) int gps_rxd; // GPS module RXD pin. We expect 9600 baud NMEA data. int gps_txd; // GPS module TXD pin // software configuration @@ -227,7 +227,6 @@ typedef struct st_rdzconfig { int noisefloor; // for spectrum display char mdnsname[15]; // mDNS-Name, defaults to rdzsonde // receiver configuration - int showafc; // show afc value in rx screen int freqofs; // frequency offset (tuner config = rx frequency + freqofs) in Hz struct st_rs41config rs41; // configuration options specific for RS41 receiver struct st_rs92config rs92;