From fa75c2058417e066caa24862a1ec6e80b4ae80dc Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Wed, 11 Nov 2020 00:12:10 +0100 Subject: [PATCH] fix spectrum display for LCD, better display for TFT --- RX_FSK/RX_FSK.ino | 8 +- RX_FSK/version.h | 2 +- libraries/SondeLib/Display.cpp | 11 ++- libraries/SondeLib/Scanner.cpp | 154 ++++++++++++++++++++++++--------- 4 files changed, 126 insertions(+), 49 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 7474813..492ec50 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -1766,13 +1766,7 @@ void loopSpectrum() { scanner.scan(); scanner.plotResult(); - if (sonde.config.marker != 0) { - itoa((sonde.config.startfreq), buf, 10); - disp.rdis->drawString(0, 1, buf); - disp.rdis->drawString(7, 1, "MHz"); - itoa((sonde.config.startfreq + 6), buf, 10); - disp.rdis->drawString(13, 1, buf); - } + if (sonde.config.spectrum > 0) { int remaining = sonde.config.spectrum - (millis() - specTimer) / 1000; itoa(remaining, buf, 10); diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 5a1cb12..2cc6a2b 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20200728"; +const char *version_id = "devel20201111"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=4; diff --git a/libraries/SondeLib/Display.cpp b/libraries/SondeLib/Display.cpp index aed2b25..d38b91a 100644 --- a/libraries/SondeLib/Display.cpp +++ b/libraries/SondeLib/Display.cpp @@ -399,7 +399,14 @@ void ILI9225Display::drawString(uint8_t x, uint8_t y, const char *s, int16_t wid } if(width==WIDTH_AUTO || alignright) { tft->getGFXTextExtent(s, x, y + gfxoffsets[findex-3].yofs, &w, &h); - if(width==WIDTH_AUTO) width=w; + if(width==WIDTH_AUTO) { + width=w; + if(alignright) { + x -= w; + Serial.print("reducing x by widht, its now "); + Serial.println(x); + } + } } if(findex-3>=ngfx) findex=3; @@ -413,7 +420,7 @@ void ILI9225Display::drawString(uint8_t x, uint8_t y, const char *s, int16_t wid } void ILI9225Display::drawTile(uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr) { - tft->drawTile(x, 2*y, cnt, tile_ptr); + tft->drawTile(x, y, cnt, tile_ptr); #if 0 int i,j; tft->startWrite(); diff --git a/libraries/SondeLib/Scanner.cpp b/libraries/SondeLib/Scanner.cpp index 9706372..03ea2e9 100644 --- a/libraries/SondeLib/Scanner.cpp +++ b/libraries/SondeLib/Scanner.cpp @@ -5,76 +5,136 @@ #include "Sonde.h" #include "Display.h" -#define CHANBW 10 -#define PIXSAMPL (50/CHANBW) -#define SMOOTH 3 + +double STARTF; + + +struct scancfg { + int PLOT_W; // Width of plot, in pixel + int PLOT_H8; // Height of plot, in 8 pixel units + int TICK1; // Pixel per MHz marker + int TICK2; // Pixel per sub-Mhz marker (250k or 200k) + double CHANSTEP; // Scanner frequenz steps + int SMPL_PIX; // Frequency steps per pixel + int NCHAN; // number of channels to scan, PLOT_W * SMPL_PIX + int SMOOTH; +}; + +struct scancfg scanLCD={ 121, 7, 120/6, 120/6/4, 6000.0/120.0/10.0, 10, 120*10, 2 }; +struct scancfg scanTFT={ 210, 16, 210/6, 210/6/5, 6000.0/210.0/10.0, 10, 210*10, 1 }; + +struct scancfg &scanconfig = scanTFT; + +#define CHANBW 12500 +//#define PIXSAMPL (50/CHANBW) //#define STARTF 401000000 -#define NCHAN ((int)(6000/CHANBW)) -double STARTF = (sonde.config.startfreq * 1000000); -//int CHANBW = (sonde.config.channelbw); -//int NCHAN = ((int)(6000/CHANBW)); -//int PIXSAMPL = (50/CHANBW); +// max of 120*5 and 210*3 +#define MAXN 210*10 +// max of 120 and 210 (ceil(210/8)*8)) +#define MAXDISP 216 -int scanresult[NCHAN]; -int scandisp[NCHAN/PIXSAMPL]; +int scanresult[MAXN]; +int scandisp[MAXDISP]; +double peakf=0; -#define PLOT_N 128 -#define TICK1 (128/6) -#define TICK2 (TICK1/4) //#define PLOT_MIN -250 #define PLOT_MIN (sonde.config.noisefloor*2) #define PLOT_SCALE(x) (x=8) { row[8*y]=255; continue; } row[8*y] = tilepatterns[nbits]; } } -/* +/* LCD: * There are 16*8 columns to plot, NPLOT must be lower than that * currently, we use 128 * 50kHz channels * There are 8*8 values to plot; MIN is bottom end, + * TFT: + * There are 210 columns to plot + * Currently we use 210 * (6000/120)kHz channels, i.e. 28.5714kHz */ -uint8_t tiles[16] = { 0x0f,0x0f,0x0f,0x0f,0xf0,0xf0,0xf0,0xf0, 1, 3, 7, 15, 31, 63, 127, 255}; +///// unused???? uint8_t tiles[16] = { 0x0f,0x0f,0x0f,0x0f,0xf0,0xf0,0xf0,0xf0, 1, 3, 7, 15, 31, 63, 127, 255}; void Scanner::plotResult() { - uint8_t row[8*8]; - for(int i=0; idrawString(0, 1, buf); + disp.rdis->drawString(95, 1, "MHz"); + itoa((sonde.config.startfreq + 6), buf, 10); + disp.rdis->drawString(195, 1, buf); + } + } + else { + if (sonde.config.marker != 0) { + itoa((sonde.config.startfreq), buf, 10); + disp.rdis->drawString(0, 1, buf); + disp.rdis->drawString(7, 1, "MHz"); + itoa((sonde.config.startfreq + 6), buf, 10); + disp.rdis->drawString(13, 1, buf); + } + } + uint8_t row[scanconfig.PLOT_H8*8]; + for(int i=0; i=scanconfig.PLOT_W ) { for(int y=0; y=7*8&&i<10*8) || i>=13*8) continue; } - disp.rdis->drawTile(i/8, y, 1, row+8*y); + disp.rdis->drawTile(i/8, y+yofs, 1, row+8*y); } } + if(sonde.config.disptype != 0) { // large TFT + sprintf(buf, "Peak: %03.3f MHz", peakf*0.000001); + disp.rdis->drawString(0, (yofs+scanconfig.PLOT_H8+1)*8, buf); + } else { + sprintf(buf, "Peak: %03.3fMHz", peakf*0.000001); + disp.rdis->drawString(0, 7, buf); + } } void Scanner::scan() { + if(sonde.config.disptype==0) { // LCD small + scanconfig = scanLCD; + } else { + scanconfig = scanTFT; + } // Configure + STARTF = (sonde.config.startfreq * 1000000); sx1278.writeRegister(REG_PLL_HOP, 0x80); // FastHopOn - sx1278.setRxBandwidth(CHANBW*1000); - sx1278.writeRegister(REG_RSSI_CONFIG, SMOOTH&0x07); + sx1278.setRxBandwidth((int)(scanconfig.CHANSTEP*1000)); + double bw = sx1278.getRxBandwidth(); + Serial.print("RX Bandwith for scan: "); Serial.println(bw); + sx1278.writeRegister(REG_RSSI_CONFIG, scanconfig.SMOOTH&0x07); sx1278.setFrequency(STARTF); + Serial.print("Start freq = "); Serial.println(STARTF); sx1278.writeRegister(REG_OP_MODE, FSK_RX_MODE); - delay(20); unsigned long start = millis(); - uint32_t lastfrf=-1; - for(int iter=0; iter<2; iter++) { // two interations, to catch all RS41 transmissions - for(int i=0; i>16)!=(frf>>16) ) { sx1278.writeRegister(REG_FRF_MSB, (frf&0xff0000)>>16); @@ -84,9 +144,8 @@ void Scanner::scan() } sx1278.writeRegister(REG_FRF_LSB, (frf&0x0000ff)); lastfrf = frf; - // Wait TS_HOP (20us) + TS_RSSI ( 2^(SMOOTH+1) / 4 / CHANBW us) - int wait = 20 + 1000*(1<<(SMOOTH+1))/4/CHANBW; - delayMicroseconds(wait+5); + // Wait TS_HOP (20us) + TS_RSSI ( 2^(scacconfig.SMOOTH+1) / 4 / CHANBW us) + delayMicroseconds(wait); int rssi = -(int)sx1278.readRegister(REG_RSSI_VALUE_FSK); if(iter==0) { scanresult[i] = rssi; } else { if(rssi>scanresult[i]) scanresult[i]=rssi; @@ -94,20 +153,37 @@ void Scanner::scan() } } unsigned long duration = millis()-start; + Serial.print("wait: "); + Serial.println(wait); Serial.print("Scan time: "); Serial.println(duration); - for(int i=0; ipeakres+1) { peakres=r; peakidx=i*scanconfig.SMPL_PIX+j; } + } //for(int j=1; jscandisp[i/PIXSAMPL]) scandisp[i/PIXSAMPL] = scanresult[i+j]; } Serial.print(scanresult[i]); Serial.print(", "); } + peakidx--; + double newpeakf = STARTF + scanconfig.CHANSTEP*1000.0*peakidx; + if(newpeakfpeakf+20000) peakf=newpeakf; // different frequency + else if (newpeakf < peakf) peakf = 0.75*newpeakf + 0.25*peakf; // averaging on frequency, some bias towards lower... + else peakf = 0.25*newpeakf + 0.75*peakf; Serial.println("\n"); - for(int i=0; i