diff --git a/IFsweep.ino b/IFsweep.ino index 7558f12..8ea612a 100644 --- a/IFsweep.ino +++ b/IFsweep.ino @@ -24,15 +24,6 @@ void initIF_Sweep() tinySA_mode = IF_SWEEP; setting.Mode = tinySA_mode; -// Turn off track gen -#ifdef TG_IF_INSTALLED - tg_if.RxMode(); -#endif - -#ifdef TG_LO_INSTALLED - tg_lo.RxMode(); -#endif - ResetIFsweepMenuStack(); // Put menu stack back to root level } diff --git a/RXsweep.ino b/RXsweep.ino index 5c8acf0..9902727 100644 --- a/RXsweep.ino +++ b/RXsweep.ino @@ -26,16 +26,6 @@ void initRX_Sweep() tinySA_mode = RX_SWEEP; setting.Mode = tinySA_mode; -// Turn off track gen -#ifdef TG_IF_INSTALLED - tg_if.RxMode(); -#endif - -#ifdef TG_LO_INSTALLED - tg_lo.RxMode(); -#endif - - ResetRXsweepMenuStack(); // Put menu stack back to root level } @@ -75,7 +65,6 @@ static uint16_t lastMinRSSI; // Minimum level for the previous sweep static bool jsonDocInitialised = false; static uint16_t chunkIndex; -static double bpfCalibrations[MAX_SI4432_FILTERS]; // temporary storage for calibration values static uint16_t bpfCalFirstSweepDone; /* * If paused and at the start of a sweep then do nothing @@ -103,7 +92,7 @@ static uint16_t bpfCalFirstSweepDone; { bpfCalibrate = false; currentRBW10 = setting.Bandwidth10; - // savebpfCal(); + SaveBpfCalibration(); Serial.println("bpfCalibration done"); } else // not reached end of filters diff --git a/SigLo.ino b/SigLo.ino index 2ab1528..683460d 100644 --- a/SigLo.ino +++ b/SigLo.ino @@ -26,17 +26,6 @@ void initSigLow() xmit.SetOffset ( 0 ); // make sure frequency offset registers are zero rcvr.SetOffset ( 0 ); -#ifdef TG_IF_INSTALLED - if (tgIF_OK) { - tg_if.RxMode ( ); // turn off the IF oscillator in tracking generator - } -#endif - -#ifdef TG_LO_INSTALLED - if (tgLO_OK) { - tg_lo.RxMode ( ); // turn off the Local Oscillator in tracking generator - } -#endif int showUpDownButtons = 0; #ifdef SHOW_FREQ_UP_DOWN_BUTTONS diff --git a/SweepLo.ino b/SweepLo.ino index ec76da8..63a45ad 100644 --- a/SweepLo.ino +++ b/SweepLo.ino @@ -168,28 +168,44 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 pushSettings (); #endif // #ifdef USE_WIFI -#ifdef TG_IF_INSTALLED +#if defined( TG_IF_INSTALLED ) && !defined( TG_LO_INSTALLED ) if (tgIF_OK && (trackGenSetting.Mode == 1) ) + { tg_if.TxMode ( trackGenSetting.IF_Drive ); // Set tracking generator IF on + Serial.println("tgif turned on"); + delayMicroseconds(300); + } else tg_if.RxMode(); #endif -#ifdef TG_LO_INSTALLED - if (tgLO_OK && (trackGenSetting.Mode == 1) ) - tg_lo.TxMode ( trackGenSetting.LO_Drive ); // Set tracking generator LO on - else - tg_lo.RxMode(); -#endif #if defined(TG_IF_INSTALLED) && defined(TG_LO_INSTALLED) - if (tgLO_OK && tgIF_OK && (trackGenSetting.Mode == 2) ) // tracking gen as signal generator + if (tgLO_OK && tgIF_OK) { - tg_if.SetFrequency ( setting.IF_Freq + trackGenSetting.Offset ); - tg_lo.SetFrequency ( setting.IF_Freq + trackGenSetting.Offset + trackGenSetting.Frequency ); - tg_lo.TxMode ( trackGenSetting.LO_Drive ); // Set tracking generator LO on - tg_if.TxMode ( trackGenSetting.IF_Drive ); // Set tracking generator IF on + switch ( trackGenSetting.Mode ) + { + case 0: // off + tg_if.RxMode(); + tg_lo.RxMode(); + break; + + case 1: // tracking + tg_if.TxMode ( trackGenSetting.IF_Drive ); // Set tracking generator IF on + tg_lo.TxMode ( trackGenSetting.LO_Drive ); // Set tracking generator LO on + break; + + case 2: // generator mode + tg_lo.TxMode ( trackGenSetting.LO_Drive ); // Set tracking generator LO on + tg_if.TxMode ( trackGenSetting.IF_Drive ); // Set tracking generator IF on + tg_lo.SetFrequency ( setting.IF_Freq + trackGenSetting.Offset + trackGenSetting.Frequency ); + break; + + default: + Serial.println("Invalid track gen mode in Sweeplo"); + } } + #endif } // initSweep || changedSetting @@ -242,7 +258,10 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 #ifdef TG_IF_INSTALLED if (tgIF_OK && (trackGenSetting.Mode == 1) ) + { tg_if.SetFrequency ( tgIF ); // Set tracking generator IF for the sweep + //Serial.printf("tgif set to %i Hz\n", tgIF); + } #endif } @@ -250,7 +269,10 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 #ifdef TG_LO_INSTALLED if (tgLO_OK && (trackGenSetting.Mode == 1) ) + { tg_lo.SetFrequency ( tgIF + autoSweepFreq ); // Set tracking generator LO + //Serial.printf("tglo set to %i Hz at start of sweep\n", tgIF + autoSweepFreq); + } #endif setFreqMicros = micros(); // Store the time the frequency was changed @@ -409,6 +431,7 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 if (tgLO_OK && (trackGenSetting.Mode == 1) ) { tg_lo.SetFrequency ( f + trackGenSetting.Offset ); // Set tracking generator LO + } #endif @@ -416,7 +439,7 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 #ifdef TG_LO_INSTALLED // if (trackGenSetting.Mode == 1) -// Serial.printf("tglo %i @ %i\n", tg_lo.GetFrequency(), setFreqMicros); +// Serial.printf("tglo %i f=%i, lo=%02X, if=%02X\n", tg_lo.ReadFrequency()- tg_if.ReadFrequency(), autoSweepFreq, tg_lo.ReadByte(REG_OFC1) & 0x0F, tg_if.ReadByte(REG_OFC1) & 0x0F ); #endif #ifdef USE_WIFI diff --git a/cmd.cpp b/cmd.cpp index b461e00..d00d680 100644 --- a/cmd.cpp +++ b/cmd.cpp @@ -42,7 +42,7 @@ extern Si4432 tg_lo; // Si4432 Transmitter object extern settings_t setting; // Structure to track & save settings extern bandpassFilter_t bandpassFilters[]; // RBW Setting data -extern int bpfCount; // Number of entries in "bandpassFilters" +extern uint16_t bpfCount; // Number of entries in "bandpassFilters" extern int changedSetting; // Something in "setting" changed extern uint16_t bpfCalibrate; // set true if a SI4432 bandpass filter calibration run is taking place diff --git a/data/index.html b/data/index.html index dbb9c43..86e2581 100644 --- a/data/index.html +++ b/data/index.html @@ -716,7 +716,7 @@ setTrackGenPower.addEventListener('change', (event) => { setTGFreq.addEventListener('change', (event) => { - sendValue("f", setTGFreq.value); + sendValue("f", setTGFreq.value * 1000000); }); store1.addEventListener('change', (event) => { @@ -1203,7 +1203,7 @@ function handleSettings (settings) } if (settings.tgFreq != oldTGFreq) { // tracking generator frequency for sig gen mode - setTGFreq.value = settings.tgFreq; + setTGFreq.value = settings.tgFreq/1000000; oldTGFreq = settings.tgFreq; } diff --git a/my_SA.h b/my_SA.h index 7065d53..610474a 100644 --- a/my_SA.h +++ b/my_SA.h @@ -12,6 +12,9 @@ #define _MY_SA_H_ // Prevent double inclusion + +//#define GLENN_BUILD + /* * The following definitions are all related to the WiFi interface. If you don't want * to use the WiFi interface, set the "USE_WIFI" definition to 'false'. diff --git a/preferences.cpp b/preferences.cpp index 593586a..9240d15 100644 --- a/preferences.cpp +++ b/preferences.cpp @@ -20,6 +20,8 @@ extern Preferences preferences; // The Preferences object - Created in the main file +extern void DisplayError ( uint8_t severity, const char *line1, const char *line2, const char *line3, const char *line4 ); + /* * "ReadConfig" - Reads the "config" (see "tinySA.h") structure from flash memory @@ -323,3 +325,73 @@ void WriteTrackGenSettings () else Serial.println ( "TrackGen saved" ); } + + +/* + * "ReadBpfCalibration" - Reads the bandpass filter calibrations from the flash memory + */ + +void ReadBpfCalibration() +{ + double tempCal[MAX_SI4432_FILTERS]; // Temporary store to check data is valid + size_t bytes; // Amount of data read + + bytes = preferences.getBytes ( "bpfCal", &tempCal, bpfCount * sizeof (bpfCalibrations[0])); + + +/* + * If the "dummy" entry is zero or what we read is the wrong size, the data is invalid. + * + * + * It might be better if we included a "magic" element that is a specific number or maybe + * even a short string. + * + * If the size isn't correct, it could be that the size of the "setting" structure was + * changed in a newer release of the code. + * + * If what we read is invalid, we store the default values in the flash memory. + */ + + if ( bytes != bpfCount * sizeof (bpfCalibrations[0]) ) + { + Serial.printf ( "Bytes got = %i - aiming for %i. No bandpass filter calibrations saved\n", + bytes, bpfCount * sizeof (bpfCalibrations[0]) ); + DisplayError ( ERR_WARN, + "No Calibrations found", + "Connect ref out, goto", + "RXSweep mode then", + "Choose bpfCalibrate" ); + preferences.remove ( "bpfCal" ); // Clear any old data just in case size has changed + } + + else // Data retrieved looks valid + { + Serial.printf ( "bpf calibrations read - %i bytes, %i filters \n", bytes, bpfCount); + for (int i = 0; i < bpfCount; i++) + { + bpfCalibrations[i] = tempCal[i]; + } + } +} + + + +/* + * Save the bandpass filter calibrations to flash + */ + +void SaveBpfCalibration ( ) +{ +// double bpfCalibrations[MAX_SI4432_FILTERS]; // temporary storage for calibration values + + size_t bytes; + + bytes = preferences.putBytes ( "bpfCal", &bpfCalibrations, bpfCount * sizeof (bpfCalibrations[0]) ); + + + if ( bytes == 0 ) + Serial.println ( "Save of bandpass filter calibrations failed" ); + else + Serial.println ( "Bandpass filter calibrations saved" ); + +} diff --git a/preferences.h b/preferences.h index 19ac3df..ac309f1 100644 --- a/preferences.h +++ b/preferences.h @@ -15,10 +15,12 @@ #include "simpleSA.h" // Definitions for the entire program -extern config_t config; // Default colors, touch screen calibration, etc. -extern settings_t setting; // Scan limits and other scan parameters -extern sigGenSettings_t sigGenSetting; // parameters for sig gen mode -extern trackGenSettings_t trackGenSetting; // parameters for tracking gen mode +extern config_t config; // Default colors, touch screen calibration, etc. +extern settings_t setting; // Scan limits and other scan parameters +extern sigGenSettings_t sigGenSetting; // parameters for sig gen mode +extern trackGenSettings_t trackGenSetting; // parameters for tracking gen mode +extern uint16_t bpfCount; // no of bandpass filters available +extern double bpfCalibrations[MAX_SI4432_FILTERS]; // temporary storage for calibration values extern void ReadConfig (); @@ -35,3 +37,6 @@ extern void WriteTrackGenSettings (); extern void Save ( uint8_t loc ); extern void Recall ( uint8_t loc ); + +extern void ReadBpfCalibration(); +extern void SaveBpfCalibration(); diff --git a/si4432.cpp b/si4432.cpp index 82e9c77..0591ee4 100644 --- a/si4432.cpp +++ b/si4432.cpp @@ -19,69 +19,72 @@ /* * The "bandpassFilters" array contains a selection of the standard bandpass settings. - * + * Values for status: enum{DO_NOT_USE, USE_IN_AUTO, AVAILABLE} + * Filters with strange behaviour are marked as DO_NOT_USE + * Filters with large dip in passband or not very good shape are AVAILABLE + * Filters with 0.5dB or 1dB dip in passband are USE_IN_AUTO */ bandpassFilter_t Si4432::_bandpassFilters[] { -// bw*10, settle, dwn3, ndec, filset - { 26, 6800, 0, 5, 1 }, // 0 "AUTO" selection possibility - { 28, 6600, 0, 5, 2 }, // 1 "AUTO" selection possibility - { 31, 6600, 0, 5, 3 }, // 2 If user selects 3KHz -> 3.1KHz actual - { 32, 6600, 0, 5, 4 }, // 3 "AUTO" selection possibility - { 37, 6600, 0, 5, 5 }, // 4 "AUTO" selection possibility - { 42, 6600, 0, 5, 6 }, // 5 "AUTO" selection possibility - { 45, 6600, 0, 5, 7 }, // 6 "AUTO" selection possibility - { 49, 5000, 0, 4, 1 }, // 7 "AUTO" selection possibility - { 54, 4200, 0, 4, 2 }, // 8 "AUTO" selection possibility - { 59, 3700, 0, 4, 3 }, // 9 "AUTO" selection possibility - { 61, 3500, 0, 4, 4 }, // 10 "AUTO" selection possibility - { 72, 3300, 0, 4, 5 }, // 11 "AUTO" selection possibility - { 82, 3300, 0, 4, 6 }, // 12 "AUTO" selection possibility - { 88, 3300, 0, 4, 7 }, // 13 "AUTO" selection possibility - { 95, 3300, 0, 3, 1 }, // 14 "AUTO" selection possibility - { 106, 2500, 0, 3, 2 }, // 15 If user selects 10KHz -> 10.6KHz actual - { 115, 2500, 0, 3, 3 }, // 16 "AUTO" selection possibility - { 121, 2500, 0, 3, 4 }, // 17 "AUTO" selection possibility - { 142, 2500, 0, 3, 5 }, // 18 "AUTO" selection possibility - { 162, 2000, 0, 3, 6 }, // 19 "AUTO" selection possibility - { 175, 2000, 0, 3, 7 }, // 20 "AUTO" selection possibility - { 189, 1600, 0, 2, 1 }, // 21 "AUTO" selection possibility - { 210, 1600, 0, 2, 2 }, // 22 "AUTO" selection possibility - { 227, 1500, 0, 2, 3 }, // 23 "AUTO" selection possibility - { 240, 1400, 0, 2, 4 }, // 24 "AUTO" selection possibility - { 282, 1000, 0, 2, 5 }, // 25 "AUTO" selection possibility - { 322, 1000, 0, 2, 6 }, // 26 If user selects 30KHz -> 32.2KHz actual - { 347, 1000, 0, 2, 7 }, // 27 "AUTO" selection possibility - { 377, 1000, 0, 1, 1 }, // 28 "AUTO" selection possibility - { 417, 1000, 0, 1, 2 }, // 29 "AUTO" selection possibility - { 452, 1000, 0, 1, 3 }, // 30 "AUTO" selection possibility - { 479, 1000, 0, 1, 4 }, // 31 "AUTO" selection possibility - { 562, 700, 0, 1, 5 }, // 32 "AUTO" selection possibility - { 641, 700, 0, 1, 6 }, // 33 "AUTO" selection possibility - { 692, 700, 0, 1, 7 }, // 34 "AUTO" selection possibility - { 752, 700, 0, 0, 1 }, // 35 "AUTO" selection possibility - { 832, 600, 0, 0, 2 }, // 36 "AUTO" selection possibility - { 900, 600, 0, 0, 3 }, // 37 "AUTO" selection possibility - { 953, 600, 0, 0, 4 }, // 38 "AUTO" selection possibility - { 1121, 500, 0, 0, 5 }, // 39 If user selects 100KHz -> 112.1KHz actual - { 1279, 600, 0, 0, 6 }, // 40 "AUTO" selection possibility - { 1379, 600, 0, 0, 7 }, // 41 "AUTO" selection possibility - { 1428, 600, 1, 1, 4 }, // 42 "AUTO" selection possibility - { 1678, 600, 1, 1, 5 }, // 43 "AUTO" selection possibility - { 1811, 500, 1, 1, 9 }, // 44 "AUTO" selection possibility - { 1915, 500, 1, 1, 15 }, // 45 "AUTO" selection possibility - { 2251, 500, 1, 0, 1 }, // 46 "AUTO" selection possibility - { 2488, 450, 1, 0, 2 }, // 47 "AUTO" selection possibility - { 2693, 450, 1, 0, 3 }, // 48 "AUTO" selection possibility - { 2849, 450, 1, 0, 4 }, // 49 "AUTO" selection possibility - { 3355, 400, 1, 0, 8 }, // 50 If user selects 300KHz -> 335.5KHz actual - { 3618, 300, 1, 0, 9 }, // 51 "AUTO" selection possibility - { 4202, 300, 1, 0, 10 }, // 52 "AUTO" selection possibility - { 4684, 300, 1, 0, 11 }, // 53 "AUTO" selection possibility - { 5188, 300, 1, 0, 12 }, // 54 "AUTO" selection possibility - { 5770, 300, 1, 0, 13 }, // 55 "AUTO" selection possibility - { 6207, 300, 1, 0, 14 } // 56 "AUTO" selection possibility +// bw*10, settle, dwn3, ndec, filset, status + { 26, 6800, 0, 5, 1, USE_IN_AUTO }, // 0 "AUTO" selection possibility + { 28, 6600, 0, 5, 2, USE_IN_AUTO }, // 1 "AUTO" selection possibility + { 31, 6600, 0, 5, 3, AVAILABLE }, // 2 If user selects 3KHz -> 3.1KHz actual + { 32, 6600, 0, 5, 4, AVAILABLE }, // 3 "AUTO" selection possibility + { 37, 6600, 0, 5, 5, USE_IN_AUTO }, // 4 "AUTO" selection possibility + { 42, 7000, 0, 5, 6, USE_IN_AUTO }, // 5 "AUTO" selection possibility + { 45, 6600, 0, 5, 7, AVAILABLE }, // 6 "AUTO" selection possibility + { 49, 5000, 0, 4, 1, USE_IN_AUTO }, // 7 "AUTO" selection possibility + { 54, 4200, 0, 4, 2, USE_IN_AUTO }, // 8 "AUTO" selection possibility + { 59, 3700, 0, 4, 3, AVAILABLE }, // 9 "AUTO" selection possibility + { 61, 3500, 0, 4, 4, AVAILABLE }, // 10 "AUTO" selection possibility + { 72, 3300, 0, 4, 5, USE_IN_AUTO }, // 11 "AUTO" selection possibility + { 82, 3300, 0, 4, 6, USE_IN_AUTO }, // 12 "AUTO" selection possibility + { 88, 4000, 0, 4, 7, AVAILABLE }, // 13 "AUTO" selection possibility + { 95, 3300, 0, 3, 1, USE_IN_AUTO }, // 14 "AUTO" selection possibility + { 106, 2500, 0, 3, 2, USE_IN_AUTO }, // 15 If user selects 10KHz -> 10.6KHz actual + { 115, 2500, 0, 3, 3, AVAILABLE }, // 16 "AUTO" selection possibility + { 121, 2500, 0, 3, 4, AVAILABLE }, // 17 "AUTO" selection possibility + { 142, 2500, 0, 3, 5, USE_IN_AUTO }, // 18 "AUTO" selection possibility + { 162, 2000, 0, 3, 6, USE_IN_AUTO }, // 19 "AUTO" selection possibility + { 175, 2000, 0, 3, 7, USE_IN_AUTO }, // 20 "AUTO" selection possibility + { 189, 1600, 0, 2, 1, AVAILABLE }, // 21 "AUTO" selection possibility + { 210, 1600, 0, 2, 2, USE_IN_AUTO }, // 22 "AUTO" selection possibility + { 227, 1500, 0, 2, 3, AVAILABLE }, // 23 "AUTO" selection possibility + { 240, 1400, 0, 2, 4, AVAILABLE }, // 24 "AUTO" selection possibility + { 282, 1000, 0, 2, 5, USE_IN_AUTO }, // 25 "AUTO" selection possibility + { 322, 1000, 0, 2, 6, USE_IN_AUTO }, // 26 If user selects 30KHz -> 32.2KHz actual + { 347, 1000, 0, 2, 7, USE_IN_AUTO }, // 27 "AUTO" selection possibility + { 377, 1000, 0, 1, 1, AVAILABLE }, // 28 "AUTO" selection possibility + { 417, 1000, 0, 1, 2, USE_IN_AUTO }, // 29 "AUTO" selection possibility + { 452, 1000, 0, 1, 3, AVAILABLE }, // 30 "AUTO" selection possibility + { 479, 1000, 0, 1, 4, AVAILABLE }, // 31 "AUTO" selection possibility + { 562, 700, 0, 1, 5, USE_IN_AUTO }, // 32 "AUTO" selection possibility + { 641, 700, 0, 1, 6, USE_IN_AUTO }, // 33 "AUTO" selection possibility + { 692, 700, 0, 1, 7, USE_IN_AUTO }, // 34 "AUTO" selection possibility + { 752, 700, 0, 0, 1, AVAILABLE }, // 35 "AUTO" selection possibility + { 832, 600, 0, 0, 2, USE_IN_AUTO }, // 36 "AUTO" selection possibility + { 900, 600, 0, 0, 3, AVAILABLE }, // 37 "AUTO" selection possibility + { 953, 600, 0, 0, 4, AVAILABLE }, // 38 "AUTO" selection possibility + { 1121, 500, 0, 0, 5, USE_IN_AUTO }, // 39 If user selects 100KHz -> 112.1KHz actual + { 1279, 600, 0, 0, 6, USE_IN_AUTO }, // 40 "AUTO" selection possibility + { 1379, 600, 0, 0, 7, USE_IN_AUTO }, // 41 "AUTO" selection possibility + { 1428, 600, 1, 1, 4, AVAILABLE }, // 42 "AUTO" selection possibility + { 1678, 600, 1, 1, 5, USE_IN_AUTO }, // 43 "AUTO" selection possibility + { 1811, 500, 1, 1, 9, USE_IN_AUTO }, // 44 "AUTO" selection possibility + { 1915, 500, 1, 0, 15, AVAILABLE }, // 45 "AUTO" selection possibility + { 2251, 500, 1, 0, 1, AVAILABLE }, // 46 "AUTO" selection possibility + { 2488, 450, 1, 0, 2, USE_IN_AUTO }, // 47 "AUTO" selection possibility + { 2693, 450, 1, 0, 3, AVAILABLE }, // 48 "AUTO" selection possibility + { 2849, 450, 1, 0, 4, AVAILABLE }, // 49 "AUTO" selection possibility + { 3355, 400, 1, 0, 8, AVAILABLE }, // 50 If user selects 300KHz -> 335.5KHz actual + { 3618, 300, 1, 0, 9, USE_IN_AUTO }, // 51 "AUTO" selection possibility + { 4202, 300, 1, 0, 10, USE_IN_AUTO }, // 52 "AUTO" selection possibility + { 4684, 300, 1, 0, 11, USE_IN_AUTO }, // 53 "AUTO" selection possibility + { 5188, 300, 1, 0, 12, USE_IN_AUTO }, // 54 "AUTO" selection possibility + { 5770, 300, 1, 0, 13, USE_IN_AUTO }, // 55 "AUTO" selection possibility + { 6207, 300, 1, 0, 14, AVAILABLE } // 56 "AUTO" selection possibility }; @@ -271,17 +274,43 @@ uint8_t regRead = 0; const char* unit[4] = { "RX", "TX", "TGIF", "TGLO" }; // For debugging WriteByte ( REG_OFC1, SW_RESET ); // Always perform a system reset + delay(10); while ( millis() - startTime < 2000 ) // Try for 2 seconds { regRead = ReadByte ( REG_IS2 ); - if ( ( regRead & ICHIPRDY ) && ( regRead != 0xFF ) ) // Wait for chip ready bit +//**************************************************************************** +// Bodge to get Glenn's board going! Do not include in normal release!!!! +// Glenn's LO SI4432 does not seen to send signals back to the SPI bus. +// +//**************************************************************************** + +#ifdef GLENN_BUILD + if (_cs != 5) { + if ( ( regRead & ICHIPRDY ) && ( regRead != 0xFF ) ) // Wait for chip ready bit { - Serial.printf ( " Si4432 Good to go - regRead = %02X _cs = %i\n", regRead, _cs ); + Serial.printf ( " %s Si4432 Good to go - regRead = %02X _cs = %i ", unit[_type], regRead, _cs ); + Serial.printf ( " Type %X Version %X Status %X \n", ReadByte(0), ReadByte(1), ReadByte(2)); return true; // Good to go! } - + } + else { + if ( regRead & ICHIPRDY ) // Wait for chip ready bit + { + Serial.printf ( " LO Si4432 Good to go - regRead = %02X _cs = %i ", regRead, _cs ); + Serial.printf ( " Type %X Version %X Status %X \n", ReadByte(0), ReadByte(1), ReadByte(2)); + return true; // Good to go! + } + } +#else + if ( ( regRead & ICHIPRDY ) && ( regRead != 0xFF ) ) // Wait for chip ready bit + { + Serial.printf ( " %s Si4432 Good to go - regRead = %02X _cs = %i ", unit[_type], regRead, _cs ); + Serial.printf ( " Type %X Version %X Status %X \n", ReadByte(0), ReadByte(1), ReadByte(2)); + return true; // Good to go! + } +#endif /* * If we don't have "ICHIPRDY" yet, only display the error message once per second. @@ -289,11 +318,11 @@ const char* unit[4] = { "RX", "TX", "TGIF", "TGLO" }; // For debugging if ((( millis () - startTime ) % 1000 ) == 0 ) { -// Serial.print ( "Waiting for " ); -// Serial.print ( unit[_type] ); -// Serial.print ( " Si4432 - regRead " ); -// Serial.println ( regRead ); -// Serial.printf ( "Type %X Version %X Status %X \n", ReadByte(0), ReadByte(1), ReadByte(2)); + Serial.print ( "Waiting for " ); + Serial.print ( unit[_type] ); + Serial.print ( " Si4432 - regRead " ); + Serial.println ( regRead ); + Serial.printf ( "Type %X Version %X Status %X \n", ReadByte(0), ReadByte(1), ReadByte(2)); } delay ( 1 ); // Slight pause @@ -570,6 +599,7 @@ void Si4432::SetOffset ( int32_t offset ) * and returns the actual value chosen as well as the required delay to allow the * FIR filter in the SI4432 to settle (in microseconds) Delay time is longer for * narrower bandwidths. + * Filters flagged as DO_NOT_USE will not be chosen */ float Si4432::SetRBW ( float reqBandwidth10, unsigned long* delaytime_p ) // "reqBandwidth" in kHz * 10 @@ -594,7 +624,8 @@ float Si4432::SetRBW ( float reqBandwidth10, unsigned long* delaytime_p ) // "re * find the setting that is nearest (and above) the requested setting. */ else - while (( _bandpassFilters[filter-1].bandwidth10 > reqBandwidth10 - 0.01 ) && ( filter > 0 )) + while ( ( ( _bandpassFilters[filter-1].bandwidth10 > reqBandwidth10 - 0.01 ) && ( filter > 0 ) ) + || (_bandpassFilters[filter].Status == DO_NOT_USE ) ) filter--; // Serial.printf ( "Required = %f, filter = %i\n", reqBandwidth10, filter); Serial.println ( filter ); diff --git a/si4432.h b/si4432.h index 07a34c5..4fbeaf7 100644 --- a/si4432.h +++ b/si4432.h @@ -155,6 +155,8 @@ #define REG_NCF0 0x77 // Nominal Carrier Frequency 0 +enum {DO_NOT_USE, USE_IN_AUTO, AVAILABLE}; // bandpass filter status values + typedef struct { float bandwidth10; // Just one decimal point to save space (kHz * 10) @@ -162,6 +164,7 @@ typedef struct uint16_t dwn3_bypass; // Bypass decimate by 3 stage if set uint16_t ndec_exp; // IF Filter decimation rate = 2^ndec_exp. larger number -> lower bandwidth (range 0-5) uint16_t filset; // IF Filter coefficient set. Predefined FIR filter sets (1-15) + uint16_t Status; // 0 = DO_NOT_USE, 1 = USE_IN_AUTO, 2 = AVAILABLE } bandpassFilter_t; class Si4432 diff --git a/simpleSA.ino b/simpleSA.ino index 5e7db78..6fe03b5 100644 --- a/simpleSA.ino +++ b/simpleSA.ino @@ -165,10 +165,14 @@ #include "simpleSA_wifi.h" // Our WiFI definitions #include // ESP32 WiFi support library #include // Asynchronous TCP library for Espressif MCUs - #include "SPIFFS.h" // ESP32 built-in "file system" + #include + #include + #include #endif +#include "SPIFFS.h" // ESP32 built-in "file system" + #include // TFT_eSPI library #include // Library to save and restore configuration information #include "preferences.h" // Functions to write/read settings and config @@ -411,6 +415,7 @@ double dBadjust; // Sum of attenuation, external gain, calibration offset uint16_t bpfCalibrate; // set true if a SI4432 bandpass filter calibration run is taking place uint16_t bpfCount; // no of bandpass filters available +double bpfCalibrations[MAX_SI4432_FILTERS]; // temporary storage for calibration values /* * Variables for offset frequency tuning (used in Bandscope mode) @@ -612,7 +617,6 @@ bool fsStatus = false; // True if SPIFFS loads ok setting.ShowStorage = false; // Display stored scan (on or off) setting.SubtractStorage = false; // Subtract stored scan (on or off) - /* * The touch screen needs to be calibrated. In previous versions, the instructions * were to un-comment the call to the "TouchCalibrate" here the first time you @@ -701,6 +705,8 @@ bool fsStatus = false; // True if SPIFFS loads ok rcvr.SetPreampGain ( setting.PreampGain ); bpfCount = rcvr.GetBandpassFilterCount(); // no of RBW filters available + ReadBpfCalibration(); // Get bandpass filter (RBW) calibrations + // If the tracking generator IF SI4432 is defined, then check to see if it is connected tgIF_OK = false; @@ -799,6 +805,54 @@ bool fsStatus = false; // True if SPIFFS loads ok buildServer (); +/* + * OTA programming + * + * Port defaults to 3232 + * ArduinoOTA.setPort(3232) + + * Hostname defaults to esp3232-[MAC] + * ArduinoOTA.setHostname("myesp32"); + + * No authentication by default + * ArduinoOTA.setPassword("admin"); + + * Password can be set with it's md5 value as well + * MD5(admin) = 21232f297a57a5a743894a0e4a801fc3 + * ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3"); + * #define WIFI_SSID ":)" // SSID of your WiFi if not using access point + * #define WIFI_PASSWORD "S0ftR0ckRXTX" // Password for your WiFi + */ + + ArduinoOTA + .onStart([]() { + String type; + if (ArduinoOTA.getCommand() == U_FLASH) + type = "sketch"; + else // U_SPIFFS + type = "filesystem"; + // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() + SPIFFS.end(); + Serial.println("Start updating " + type); + }) + .onEnd([]() { + Serial.println("\nEnd"); + }) + .onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }) + .onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println("End Failed"); + }); + + ArduinoOTA.begin(); + + IPAddress ipAddress = WiFi.localIP (); // Get our IP address Serial.print ( "Setup - WiFi access point started - browse to http://" ); @@ -871,6 +925,7 @@ loopStartMicros = micros(); lastWebsocketMicros = loopStartMicros; } + ArduinoOTA.handle(); // check if OTA programming requested #endif CheckCommand (); // Anything from the serial input? @@ -1106,19 +1161,19 @@ void init_sweep() xmit.SetDrive ( setting.Drive ); // Set transmitter power level rcvr.SetPreampGain ( setting.PreampGain ); -#ifdef TG_IF_INSTALLED +#ifdef SI_TG_IF_CS if (tgIF_OK) { - tg_if.TxMode ( trackGenSetting.IF_Drive ); // turn on the IF oscillator in tracking generator + tg_if.TxMode ( trackGenSetting.IF_Drive ); // turn on the IF oscillator in tracking generator } #endif -#ifdef TG_LO_INSTALLED +#ifdef SI_TG_LO_CS if (tgLO_OK) { - tg_lo.TxMode ( trackGenSetting.LO_Drive ); // turn on the Local Oscillator in tracking generator + tg_lo.TxMode ( trackGenSetting.LO_Drive ); // turn on the Local Oscillator in tracking generator } #endif - + sweepStartDone = false; // Make sure this initialize is only done once per sweep initSweep = true; } diff --git a/simpleSA_wifi.cpp b/simpleSA_wifi.cpp index 6b53c10..1d4baff 100644 --- a/simpleSA_wifi.cpp +++ b/simpleSA_wifi.cpp @@ -36,12 +36,12 @@ extern uint16_t waterfallHeight; extern unsigned long sweepMicros; // To report the scan time -extern int bpfCount; // Number of elements in the bandpassFilters array -extern int updateSidebar; // Flag to indicate no of clients has changed -extern void ClearDisplay (); -extern void DisplayError ( uint8_t severity, const char *l1, const char *l2, const char *l3, const char *l4 ); +extern uint16_t bpfCount; // Number of elements in the bandpassFilters array +extern int updateSidebar; // Flag to indicate no of clients has changed +extern void ClearDisplay (); +extern void DisplayError ( uint8_t severity, const char *l1, const char *l2, const char *l3, const char *l4 ); -extern void setMode (uint16_t newMode); +extern void setMode (uint16_t newMode); /* * In Version 1.8, the transmitter and receiver Si4432 modules are implemented as