diff --git a/include/LoRaBoards.cpp b/lib/loraboards/LoRaBoards.cpp similarity index 100% rename from include/LoRaBoards.cpp rename to lib/loraboards/LoRaBoards.cpp diff --git a/include/LoRaBoards.h b/lib/loraboards/LoRaBoards.h similarity index 100% rename from include/LoRaBoards.h rename to lib/loraboards/LoRaBoards.h diff --git a/include/utilities.h b/lib/loraboards/utilities.h similarity index 100% rename from include/utilities.h rename to lib/loraboards/utilities.h diff --git a/platformio.ini b/platformio.ini index 5ff09ab..997258b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,6 +63,8 @@ board_build.f_cpu = 240000000 lib_deps = ropg/Heltec_ESP32_LoRa_v3@^0.9.1 RadioLib + U8g2 + XPowersLib build_flags = -DLILYGO -DT3_S3_V1_2_SX1280_PA diff --git a/src/main.cpp b/src/main.cpp index c4f3573..fdcd374 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ https://jgromes.github.io/RadioLib/ */ -// #define HELTEC_NO_DISPLAY +// #define HELTEC_NO_DISPLAY #include @@ -36,7 +36,8 @@ // library internals. #define RADIOLIB_GODMODE (1) -#include "radioScan/radioScan.h" +#include +#include #ifndef LILYGO #include @@ -354,7 +355,6 @@ void init_radio() // initialize SX1262 FSK modem at the initial frequency both.println("Init radio"); #ifdef USING_SX1280PA - // radio.begin(); state = radio.beginGFSK(FREQ_BEGIN); #else state = radio.beginFSK(FREQ_BEGIN); @@ -423,6 +423,10 @@ void init_radio() void setup(void) { + setupBoards(); + delay(5000); + Serial.println("setup is done"); + // LED brightness heltec_led(25); #ifdef OSD_ENABLED diff --git a/src/radioScan/radioScan.cpp b/src/radioScan/radioScan.cpp deleted file mode 100644 index a5a2332..0000000 --- a/src/radioScan/radioScan.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef LORASA_CORE_CPP -#define LORASA_CORE_CPP - -#include "radioScan.h" -#include -#include -#include - -uint16_t Scan::rssiMethod(size_t samples, uint16_t *result, size_t res_size) -{ - float scale((float)res_size / (HI_RSSI_THRESHOLD - LO_RSSI_THRESHOLD + 0.1)); - - memset(result, 0, res_size * sizeof(uint16_t)); - int result_index = 0; - - // - uint16_t max_signal = 65535; - // N of samples - for (int r = 0; r < samples; r++) - { - float rssi = getRSSI(); - if (rssi < -65535) - rssi = -65535; - - uint16_t abs_rssi = abs(rssi); - if (abs_rssi < max_signal) - { - max_signal = abs_rssi; - } - // ToDO: check if 4 is correct value for 33 power bins - // Now we have more space because we are ignoring low dB values - // we can / 3 default 4 - if (RSSI_OUTPUT_FORMULA == 1) - { - result_index = - /// still not clear formula but it works - uint8_t(abs(rssi) / 4); - } - else if (RSSI_OUTPUT_FORMULA == 2) - { - if (rssi > HI_RSSI_THRESHOLD) - { - rssi = HI_RSSI_THRESHOLD; - } - else if (rssi < LO_RSSI_THRESHOLD) - { - rssi = LO_RSSI_THRESHOLD; - } - - result_index = uint8_t((HI_RSSI_THRESHOLD - rssi) * scale); - } - - if (result_index >= res_size) - { - // Maximum index possible - result_index = res_size - 1; - } - - LOG("RSSI: %f IDX: %d\n", rssi, result_index); - if (result[result_index] == 0 || result[result_index] > abs_rssi) - { - result[result_index] = abs_rssi; - } - } - - return max_signal; -} - -size_t Scan::detect(uint16_t *result, bool *filtered_result, size_t result_size, - int samples) -{ - size_t max_rssi_x = 999; - - for (int y = 0; y < result_size; y++) - { - - LOG("%i:%i,", y, result[y]); -#if !defined(FILTER_SPECTRUM_RESULTS) || FILTER_SPECTRUM_RESULTS == false - if (result[y] && result[y] != 0) - { - filtered_result[y] = 1; - } - else - { - filtered_result[y] = 0; - } -#endif - -// if samples low ~1 filter removes all values -#if FILTER_SPECTRUM_RESULTS - - filtered_result[y] = 0; - // Filter Elements without neighbors - // if RSSI method actual value is -xxx dB - if (result[y] > 0 && samples > 1) - { - // do not process 'first' and 'last' row to avoid out of index - // access. - if ((y > 0) && (y < (result_size - 2))) - { - if (((result[y + 1] != 0) && (result[y + 2] != 0)) || - (result[y - 1] != 0)) - { - filtered_result[y] = 1; - // Fill empty pixel - result[y + 1] = 1; - } - else - { - LOG("Filtered::%i,", y); - } - } - } // not filtering if samples == 1 because it will be filtered - else if (result[y] > 0 && samples == 1) - { - filtered_result[y] = 1; - } -#endif - if (filtered_result[y] && max_rssi_x > y) - { - max_rssi_x = y; - } - } - - return max_rssi_x; -} - -#endif diff --git a/src/radioScan/radioScan.h b/src/radioScan/radioScan.h deleted file mode 100644 index bfbdcf8..0000000 --- a/src/radioScan/radioScan.h +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#ifndef LORASA_CORE_H - -#define LORASA_CORE_H - -#ifdef PRINT_DEBUG -#define LOG(args...) Serial.printf(args...) -#define LOG_IF(cond, args...) \ - if (cond) \ - LOG(args...) -#elif !defined(LOG) -#define LOG(args...) -#define LOG_IF(cond, args...) -#endif - -// Output Pixel Formula -// 1 = rssi / 4, 2 = (rssi / 2) - 22 or 20 -constexpr int RSSI_OUTPUT_FORMULA = 2; - -// based on the formula for RSSI_OUTPUT_FORMULA == 2 -// -2 * (22 + RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE) < rssi =< -44 -// practice may require a better pair of thresholds -constexpr float HI_RSSI_THRESHOLD = -44.0; -constexpr float LO_RSSI_THRESHOLD = HI_RSSI_THRESHOLD - 66; - -// number of samples for RSSI method -#define SAMPLES_RSSI 12 // 21 // - -struct Scan -{ - virtual float getRSSI() = 0; - - // rssiMethod gets the data similar to the scan method, - // but uses getRSSI directly. - uint16_t rssiMethod(size_t samples, uint16_t *result, size_t res_size); - - // detect method analyses result, and produces filtered_result, marking - // those values that represent a detection event. - // It returns index that represents strongest signal at which a detection event - // occurred. - static size_t detect(uint16_t *result, bool *filtered_result, size_t result_size, - int samples); -}; - -// Remove reading without neighbors -#define FILTER_SPECTRUM_RESULTS true - -#endif diff --git a/test/test_rssi.cpp b/test/test_rssi.cpp index 519f72f..8a75b60 100644 --- a/test/test_rssi.cpp +++ b/test/test_rssi.cpp @@ -1,6 +1,6 @@ #include #define LOG(args...) printf(args) -#include "../src/radioScan/radioScan.cpp" +#include "../lib/scan/scan.cpp" #include void setUp(void) {}