From 64e45e76adbee0174ec5248b4a721434a93b9dff Mon Sep 17 00:00:00 2001 From: M0WID Date: Sat, 15 Aug 2020 22:44:19 +0100 Subject: [PATCH] Now runs Need to expand to full width, reduce height, add waterfall --- Bandscope.ino | 145 ++++++++++++++++++++++++++++++++++++++++++++------ simpleSA.ino | 18 +++++-- 2 files changed, 142 insertions(+), 21 deletions(-) diff --git a/Bandscope.ino b/Bandscope.ino index 48acdd5..9e16544 100644 --- a/Bandscope.ino +++ b/Bandscope.ino @@ -22,7 +22,7 @@ void initBandscope() img.setTextSize ( 1 ); img.setColorDepth ( 16 ); img.setAttribute ( PSRAM_ENABLE, false ); // Don't use the PSRAM on the WROVERs - img.createSprite ( 2, GRID_HEIGHT + 1 ); // Only 2 columns wide + img.createSprite ( 9, GRID_HEIGHT + 1 ); // Only 2 columns wide /* @@ -91,8 +91,8 @@ static uint32_t nextPointFreq = 0; // Frequency for the next display point. Us static unsigned long setFreqMicros; static unsigned long nowMicros; -static uint32_t sweepStep; // Step count -static uint32_t sweepFreqStep; +//static uint32_t sweepStep; // Step count +//static uint32_t sweepFreqStep; static int16_t pointMinGain; // to record minimum gain for the current display point static int16_t pointMaxRSSI; // to record max RSSI of the samples in the current display point @@ -147,7 +147,7 @@ static uint16_t chunkIndex; rcvr.SetFrequency ( setting.IF_Freq ); // Set the RX Si4432 to the IF frequency - sweepFreqStep = autoSweepFreqStep; // Step for each reading +// sweepFreqStep = autoSweepFreqStep; // Step for each reading if ( setting.Attenuate != old_settingAttenuate ) { @@ -167,7 +167,7 @@ static uint16_t chunkIndex; wiFiPoints = MAX_WIFI_POINTS; if (wiFiPoints > setting.BandscopePoints) wiFiPoints = setting.BandscopePoints; - Serial.printf("No of wifiPoints set to %i\n", wiFiPoints); +// Serial.printf("No of wifiPoints set to %i\n", wiFiPoints); if ( numberOfWebsocketClients > 0 ) pushBandscopeSettings (); @@ -212,11 +212,11 @@ static uint16_t chunkIndex; #endif // #ifdef USE_WIFI - sweepStep = 0; +// sweepStep = 0; startFreq = setting.BandscopeStart + setting.IF_Freq; // Start freq for the LO stopFreq = setting.BandscopeSpan + startFreq; // Stop freq for the LO - Serial.printf(" start %i; stop %i; points %i \n", startFreq, stopFreq, sweepPoints ); +// Serial.printf(" start %i; stop %i; points %i \n", startFreq, stopFreq, sweepPoints ); if ( setActualPowerRequested ) { @@ -242,7 +242,7 @@ static uint16_t chunkIndex; peaks[i].Level = 0; } - //DisplayInfo (); // Display axis, top and side bar text + DisplayBandscopeInfo (); // Display axis and other info peakLevel = 0; // Reset the peak values for the sweep peakFreq = 0.0; @@ -311,19 +311,19 @@ static uint16_t chunkIndex; * The second one produces a listing more fit for human consumption! */ -// if ( showRSSI ) // Displaying RSSI? -// { + if ( showRSSI ) // Displaying RSSI? + { // Serial.printf ( "%s\t%03d\n", // FormatFrequency ( autoSweepFreq) , rxRSSI ); // Send it to the serial output Serial.printf ( "Freq: %s - RSSI: %03d\n", FormatFrequency ( autoSweepFreq) , rxRSSI ); // Send it to the serial output -// } + } if ( (numberOfWebsocketClients > 0) || (setting.ShowGain) ) gainReading = GetPreampGain ( &AGC_On, &AGC_Reg ); // Record the preamp/lna gains - autoSweepFreq += sweepFreqStep; // Increment the frequency - sweepStep++; // and increment the step count + autoSweepFreq += autoSweepFreqStep; // Increment the frequency + autoSweepStep++; // and increment the step count /* @@ -376,7 +376,7 @@ static uint16_t chunkIndex; chunkIndex = 0; jsonDocument.clear(); jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = sweepStep; + jsonDocument["StartIndex"] = autoSweepStep; jsonDocument["sweepPoints"] = sweepPoints; jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); Points = jsonDocument.createNestedArray ("Points" ); // Add Points array @@ -389,7 +389,7 @@ static uint16_t chunkIndex; myActual[autoSweepStep] = rxRSSI; myGain[autoSweepStep] = gainReading; - + DrawCheckerBoard ( oldSweepStep ); // Draw the grid for the point in the sweep we have just read if ( resetAverage || setting.Average == AV_OFF ) // Store data, either as read or as rolling average @@ -543,7 +543,7 @@ static uint16_t chunkIndex; myFreq[oldSweepStep] = oldSweepFreq; // Store the frequency for XML file creation - if ( sweepStep >= sweepPoints ) // If we have got to the end of the sweep + if ( autoSweepStep >= sweepPoints ) // If we have got to the end of the sweep { // autoSweepStep = 0; sweepStartDone = false; @@ -584,3 +584,116 @@ static uint16_t chunkIndex; } // End of "if ( sweepStep >= sweepPoints )" } // End of "doSweepLow" + + +/* + * "DisplayInfo" - Draws the background text around the checkerboard. Called + * when a setting is changed to set axis labels and top info bar + */ + +void DisplayBandscopeInfo () +{ +const char *averageText[] = { " OFF", " MIN", " MAX", " 2", " 4", " 8" }; +const char *referenceOutText[] = { " 30", " 15", " 10", " 4", " 3", " 2", " 1" }; + +double fStart; +double fCenter; +double fStop; + +// enum { SA_LOW_RANGE, SA_HIGH_RANGE, SIG_GEN_LOW_RANGE, SIG_GEN_HIGH_RANGE, IF_SWEEP, ZERO_SPAN_LOW_RANGE, ZERO_SPAN_HIGH_RANGE, TRACKING_GENERATOR }; + tSprite.fillSprite ( BLACK ); + tSprite.setTextColor ( WHITE ); + + +/* + * Update frequency labels at bottom if changed + */ + + tft.setTextColor ( WHITE,BLACK ); + tft.setTextSize ( 1 ); + + fStart = (double)( setting.BandscopeStart / 1000000.0 ); // Start freq + fCenter = (double)( ( setting.BandscopeStart + setting.BandscopeSpan/2.0 ) / 1000000.0 ); + fStop = (double)( (setting.BandscopeStart + setting.BandscopeSpan ) / 1000000.0 ) ; // Stop freq + + if ( old_startFreq != fStart || old_stopFreq != fStop ) + { + Serial.printf("DisplayBandscopeInfo fStart %f; old_startFreq %f \n", fStart, old_startFreq); + Serial.printf("DisplayBandscopeInfo fStop %f; old_stopFreq %f \n", fStop, old_stopFreq); + + tft.fillRect ( X_ORIGIN, SCREEN_HEIGHT - + CHAR_HEIGHT, SCREEN_WIDTH - X_ORIGIN - 1, SCREEN_HEIGHT - 1, BLACK ); + + // Show operating mode + tft.setCursor ( X_ORIGIN + 50, SCREEN_HEIGHT - CHAR_HEIGHT ); + tft.setTextColor ( DB_COLOR ); + tft.printf ( "Mode:%s", modeText[setting.Mode] ); + tft.setTextColor ( WHITE ); + + tft.setCursor ( X_ORIGIN + 2, SCREEN_HEIGHT - CHAR_HEIGHT ); + + tft.print ( fStart ); + + tft.setCursor ( SCREEN_WIDTH - 37, SCREEN_HEIGHT - CHAR_HEIGHT ); + tft.print ( fStop ); + + +/* + * Show the center frequency: + */ + tft.setCursor ( SCREEN_WIDTH / 2 - 40 + X_ORIGIN, SCREEN_HEIGHT - CHAR_HEIGHT ); + tft.print ( fCenter ); + tft.print ( "(MHz)" ); + + old_startFreq = fStart; // Save current frequency range + old_stopFreq = fStop; // For next time + } + + tft.setCursor ( 220, SCREEN_HEIGHT - CHAR_HEIGHT ); // Show sweep time + tft.printf ( "%6ums", sweepMicros / 1000 ); + + +/* + * We use the "tSprite" to paint the data at the top of the screen to avoid + * flicker. + */ + + +/* + * Show marker values: + * + * The "xPos" and "yPos" arrays are the coordinates of where to place the marker data. + * + * The "posIndex" variable keeps track of the next available position for the marker + * data. If we want fixed positions for each marker, then change the "xPos" and "yPos" + * indicies to use "m". + */ + + int xPos[MARKER_COUNT] = { 20, 20, 160, 160 }; + int yPos[MARKER_COUNT] = { 0, CHAR_HEIGHT, 0, CHAR_HEIGHT }; + int posIndex = 0; + + for ( int m = 0; m < MARKER_COUNT; m++ ) + { + tSprite.setCursor ( xPos[m], yPos[m] ); + if (( marker[m].isEnabled()) && ( setting.ShowSweep || setting.Average != AV_OFF )) + { + tSprite.setTextColor ( WHITE ); + tSprite.printf ( "%u:%5.1fdBm %8.4fMHz", marker[m].Index()+1, + rssiTodBm ( oldPeaks[m].Level ), oldPeaks[m].Freq / 1000000.0 ); + } + else + { + tSprite.setTextColor ( DARKGREY ); + tSprite.printf ( "%u:", marker[m].Index()+1 ); + } + posIndex++; + } + + int x = tSprite.width () - 45; + tSprite.setTextColor ( WHITE ); + + tSprite.pushSprite ( X_ORIGIN, 0 ); // Write sprite to the display + + updateSidebar = false; +} // End of "DisplayBandscopeInfo" diff --git a/simpleSA.ino b/simpleSA.ino index 4e163d7..bfae0ca 100644 --- a/simpleSA.ino +++ b/simpleSA.ino @@ -361,7 +361,7 @@ static JsonArray Points = jsonDocument.createNestedArray ( "Points" ); // add Po uint16_t tinySA_mode = SA_LOW_RANGE; // Low frequency range -const char *modeText[] = { "SALo", "SAHi", "SGLo", "SGHi", "IFSw", "0SpL", "0SpH", "TrGn" }; // For mode display +const char *modeText[] = { "SALo", "SAHi", "SGLo", "SGHi", "IFSw", "0SpL", "0SpH", "TrGn", "Band" }; // For mode display float bandwidth; // The current bandwidth (not * 10) unsigned long delaytime = 2000; // M0WID - changed to microseconds and moved here @@ -448,8 +448,8 @@ static int old_settingAttenuate = -1000; static int old_settingPowerGrid = -1000; static int old_settingMax = -1; static int old_settingMin = -1; -static long old_startFreq = -1; -static long old_stopFreq = -1; +static double old_startFreq = -1; +static double old_stopFreq = -1; static int ownrbw = 0; static int old_ownrbw = -1; static int vbw = 0; @@ -1331,8 +1331,16 @@ void RedrawHisto () old_settingAverage = -1; old_settingSpur = -100; ClearDisplay(); - DisplayInfo(); - DrawFullCheckerBoard(); + switch (tinySA_mode) { + case BANDSCOPE: + DisplayBandscopeInfo(); + break; + + default: + DisplayInfo(); + DrawFullCheckerBoard(); + break; + } }