mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-03-28 17:42:59 +01:00
Merge branch 'main' of https://github.com/Genaker/LoraSA into rtl-sdr
This commit is contained in:
122
src/main.cpp
122
src/main.cpp
@@ -262,6 +262,15 @@ void sendBTData(float heading, float rssi)
|
||||
#include <LiLyGo.h>
|
||||
#endif // end LILYGO
|
||||
|
||||
#include <bus.h>
|
||||
#include <heading.h>
|
||||
#include <radio.h>
|
||||
|
||||
DroneHeading droneHeading;
|
||||
Compass *compass = NULL;
|
||||
|
||||
RadioModule *radio2;
|
||||
|
||||
#define BT_SCAN_DELAY 60 * 1 * 1000
|
||||
#define WF_SCAN_DELAY 60 * 2 * 1000
|
||||
long noDevicesMillis = 0, cycleCnt = 0;
|
||||
@@ -813,6 +822,7 @@ void osdProcess()
|
||||
|
||||
Config config;
|
||||
|
||||
#ifdef USING_LR1121
|
||||
void setLRFreq(float freq)
|
||||
{
|
||||
bool skipCalibration = false;
|
||||
@@ -838,6 +848,7 @@ void setLRFreq(float freq)
|
||||
radio.freqMHz = freq;
|
||||
radio.highFreq = (freq > 1000.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
float getRSSI(void *param)
|
||||
{
|
||||
@@ -1057,6 +1068,25 @@ void init_radio()
|
||||
setFrequency(CONF_FREQ_BEGIN);
|
||||
|
||||
delay(100);
|
||||
|
||||
if (config.radio2.enabled && config.radio2.module.equalsIgnoreCase("SX1262"))
|
||||
{
|
||||
radio2 = new SX1262Module(config.radio2);
|
||||
state = radio2->beginScan(CONF_FREQ_BEGIN, BANDWIDTH, RADIOLIB_SHAPING_NONE);
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
both.println("Initialized additional module OK");
|
||||
radio2->setRxBandwidth(BANDWIDTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.printf("Error initializing additional module: %d\n", state);
|
||||
if (state == RADIOLIB_ERR_CHIP_NOT_FOUND)
|
||||
{
|
||||
Serial.println("Radio2: CHIP NOT FOUND");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct frequency_scan_result
|
||||
@@ -1088,12 +1118,19 @@ void eventListenerForReport(void *arg, Event &e)
|
||||
frequency_scan_result.readings_sz = frequency_scan_result.dump.sz + 1;
|
||||
uint32_t *f = new uint32_t[frequency_scan_result.readings_sz];
|
||||
int16_t *r = new int16_t[frequency_scan_result.readings_sz];
|
||||
int16_t *r2 = radio2 ? new int16_t[frequency_scan_result.readings_sz] : NULL;
|
||||
|
||||
if (old_sz > 0)
|
||||
{
|
||||
memcpy(f, frequency_scan_result.dump.freqs_khz,
|
||||
old_sz * sizeof(uint32_t));
|
||||
memcpy(r, frequency_scan_result.dump.rssis, old_sz * sizeof(int16_t));
|
||||
if (radio2)
|
||||
{
|
||||
memcpy(r2, frequency_scan_result.dump.rssis2,
|
||||
old_sz * sizeof(int16_t));
|
||||
delete[] frequency_scan_result.dump.rssis2;
|
||||
}
|
||||
|
||||
delete[] frequency_scan_result.dump.freqs_khz;
|
||||
delete[] frequency_scan_result.dump.rssis;
|
||||
@@ -1101,12 +1138,16 @@ void eventListenerForReport(void *arg, Event &e)
|
||||
|
||||
frequency_scan_result.dump.freqs_khz = f;
|
||||
frequency_scan_result.dump.rssis = r;
|
||||
frequency_scan_result.dump.rssis2 = r2;
|
||||
}
|
||||
|
||||
frequency_scan_result.dump.freqs_khz[frequency_scan_result.dump.sz] =
|
||||
e.detected.freq * 1000; // convert to kHz
|
||||
frequency_scan_result.dump.rssis[frequency_scan_result.dump.sz] =
|
||||
max(e.detected.rssi, -999.0f);
|
||||
if (radio2)
|
||||
frequency_scan_result.dump.rssis2[frequency_scan_result.dump.sz] =
|
||||
max(e.detected.rssi2, -999.0f);
|
||||
frequency_scan_result.dump.sz++;
|
||||
|
||||
if (e.epoch != frequency_scan_result.last_epoch ||
|
||||
@@ -1529,6 +1570,31 @@ void setup(void)
|
||||
wf_start = millis();
|
||||
|
||||
config = Config::init();
|
||||
#if defined(HAS_SDCARD)
|
||||
SD.end();
|
||||
SDCardSPI.end(); // end SPI before other uses, eg radio2 over SPI
|
||||
#endif
|
||||
|
||||
pinMode(LED, OUTPUT);
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
pinMode(REB_PIN, OUTPUT);
|
||||
heltec_setup();
|
||||
|
||||
if (!initUARTs(config))
|
||||
{
|
||||
Serial.println("Failed to initialize UARTs");
|
||||
}
|
||||
|
||||
if (!initSPIs(config))
|
||||
{
|
||||
Serial.println("Failed to initialize SPIs");
|
||||
}
|
||||
|
||||
if (!initWires(config))
|
||||
{
|
||||
Serial.println("Failed to initialize I2Cs");
|
||||
}
|
||||
|
||||
r.comms_initialized = Comms::initComms(config);
|
||||
if (r.comms_initialized)
|
||||
{
|
||||
@@ -1539,11 +1605,6 @@ void setup(void)
|
||||
Serial.println("Comms did not initialize");
|
||||
}
|
||||
|
||||
pinMode(LED, OUTPUT);
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
pinMode(REB_PIN, OUTPUT);
|
||||
heltec_setup();
|
||||
|
||||
#ifdef JOYSTICK_ENABLED
|
||||
calibrate_joy();
|
||||
pinMode(JOY_BTN_PIN, INPUT_PULLUP);
|
||||
@@ -1769,6 +1830,29 @@ void setup(void)
|
||||
|
||||
#endif
|
||||
|
||||
if (wireDevices & QMC5883L || wire1Devices & QMC5883L)
|
||||
{
|
||||
compass = new QMC5883LCompass(wireDevices & QMC5883L ? Wire : Wire1);
|
||||
}
|
||||
|
||||
if (compass)
|
||||
{
|
||||
if (!compass->begin())
|
||||
{
|
||||
Serial.println("Failed to initialize Compass");
|
||||
}
|
||||
|
||||
String err = compass->selfTest();
|
||||
if (err.startsWith("OK\n"))
|
||||
{
|
||||
Serial.printf("Compass self-test passed: %s\n", err.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.printf("Compass self-sets failed: %s\n", err.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UPTIME_CLOCK
|
||||
uptime = new UptimeClock(display, millis());
|
||||
#endif
|
||||
@@ -2149,6 +2233,9 @@ void sendMessage(RoutedMessage &m)
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case HEADING:
|
||||
droneHeading.setHeading(millis(), m.message->payload.heading.heading);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2259,6 +2346,7 @@ void doScan();
|
||||
void reportScan();
|
||||
long calStart = 0;
|
||||
|
||||
#ifdef COMPASS_ENABLED
|
||||
float getCompassHeading()
|
||||
{
|
||||
if (calStart == 0)
|
||||
@@ -2360,6 +2448,7 @@ float getCompassHeading()
|
||||
return headingDegrees;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
float historicalCompassRssi[STEPS] = {999};
|
||||
int compassCounter = 0;
|
||||
@@ -2383,6 +2472,12 @@ void loop(void)
|
||||
delete mess.message;
|
||||
}
|
||||
|
||||
if (compass != NULL)
|
||||
{
|
||||
int16_t heading = compass->heading();
|
||||
Serial.printf("Heading: %" PRIi16 "\n", heading);
|
||||
}
|
||||
|
||||
if (!config.is_host)
|
||||
{
|
||||
doScan();
|
||||
@@ -2778,6 +2873,14 @@ void doScan()
|
||||
int display_x = x / SCAN_RBW_FACTOR;
|
||||
freqX[(int)r.current_frequency] = display_x;
|
||||
setFrequency(curr_freq / 1000.0);
|
||||
if (radio2 != NULL)
|
||||
{
|
||||
state = radio2->setFrequency(curr_freq / 1000.0);
|
||||
if (state != RADIOLIB_ERR_NONE)
|
||||
{
|
||||
Serial.printf("Radio2: Failed to set freq: %d\n", state);
|
||||
}
|
||||
}
|
||||
|
||||
LOG("Step:%d Freq: %f\n", x, r.current_frequency);
|
||||
// SpectralScan Method
|
||||
@@ -2809,6 +2912,8 @@ void doScan()
|
||||
#endif
|
||||
#ifdef METHOD_RSSI
|
||||
// Spectrum analyzer using getRSSI
|
||||
float rssi2 = -999;
|
||||
|
||||
{
|
||||
LOG("METHOD RSSI");
|
||||
|
||||
@@ -2828,6 +2933,7 @@ void doScan()
|
||||
else
|
||||
g = &getRSSI;
|
||||
uint16_t max_rssi = 120;
|
||||
|
||||
// Scan if not in the ignore list
|
||||
if (ignoredFreq.find((int)r.current_frequency) == ignoredFreq.end())
|
||||
{
|
||||
@@ -2839,6 +2945,11 @@ void doScan()
|
||||
{
|
||||
xRSSI[display_x] = (int)max_rssi;
|
||||
}
|
||||
|
||||
for (int i = 0; radio2 != NULL && i < samples; i++)
|
||||
{
|
||||
rssi2 = max(rssi2, radio2->getRSSI());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2874,6 +2985,7 @@ void doScan()
|
||||
Event event = r.detect(result, filtered_result,
|
||||
RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE, samples);
|
||||
event.time_ms = millis();
|
||||
event.detected.rssi2 = rssi2;
|
||||
|
||||
size_t detected_at = event.detected.detected_at;
|
||||
if (max_rssi_x > detected_at)
|
||||
|
||||
Reference in New Issue
Block a user