Ad legend and fix screen scaling

This commit is contained in:
Egor
2024-11-24 13:28:34 -08:00
parent 85349f2a8c
commit 6028e13ef6
2 changed files with 97 additions and 19 deletions

View File

@@ -364,7 +364,7 @@ void loop()
for (int i = 0; i < SAMPLES_RSSI; i++)
{
state = radio.setFrequency((float)fr + (float)(rssi_mhz_step * u),
false); // false = no calibration need here
true); // false = no calibration need here
int radio_error_count = 0;
if (state != RADIOLIB_ERR_NONE)
{

View File

@@ -18,6 +18,23 @@
// #include "ui.h"
#include <Adafruit_GFX.h>
#include <Arduino.h>
#include <vector>
struct Entry
{
String drone; // Drone name
int fstart; // Fr Start
int fend; // Fr End
int y; // y(vertical) position
uint16_t color; // color
};
// Define and initialize the vector
std::vector<Entry> fpvArray = {{"FPV-ELRS", 160, 350, 100, ST7789_BLUE},
{"915-ELRS", 700, 1000, 100, ST7789_ORANGE},
{"FPV433-ELRS", 350, 530, 100, ST7789_YELLOW},
{"Orlan", 820, 940, 98, ST7789_GREEN},
{"Zala", 830, 950, 80, ST7789_MAGENTA}};
#define st7789_CS_Pin 39
#define st7789_REST_Pin 40
@@ -74,7 +91,8 @@ constexpr bool DRAW_DETECTION_TICKS = true;
#define FREQ_END 950
#define BANDWIDTH 467.0
#define MHZ_PX (float)((float)(FREQ_END - FREQ_BEGIN) / DISPLAY_WIDTH)
#define DEFAULT_DRONE_DETECTION_LEVEL 90
#define DEFAULT_DRONE_DETECTION_LEVEL -90
#define DRONE_LEGEND 1;
#define RANGE (int)(FREQ_END - FREQ_BEGIN)
@@ -117,7 +135,7 @@ bool waterfall[STEPS], detected_y[STEPS]; // 20 - ??? steps of the waterfall
bool first_run, new_pixel, detected_x = false;
// drone detection flag
bool detected = false;
uint64_t drone_detection_level = DEFAULT_DRONE_DETECTION_LEVEL;
int64_t drone_detection_level = DEFAULT_DRONE_DETECTION_LEVEL;
uint64_t drone_detected_frequency_start = 0;
uint64_t drone_detected_frequency_end = 0;
uint64_t detection_count = 0;
@@ -135,11 +153,22 @@ uint64_t scan_start_time = 0;
#endif
// To remove waterfall adjust this and this
#define LOWER_LEVEL DISPLAY_HEIGHT - 22 // 108
#define SPECTR_CHART_STAR_TOP 40 + 50;
#define WATERFALL_START 115
#define ZERO_LEVEL 110 // Equal to minimal RSSI
#define ZERO_SHIFT 42
#define LOWER_LEVEL ZERO_LEVEL + ZERO_SHIFT // 108(zero) - (40 moving down)
#define SPECTR_CHART_STAR_TOP 42;
#define WATERFALL_START 119
#define WATERFALL_END DISPLAY_HEIGHT - 10 - 2
#ifndef DISABLE_WATERFALL
#define DISABLE_WATERFALL 1 // to disable set to 1
#endif
#if DISABLE_WATERFALL == 0
#define ZERO_LEVEL 110
#define ZERO_SHIFT 0
#define LOWER_LEVEL ZERO_LEVEL
#endif
uint64_t x, y, range_item, w = WATERFALL_START, i = 0;
int osd_x = 1, osd_y = 2, col = 0, max_bin = 32;
@@ -254,6 +283,25 @@ void battery()
}
}
void drawDroneLegend()
{
// Draw FPV array Names
for (const auto &entry : fpvArray)
{
int pixelStart = (entry.fstart - FREQ_BEGIN) / MHZ_PX;
int pixelEnd = (entry.fend - FREQ_BEGIN) / MHZ_PX;
int length = (pixelEnd - pixelStart);
// Serial.println("Pixel Start: " + String(pixelStart));
// Serial.println("MHinPIX: " + String(MHZ_PX));
int median = length / 2;
if (entry.fstart < FREQ_END)
{
st7789->drawFastHLine(pixelStart, entry.y, length, entry.color);
drawText(pixelStart, entry.y - 10, entry.drone, entry.color);
}
}
}
constexpr int lower_level = LOWER_LEVEL;
constexpr int up_level = SPECTR_CHART_STAR_TOP;
int rssiToPix(int rssi)
@@ -270,13 +318,13 @@ int rssiToPix(int rssi)
// if chart moved to the bottom
if (lower_level > 130)
{
int returnRssi = lower_level + abs(rssi) - up_level - 21;
Serial.println("RSSI: " + String(rssi));
if (returnRssi >= lower_level - 2)
int returnRssi = abs(rssi - ZERO_SHIFT);
// Serial.println("RSSI: " + String(rssi));
if (returnRssi >= lower_level)
{
return lower_level - 1;
}
return abs(returnRssi);
return returnRssi;
}
else
{
@@ -322,6 +370,7 @@ int window_max_rssi = -999;
int window_max_fr = -999;
int max_scan_rssi[STEPS + 2];
int max_history_rssi[STEPS + 2];
int historical_loops = 50, h = 0;
long display_scan_start = 0;
long display_scan_end = 0;
long display_scan_i_end = 0;
@@ -336,7 +385,7 @@ constexpr unsigned int STATUS_BAR_HEIGHT = 5;
void loop()
{
Serial.println("Loop");
// Serial.println("Loop");
if (screen_update_loop_counter == 0)
{
fr_x[x1] = 0;
@@ -357,7 +406,16 @@ void loop()
// Clear old data with the cursor ...
st7789->drawFastVLine(x1, lower_level, -lower_level + 11, ST7789_BLACK);
// Draw max history line
if (h == historical_loops)
{
st7789->drawLine(x1, rssiToPix(max_history_rssi[x1]), x1, lower_level,
ST7789_BLACK /*gray*/);
// clear history
max_history_rssi[x1] = -999;
}
st7789->drawLine(x1, rssiToPix(max_history_rssi[x1]), x1, lower_level,
12710 /*gray*/);
// Fetch samples
@@ -429,7 +487,8 @@ void loop()
// Draw Update Cursor
st7789->drawFastVLine(x1 + 1, lower_level, -lower_level + 11, ST7789_BLACK);
st7789->drawFastVLine(x1 + 2, lower_level, -lower_level + 11, ST7789_BLACK);
// st7789->drawFastVLine(x1 + 3, lower_level, -lower_level + 11, ST7789_BLACK);
// st7789->drawFastVLine(x1 + 3, lower_level, -lower_level + 11,
// ST7789_BLACK);
if (max_scan_rssi[x1] == -999)
{
@@ -457,7 +516,7 @@ void loop()
}
}
// Writing pixel only if it is bigger than drone detection level
if (abs(max_scan_rssi[x1]) < drone_detection_level)
if (abs(max_scan_rssi[x1]) < abs(drone_detection_level))
{
if (DISABLE_WATERFALL == 0)
{
@@ -474,7 +533,7 @@ void loop()
// Draw legend for windows
if (x1 % rssi_window_size == 0 || x1 == DISPLAY_WIDTH)
{
if (abs(window_max_rssi) < drone_detection_level && window_max_rssi != 0 &&
if (abs(window_max_rssi) < abs(drone_detection_level) && window_max_rssi != 0 &&
window_max_rssi != -999)
{
y2 = 15;
@@ -519,9 +578,9 @@ void loop()
button_pressed_counter = 0;
if (button.pressed())
{
drone_detection_level++;
if (drone_detection_level > 107)
drone_detection_level = DEFAULT_DRONE_DETECTION_LEVEL - 20;
drone_detection_level--;
if (drone_detection_level < -107)
drone_detection_level = DEFAULT_DRONE_DETECTION_LEVEL + 20;
while (button.pressedNow())
{
delay(100);
@@ -540,6 +599,14 @@ void loop()
heltec_deep_sleep();
}
// Drone legend every 1/4 of the screen
if (x1 % (STEPS / 4) == 0)
{
#ifdef DRONE_LEGEND
drawDroneLegend();
#endif
}
// Main N x-axis full loop end logic
if (x1 >= STEPS)
{
@@ -551,17 +618,28 @@ void loop()
#ifdef PRINT_DEBUG
Serial.println("Screen End for Output: " + String(screen_update_loop_counter));
#endif
// Doing output only after full scan
if (screen_update_loop_counter + 1 == SCANS_PER_DISPLAY)
{
#ifdef DRONE_LEGEND
drawDroneLegend();
#endif
h++;
if (h == historical_loops - 1)
{
h = 0;
}
// Scan results to max Mhz and dB in window
display_scan_end = millis();
st7789->fillRect(0, 0, DISPLAY_WIDTH, 11, ST7789_BLACK);
drawText(0, 0,
"T:" + String(display_scan_end - display_scan_start) + "/" +
String(rssi_single_end - rssi_single_start) + " L:-" +
String(drone_detection_level) + "dB",
String(rssi_single_end - rssi_single_start) +
" L:" + String(drone_detection_level) + "dB",
ST7789_BLUE);
/// battery();