From ea319a6cac8694ca3a2338970afc4e579cae77b9 Mon Sep 17 00:00:00 2001 From: Egor Shitikov Date: Thu, 19 Sep 2024 16:00:38 -0700 Subject: [PATCH] Refactor RSSI Scan --- include/DFRobot_OSD.h | 59 +++++++++++++++++++++++++++++ src/core.cpp => lib/scan/scan.cpp | 3 +- src/core.h => lib/scan/scan.h | 0 platformio.ini | 1 + src/main.cpp | 62 ++----------------------------- test/test_rssi.cpp | 2 +- 6 files changed, 66 insertions(+), 61 deletions(-) rename src/core.cpp => lib/scan/scan.cpp (98%) rename src/core.h => lib/scan/scan.h (100%) diff --git a/include/DFRobot_OSD.h b/include/DFRobot_OSD.h index d446a86..063753c 100644 --- a/include/DFRobot_OSD.h +++ b/include/DFRobot_OSD.h @@ -13,8 +13,67 @@ #ifndef _DFRobot_OSD_H_ #define _DFRobot_OSD_H_ +#define MAX_POWER_LEVELS 33 + #include +/*Define Custom characters Example*/ +static const int buf0[36] = {0x02, 0x80, 0x02, 0x40, 0x7F, 0xE0, 0x42, 0x00, + 0x42, 0x00, 0x7A, 0x40, 0x4A, 0x40, 0x4A, 0x80, + 0x49, 0x20, 0x5A, 0xA0, 0x44, 0x60, 0x88, 0x20}; + +static constexpr uint16_t levels[10] = { + 0x105, // 0 + 0x10E, // 1 + 0x10D, // 2 + 0x10C, // 3 + 0x10B, // 4 + 0x10A, // 5 + 0x109, // 6 + 0x108, // 7 + 0x107, // 8 + 0x106, // 9 +}; + +static constexpr uint16_t power_level[MAX_POWER_LEVELS + 1] = { + 0x10E, // 0 + 0x10E, // 1 + 0x10D, // 2 + 0x10C, // 3 + 0x10B, // 4 + 0x10A, // 5 + 0x109, // 6 + 0x108, // 7 + 0x107, // 8 + 0x106, // 9 not using 106 to accent rise + // new line + 0x10E, // 10 + 0x10D, // 11 + 0x10C, // 12 + 0x10B, // 13 + 0x10A, // 14 + 0x109, // 15 + 0x108, // 16 + 0x107, // 17 + 0x106, // 18 not using 106 + // new line + 0x10E, // 19 + 0x10D, // 20 + 0x10C, // 21 + 0x10B, // 22 + 0x10A, // 23 + 0x109, // 24 + 0x108, // 25 + 0x107, // 26 + 0x106, // 27 + 0x105, // 28 --- + 0x105, // 29 + 0x105, // 30 + 0x105, // 31 + 0x105, // 32 + 0x105 // 33 +}; + // #define ENABLE_DBG //!< Open this macro and you can see the details of the program #ifdef ENABLE_DBG #define DBG(...) \ diff --git a/src/core.cpp b/lib/scan/scan.cpp similarity index 98% rename from src/core.cpp rename to lib/scan/scan.cpp index 1eca711..bf8b416 100644 --- a/src/core.cpp +++ b/lib/scan/scan.cpp @@ -1,7 +1,7 @@ #ifndef LORASA_CORE_CPP #define LORASA_CORE_CPP -#include "core.h" +#include "scan.h" #include #include #include @@ -13,6 +13,7 @@ uint16_t Scan::rssiMethod(uint16_t *result) 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_RSSI; r++) diff --git a/src/core.h b/lib/scan/scan.h similarity index 100% rename from src/core.h rename to lib/scan/scan.h diff --git a/platformio.ini b/platformio.ini index e8fcfb9..7145e78 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,6 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] +default_envs = heltec_wifi_lora_32_V3 ; for env:vision-master-e190 ; src_dir = tft_src ; for env:vision-master-e290 diff --git a/src/main.cpp b/src/main.cpp index 71320a5..b6953bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,11 +25,12 @@ #include -// #define OSD_ENABLED true +#define OSD_ENABLED true // #define WIFI_SCANNING_ENABLED true // #define BT_SCANNING_ENABLED true -#include "core.h" +// RSSI Scan Logic +#include #ifndef LILYGO #include @@ -64,58 +65,6 @@ uint64_t bt_start = 0; #include "DFRobot_OSD.h" #define OSD_SIDE_BAR true -static constexpr uint16_t levels[10] = { - 0x105, // 0 - 0x10E, // 1 - 0x10D, // 2 - 0x10C, // 3 - 0x10B, // 4 - 0x10A, // 5 - 0x109, // 6 - 0x108, // 7 - 0x107, // 8 - 0x106, // 9 -}; - -static constexpr uint16_t power_level[MAX_POWER_LEVELS + 1] = { - 0x10E, // 0 - 0x10E, // 1 - 0x10D, // 2 - 0x10C, // 3 - 0x10B, // 4 - 0x10A, // 5 - 0x109, // 6 - 0x108, // 7 - 0x107, // 8 - 0x106, // 9 not using 106 to accent rise - // new line - 0x10E, // 10 - 0x10D, // 11 - 0x10C, // 12 - 0x10B, // 13 - 0x10A, // 14 - 0x109, // 15 - 0x108, // 16 - 0x107, // 17 - 0x106, // 18 not using 106 - // new line - 0x10E, // 19 - 0x10D, // 20 - 0x10C, // 21 - 0x10B, // 22 - 0x10A, // 23 - 0x109, // 24 - 0x108, // 25 - 0x107, // 26 - 0x106, // 27 - 0x105, // 28 --- - 0x105, // 29 - 0x105, // 30 - 0x105, // 31 - 0x105, // 32 - 0x105 // 33 -}; - // SPI pins #define OSD_CS 47 #define OSD_MISO 33 @@ -140,11 +89,6 @@ int global_counter = 0; DFRobot_OSD osd(OSD_CS); #endif -/*Define Custom characters Example*/ -static const int buf0[36] = {0x02, 0x80, 0x02, 0x40, 0x7F, 0xE0, 0x42, 0x00, - 0x42, 0x00, 0x7A, 0x40, 0x4A, 0x40, 0x4A, 0x80, - 0x49, 0x20, 0x5A, 0xA0, 0x44, 0x60, 0x88, 0x20}; - #include "global_config.h" #include "ui.h" diff --git a/test/test_rssi.cpp b/test/test_rssi.cpp index fad8e22..9c4b023 100644 --- a/test/test_rssi.cpp +++ b/test/test_rssi.cpp @@ -1,6 +1,6 @@ #include #define LOG(args...) printf(args) -#include "../src/core.cpp" +#include #include void setUp(void) {}