add diapasons

This commit is contained in:
Egor Shitikov
2024-08-01 11:18:47 -07:00
committed by GitHub
parent 23a9b5cf0b
commit 91397aedcd

View File

@@ -26,8 +26,12 @@
// TODO: if % RANGE_PER_PAGE 1= 0
#define FREQ_END 950
// Feature to scan diapazones. Other frequency settings will be ignored.
//int SCAN_DIAPAZONES[] = {};
int SCAN_DIAPAZONES[] = {850890, 920950};
// MHZ per page
// To put everything on one page set RANGE_PER_PAGE = FREQ_END - 800
// to put everething into one page set RANGE_PER_PAGE = FREQ_END - 800
unsigned int RANGE_PER_PAGE = FREQ_END - FREQ_BEGIN; // FREQ_END - FREQ_BEGIN
// TODO: Ignore power lines
@@ -35,11 +39,11 @@ unsigned int RANGE_PER_PAGE = FREQ_END - FREQ_BEGIN; // FREQ_END - FREQ_BEGIN
#define LOW_FILTER 3
#define FILTER_SPECTRUM_RESULTS true
// The number of the spectrum screen lines = width of screen
// Resolution of the scan is limited by 128-pixel screen
// numbers of the spectrum screen lines = width of screen
// resolution of the scan limited by 128 pixel screan
#define STEPS 128
// Number of samples for each frequency scan. Fewer samples = better temporal resolution.
// if more than 100 it can freez
// if more tan 100 it can feez
#define SAMPLES 100 //(scan time = 1294)
#define RANGE (int)(FREQ_END - FREQ_BEGIN)
@@ -72,7 +76,7 @@ unsigned int median_freqancy = FREQ_BEGIN + range_freqancy / 2;
#include <heltec_unofficial.h>
#include <images.h>
// This file contains a binary patch for the SX1262
// This file contaiminins binary patch for the SX1262
#include "modules/SX126x/patches/SX126x_patch_scan.h"
// Prints the scan measurement bins from the SX1262 in hex
@@ -85,13 +89,13 @@ unsigned int median_freqancy = FREQ_BEGIN + range_freqancy / 2;
#define MINOR_TICK_LENGTH 1
// WEIGHT of the x-asix line
#define X_AXIS_WEIGHT 1
// Height of the plotter area
// Height of the ploter area
#define HEIGHT RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE
//
#define SCALE_TEXT_TOP (HEIGHT + X_AXIS_WEIGHT + MAJOR_TICK_LENGTH)
#define STATUS_TEXT_TOP (64 - 10)
// Detection level from the 33 levels. The higher number is more sensitive
// Detection level from the 33 levels. Higher number is more sensative
#define DEFAULT_DRONE_DETECTION_LEVEL 21
#define BUZZZER_PIN 41
@@ -100,6 +104,7 @@ unsigned int median_freqancy = FREQ_BEGIN + range_freqancy / 2;
#define WATERFALL_ENABLED true
#define WATERFALL_START 37
#define OSD_ENABLED true
#define DISABLE_PLOT_CHART false
@@ -113,10 +118,10 @@ bool waterfall[10][STEPS][10];
unsigned short int scan_var = 0;
// initialized flag
bool initialized = false;
// Used as a Led Light and Buzzer/count trigger
// Used as a Led Light and Buzzer/sount trigger
bool led_flag = false;
bool first_run = false;
// drone detection flag
// drone tetection flag
bool drone_detected = false;
bool detected = false;
unsigned int drone_detection_level = DEFAULT_DRONE_DETECTION_LEVEL;
@@ -134,6 +139,7 @@ unsigned int scan_start_time = 0;
uint64_t start = 0;
unsigned int x, y, i, w = 0;
unsigned int diapazones_count = 0;
float freq = 0;
int rssi = 0;
@@ -150,14 +156,14 @@ void clearStatus()
void clearPloter()
{
//Clear the scan plot rectangle
// clear the scan plot rectangle
display.setColor(BLACK);
display.fillRect(0, 0, STEPS, HEIGHT);
display.setColor(WHITE);
}
/**
* @brief Draws ticks on display at regular intervals.
* @brief Draws ticks on the display at regular whole intervals.
*
* @param every The interval between ticks in MHz.
* @param length The length of each tick in pixels.
@@ -180,7 +186,7 @@ void drawTicks(float every, int length)
int tick = 0;
int tick_minor = 0;
int median = (RANGE_PER_PAGE / every) / 2;
// TODO: (RANGE_PER_PAGE / every) * 2 has twice extra steps we need to figure out correct logic or minor ticks are not showing to the end
// TODO: (RANGE_PER_PAGE / every) * 2 has twice extra steps we need to figureout correct logic or minor ticks is not showing to the end
for (int t = 0; t <= (RANGE_PER_PAGE / every) * 2; t++)
{
// fix if pixels per step is not int and we have shift
@@ -204,7 +210,7 @@ void drawTicks(float every, int length)
}
#ifdef MINOR_TICKS
// Fix two ticks together
// Fix two ticks togather
if (tick_minor + 1 != tick && tick_minor - 1 != tick && tick_minor + 2 != tick && tick_minor - 2 != tick)
{
display.drawLine(tick_minor, HEIGHT + X_AXIS_WEIGHT, tick_minor, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
@@ -214,12 +220,8 @@ void drawTicks(float every, int length)
{
display.drawLine(tick_minor + 1, HEIGHT + X_AXIS_WEIGHT, tick_minor + 1, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
}
//}
#endif
}
// Draw Central Tick
// display.drawLine(128/2, HEIGHT + X_AXIS_WEIGHT, 128/2, HEIGHT + X_AXIS_WEIGHT + 5);
}
/**
@@ -229,11 +231,11 @@ void displayDecorate(int begin = 0, int end = 0, bool redraw = false)
{
if (!initialized)
{
// Start and end ticks
// begining and end ticks
display.fillRect(0, HEIGHT + X_AXIS_WEIGHT, 2, MAJOR_TICK_LENGTH + 1);
display.fillRect(126, HEIGHT + X_AXIS_WEIGHT, 2, MAJOR_TICK_LENGTH + 1);
// Drone detection level
// drone detection level
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 0, String(drone_detection_level));
}
@@ -245,18 +247,18 @@ void displayDecorate(int begin = 0, int end = 0, bool redraw = false)
display.fillRect(0, SCALE_TEXT_TOP + 1, 128, 12);
display.setColor(WHITE);
// Drone detection level
// drone detection level
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 0, String(drone_detection_level));
// Frequency start
// frequency start
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, SCALE_TEXT_TOP, (begin == 0) ? String(FREQ_BEGIN) : String(begin));
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(128 / 2, SCALE_TEXT_TOP, (begin == 0) ? String(median_freqancy) : String(begin + ((end - begin) / 2)));
// Frequency end
// frequency end
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, SCALE_TEXT_TOP, (end == 0) ? String(FREQ_END) : String(end));
}
@@ -311,11 +313,14 @@ void displayDecorate(int begin = 0, int end = 0, bool redraw = false)
display.drawString(start_scan_text, STATUS_TEXT_TOP, String(drone_detected_freqancy_start) + ">RF<" + String(drone_detected_freqancy_end));
}
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, STATUS_TEXT_TOP, String(FREQ_BEGIN));
if (diapazones_count == 0)
{
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, STATUS_TEXT_TOP, String(FREQ_BEGIN));
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, STATUS_TEXT_TOP, String(FREQ_END));
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, STATUS_TEXT_TOP, String(FREQ_END));
}
if (!initialized)
{
@@ -368,7 +373,7 @@ void setup()
RADIOLIB_OR_HALT(radio.setRxBandwidth(BANDWIDTH));
// and disable the data shaping
RADIOLIB_OR_HALT(radio.setDataShaping(RADIOLIB_SHAPING_NONE));
both.println("Starting scanning...");
both.println("Starting scaning...");
float vbat = heltec_vbat();
both.printf("V battery: %.2fV (%d%%)\n", vbat, heltec_battery_percent(vbat));
delay(300);
@@ -438,7 +443,7 @@ void setup()
}
display.clear();
// waterfall start line y-axis
// waterfall start line y-asix
w = WATERFALL_START;
}
@@ -468,8 +473,8 @@ void loop()
fr_begin = FREQ_BEGIN;
fr_end = fr_begin;
// 50 is a single-screen range
// TODO: Make 50 a variable with the option to show the full range
// 50 is a single screen range
// TODO:Make 50 as a variable with the option show full range
iterations = range / RANGE_PER_PAGE;
single_step = RANGE_PER_PAGE / 128;
@@ -488,14 +493,36 @@ void loop()
single_page_scan = false;
}
// Iterating by small ranges of 50 Mhz, each pixel is 0.4 Mhz
diapazones_count = 0;
for (int diapazone : SCAN_DIAPAZONES)
{
diapazones_count++;
}
if (diapazones_count > 0)
{
iterations = diapazones_count;
single_page_scan = false;
}
// Iterateing by small ranges by 50 Mhz each pixel is 0.4 Mhz
for (i = 0; i < iterations; i++)
{
range = RANGE_PER_PAGE;
drone_detected_freqancy_start == 0;
drone_detected_freqancy_start = 0;
fr_begin = (i == 0) ? fr_begin : fr_begin += range;
fr_end = fr_begin + RANGE_PER_PAGE;
if (diapazones_count == 0)
{
fr_begin = (i == 0) ? fr_begin : fr_begin += range;
fr_end = fr_begin + RANGE_PER_PAGE;
}
else
{
fr_begin = SCAN_DIAPAZONES[i] / 1000;
fr_end = SCAN_DIAPAZONES[i] % 1000;
range = fr_end - fr_begin;
}
if (!ANIMATED_RELOAD || !single_page_scan)
{
@@ -525,7 +552,7 @@ void loop()
freq = fr_begin + (range * ((float)x / STEPS));
radio.setFrequency(freq);
// RSSI METHOD
// Gets RSSI (Recorded Signal Strength Indicator)
// Get RSSI (Recorded Signal Strength Indicator)
// rssi = radio.getRSSI(false);
// Serial.println(String(rssi) + "db");
#ifdef PRINT_SCAN_VALUES
@@ -547,12 +574,12 @@ void loop()
radio.spectralScanGetResult(result);
detected = false;
#ifdef FILTER_SPECTRUM_RESULTS
// Filter Elements without neighbors
// Filter Elements without neabors
for (y = 1; y < RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE; y++)
{
if (result[y] && (result[y + 1] > 0 && result[y - 1] > 0))
{
//Filling the empty pixel between signals int the level < 27 (noise level)
// filling the empty pixel between signals int the level < 27 (noise level)
/* if (y < 27 && result[y + 1] == 0 && result[y + 2] > 0)
{
result[y + 1] = 1;
@@ -573,10 +600,11 @@ void loop()
#endif
if (result[y] || y == drone_detection_level)
{
// check if we should alarm about a drone presence
// check if we shuld alarm the dron
if (filtered_result[y] == 1 && y <= drone_detection_level)
{
drone_detected = true;
#ifdef WATERFALL_ENABLED
if (single_page_scan)
{
// Drone detection true for waterfall
@@ -584,14 +612,14 @@ void loop()
display.setColor(WHITE);
display.setPixel(x, w);
}
#endif
if (drone_detected_freqancy_start == 0)
{
drone_detected_freqancy_start = freq;
}
drone_detected_freqancy_end = freq;
led_flag = true;
//If level is set to sensitive, start beeping every 10th frequency and shorter
// if level to sensetive doing beep every 10th freaqancy and shorter
if (drone_detection_level <= 25)
{
if (detection_count == 1 && SOUND_ON)
@@ -609,16 +637,17 @@ void loop()
display.setPixel(x, 3);
display.setPixel(x, 4);
}
else if (filtered_result[y] == 1 && y > drone_detection_level && single_page_scan && waterfall[i][x][w] != true)
#ifdef WATERFALL_ENABLED
if (filtered_result[y] == 1 && y > drone_detection_level && single_page_scan && waterfall[i][x][w] != true)
{
// If drone not found set dark pixel on the waterfall
// TODO: make something like scrolling up if possible
// if drone not found dark pixel on waterfall
// TODO: make somethin like scrolling up if possible
waterfall[i][x][w] = false;
display.setColor(BLACK);
display.setPixel(x, w);
display.setColor(WHITE);
}
#endif
if (filtered_result[y] == 1)
{
// Set signal level pixel
@@ -666,14 +695,14 @@ void loop()
display.drawString(128 / 2, 0, String(freq));
display.display();
button_pressed_counter++;
if (button_pressed_counter > 200)
if (button_pressed_counter > 150)
{
digitalWrite(LED, HIGH);
delay(150);
digitalWrite(LED, LOW);
}
}
if (button_pressed_counter > 200)
if (button_pressed_counter > 150)
{
// Remove Curent Freqancy Text
display.setTextAlignment(TEXT_ALIGN_CENTER);
@@ -683,7 +712,7 @@ void loop()
display.display();
break;
}
if (button_pressed_counter > 50 && button_pressed_counter < 200)
if (button_pressed_counter > 50 && button_pressed_counter < 150)
{
// Visually confirm it's off so user releases button
display.displayOff();
@@ -717,7 +746,7 @@ void loop()
{
w = WATERFALL_START;
}
#ifdef WATERFALL_ENABLED
// Draw waterfall position cursor
if (single_page_scan)
{
@@ -725,6 +754,7 @@ void loop()
display.drawHorizontalLine(0, w, STEPS);
display.setColor(WHITE);
}
#endif
display.display();
}