mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-03-28 17:42:59 +01:00
Fix formatting + spellcheck
This commit is contained in:
364
src/ui.cpp
364
src/ui.cpp
@@ -1,12 +1,10 @@
|
||||
|
||||
|
||||
#include "ui.h"
|
||||
#include "images.h"
|
||||
#include "global_config.h"
|
||||
#include "RadioLib.h"
|
||||
|
||||
// -------------------------------------------------
|
||||
// LCOAL DEFINES
|
||||
// LOCAL DEFINES
|
||||
// Height of the plotter area
|
||||
// -------------------------------------------------
|
||||
|
||||
@@ -14,16 +12,14 @@
|
||||
//
|
||||
#define SCALE_TEXT_TOP (HEIGHT + X_AXIS_WEIGHT + MAJOR_TICK_LENGTH)
|
||||
|
||||
|
||||
static unsigned int start_scan_text = (128 / 2) - 3;
|
||||
// initialized flag
|
||||
static bool ui_initialized = false;
|
||||
static bool led_flag = false;
|
||||
static unsigned short int scan_progress_count = 0;
|
||||
|
||||
static SSD1306Wire *display_instance; //(0x3c, SDA_OLED, SCL_OLED, DISPLAY_GEOMETRY);
|
||||
// PrintSplitter both(Serial, display);
|
||||
|
||||
//(0x3c, SDA_OLED, SCL_OLED, DISPLAY_GEOMETRY);
|
||||
static SSD1306Wire *display_instance;
|
||||
|
||||
// temporary dirty import ... to be solved durring upcoming refactoring
|
||||
extern unsigned int drone_detection_level;
|
||||
@@ -33,45 +29,43 @@ extern unsigned int detection_count;
|
||||
extern bool SOUND_ON;
|
||||
extern bool drone_detected;
|
||||
extern unsigned int drone_detected_frequency_start;
|
||||
extern unsigned int drone_detected_frequency_end ;
|
||||
extern unsigned int drone_detected_frequency_end;
|
||||
extern unsigned int ranges_count;
|
||||
extern int SCAN_RANGES[];
|
||||
extern unsigned int ranges_count;
|
||||
extern unsigned int iterations ;
|
||||
extern unsigned int scan_iterration;
|
||||
extern unsigned int iterations;
|
||||
extern unsigned int scan_iteration;
|
||||
|
||||
void UI_Init(SSD1306Wire *display_ptr)
|
||||
{
|
||||
// init pointer to display instance.
|
||||
display_instance = display_ptr;
|
||||
|
||||
// check for null ???
|
||||
display_instance->clear();
|
||||
// draw the UCOG welcome logo
|
||||
display_instance->drawXbm(0, 2, 128, 64, epd_bitmap_ucog);
|
||||
display_instance->display();
|
||||
// init pointer to display instance.
|
||||
display_instance = display_ptr;
|
||||
// check for null ???
|
||||
display_instance->clear();
|
||||
// draw the UCOG welcome logo
|
||||
display_instance->drawXbm(0, 2, 128, 64, epd_bitmap_ucog);
|
||||
display_instance->display();
|
||||
}
|
||||
|
||||
void UI_setLedFlag( bool new_status)
|
||||
void UI_setLedFlag(bool new_status)
|
||||
{
|
||||
led_flag = new_status;
|
||||
led_flag = new_status;
|
||||
}
|
||||
|
||||
|
||||
void clearStatus(void)
|
||||
{
|
||||
// clear status line
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, STATUS_TEXT_TOP + 2, 128, 13);
|
||||
display_instance->setColor(WHITE);
|
||||
// clear status line
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, STATUS_TEXT_TOP + 2, 128, 13);
|
||||
display_instance->setColor(WHITE);
|
||||
}
|
||||
|
||||
void UI_clearPlotter(void)
|
||||
{
|
||||
// clear the scan plot rectangle
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, 0, STEPS, HEIGHT);
|
||||
display_instance->setColor(WHITE);
|
||||
// clear the scan plot rectangle
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, 0, STEPS, HEIGHT);
|
||||
display_instance->setColor(WHITE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,189 +76,193 @@ void UI_clearPlotter(void)
|
||||
*/
|
||||
void drawTicks(float every, int length)
|
||||
{
|
||||
int first_tick = 0;
|
||||
//+ (every - (fr_begin - (int)(fr_begin / every) * every));
|
||||
/*if (first_tick < fr_begin)
|
||||
{
|
||||
first_tick += every;
|
||||
}*/
|
||||
bool correction = false;
|
||||
int pixels_per_step = STEPS / (RANGE_PER_PAGE / every);
|
||||
if (STEPS / RANGE_PER_PAGE != 0)
|
||||
{
|
||||
correction = true;
|
||||
}
|
||||
int first_tick;
|
||||
bool correction;
|
||||
int pixels_per_step;
|
||||
int correction_number;
|
||||
int tick;
|
||||
int tick_minor;
|
||||
int median;
|
||||
|
||||
int correction_number = STEPS - (int)(pixels_per_step * (RANGE_PER_PAGE / every));
|
||||
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 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
|
||||
if (correction && t % 2 != 0 && correction_number > 1)
|
||||
first_tick = 0;
|
||||
//+ (every - (fr_begin - (int)(fr_begin / every) * every));
|
||||
/*if (first_tick < fr_begin)
|
||||
{
|
||||
// pixels_per_step++;
|
||||
correction_number--;
|
||||
}
|
||||
|
||||
tick += pixels_per_step;
|
||||
tick_minor = tick / 2;
|
||||
|
||||
if (tick <= 128 - 3)
|
||||
first_tick += every;
|
||||
}*/
|
||||
correction = false;
|
||||
pixels_per_step = STEPS / (RANGE_PER_PAGE / every);
|
||||
if (STEPS / RANGE_PER_PAGE != 0)
|
||||
{
|
||||
display_instance->drawLine(tick, HEIGHT + X_AXIS_WEIGHT, tick, HEIGHT + X_AXIS_WEIGHT + length);
|
||||
// Central tick
|
||||
if (tick > (128 / 2) - 3 && tick < (128 / 2) + 3)
|
||||
{
|
||||
display_instance->drawLine(tick + 1, HEIGHT + X_AXIS_WEIGHT, tick + 1, HEIGHT + X_AXIS_WEIGHT + length);
|
||||
}
|
||||
correction = true;
|
||||
}
|
||||
|
||||
correction_number = STEPS - (int)(pixels_per_step * (RANGE_PER_PAGE / every));
|
||||
tick = 0;
|
||||
tick_minor = 0;
|
||||
median = (RANGE_PER_PAGE / every) / 2;
|
||||
// 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
|
||||
if (correction && t % 2 != 0 && correction_number > 1)
|
||||
{
|
||||
// pixels_per_step++;
|
||||
correction_number--;
|
||||
}
|
||||
tick += pixels_per_step;
|
||||
tick_minor = tick / 2;
|
||||
if (tick <= 128 - 3)
|
||||
{
|
||||
display_instance->drawLine(tick, HEIGHT + X_AXIS_WEIGHT, tick,
|
||||
HEIGHT + X_AXIS_WEIGHT + length);
|
||||
// Central tick
|
||||
if (tick > (128 / 2) - 3 && tick < (128 / 2) + 3)
|
||||
{
|
||||
display_instance->drawLine(tick + 1, HEIGHT + X_AXIS_WEIGHT,
|
||||
tick + 1, HEIGHT + X_AXIS_WEIGHT + length);
|
||||
}
|
||||
}
|
||||
#ifdef MINOR_TICKS
|
||||
// Fix two ticks together
|
||||
if (tick_minor + 1 != tick && tick_minor - 1 != tick && tick_minor + 2 != tick && tick_minor - 2 != tick)
|
||||
{
|
||||
display_instance->drawLine(tick_minor, HEIGHT + X_AXIS_WEIGHT, tick_minor, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
|
||||
}
|
||||
// Central tick
|
||||
if (tick_minor > (128 / 2) - 3 && tick_minor < (128 / 2) + 3)
|
||||
{
|
||||
display_instance->drawLine(tick_minor + 1, HEIGHT + X_AXIS_WEIGHT, tick_minor + 1, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
|
||||
}
|
||||
// Fix two ticks together
|
||||
if ((tick_minor + 1 != tick) && (tick_minor - 1 != tick) && (tick_minor + 2 != tick) && (tick_minor - 2 != tick))
|
||||
{
|
||||
display_instance->drawLine(tick_minor, HEIGHT + X_AXIS_WEIGHT,
|
||||
tick_minor, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
|
||||
}
|
||||
// Central tick
|
||||
if (tick_minor > (128 / 2) - 3 && tick_minor < (128 / 2) + 3)
|
||||
{
|
||||
display_instance->drawLine(tick_minor + 1, HEIGHT + X_AXIS_WEIGHT,
|
||||
tick_minor + 1, HEIGHT + X_AXIS_WEIGHT + MINOR_TICK_LENGTH);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI_drawCurrsor(int16_t possition)
|
||||
void UI_drawCursor(int16_t possition)
|
||||
{
|
||||
// Draw animated cursor on reload process
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->drawVerticalLine(possition, 0, HEIGHT);
|
||||
display_instance->drawVerticalLine(possition + 1, 0, HEIGHT);
|
||||
display_instance->setColor(WHITE);
|
||||
|
||||
// Draw animated cursor on reload process
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->drawVerticalLine(possition, 0, HEIGHT);
|
||||
display_instance->drawVerticalLine(possition + 1, 0, HEIGHT);
|
||||
display_instance->setColor(WHITE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Decorates the display: everything but the plot itself.
|
||||
*/
|
||||
void UI_displayDecorate(int begin = 0, int end = 0, bool redraw = false)
|
||||
{
|
||||
if (!ui_initialized)
|
||||
{
|
||||
// Start and end ticks
|
||||
display_instance->fillRect(0, HEIGHT + X_AXIS_WEIGHT, 2, MAJOR_TICK_LENGTH + 1);
|
||||
display_instance->fillRect(126, HEIGHT + X_AXIS_WEIGHT, 2, MAJOR_TICK_LENGTH + 1);
|
||||
|
||||
// Drone detection level
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, 0, String(drone_detection_level));
|
||||
}
|
||||
|
||||
if (!ui_initialized || redraw)
|
||||
{
|
||||
// Clear something
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, SCALE_TEXT_TOP + 1, 128, 12);
|
||||
display_instance->setColor(WHITE);
|
||||
|
||||
// Drone detection level
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, 0, String(drone_detection_level));
|
||||
|
||||
// Frequency start
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, SCALE_TEXT_TOP, (begin == 0) ? String(FREQ_BEGIN) : String(begin));
|
||||
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display_instance->drawString(128 / 2, SCALE_TEXT_TOP, (begin == 0) ? String(median_frequency) : String(begin + ((end - begin) / 2)));
|
||||
|
||||
// Frequency end
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, SCALE_TEXT_TOP, (end == 0) ? String(FREQ_END) : String(end));
|
||||
}
|
||||
|
||||
if (led_flag == true && detection_count >= 5)
|
||||
{
|
||||
digitalWrite(LED, HIGH);
|
||||
if (SOUND_ON)
|
||||
if (!ui_initialized)
|
||||
{
|
||||
tone(BUZZER_PIN, 104, 100);
|
||||
// Start and end ticks
|
||||
display_instance->fillRect(0, HEIGHT + X_AXIS_WEIGHT, 2,
|
||||
MAJOR_TICK_LENGTH + 1);
|
||||
display_instance->fillRect(126, HEIGHT + X_AXIS_WEIGHT, 2,
|
||||
MAJOR_TICK_LENGTH + 1);
|
||||
// Drone detection level
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, 0, String(drone_detection_level));
|
||||
}
|
||||
digitalWrite(REB_PIN, HIGH);
|
||||
led_flag = false;
|
||||
}
|
||||
|
||||
else if (!redraw)
|
||||
{
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
// Status text block
|
||||
if (!drone_detected)
|
||||
{
|
||||
// "Scanning"
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
// clear status line
|
||||
clearStatus();
|
||||
if (scan_progress_count == 0)
|
||||
if (!ui_initialized || redraw)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP, "Scan. ");
|
||||
// Clear something
|
||||
display_instance->setColor(BLACK);
|
||||
display_instance->fillRect(0, SCALE_TEXT_TOP + 1, 128, 12);
|
||||
display_instance->setColor(WHITE);
|
||||
// Drone detection level
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, 0, String(drone_detection_level));
|
||||
// Frequency start
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, SCALE_TEXT_TOP,
|
||||
(begin == 0) ? String(FREQ_BEGIN) : String(begin));
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display_instance->drawString(128 / 2, SCALE_TEXT_TOP,
|
||||
(begin == 0) ? String(median_frequency) : String(begin + ((end - begin) / 2)));
|
||||
// Frequency end
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, SCALE_TEXT_TOP,
|
||||
(end == 0) ? String(FREQ_END) : String(end));
|
||||
}
|
||||
else if (scan_progress_count == 1)
|
||||
if (led_flag == true && detection_count >= 5)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP, "Scan.. ");
|
||||
digitalWrite(LED, HIGH);
|
||||
if (SOUND_ON)
|
||||
{
|
||||
tone(BUZZER_PIN, 104, 100);
|
||||
}
|
||||
digitalWrite(REB_PIN, HIGH);
|
||||
led_flag = false;
|
||||
}
|
||||
else if (scan_progress_count == 2)
|
||||
else if (!redraw)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP, "Scan...");
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
scan_progress_count++;
|
||||
|
||||
if (scan_progress_count == 3)
|
||||
// Status text block
|
||||
if (!drone_detected)
|
||||
{
|
||||
scan_progress_count = 0;
|
||||
// "Scanning"
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
// clear status line
|
||||
clearStatus();
|
||||
if (scan_progress_count == 0)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP,
|
||||
"Scan. ");
|
||||
}
|
||||
else if (scan_progress_count == 1)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP,
|
||||
"Scan.. ");
|
||||
}
|
||||
else if (scan_progress_count == 2)
|
||||
{
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP,
|
||||
"Scan...");
|
||||
}
|
||||
scan_progress_count++;
|
||||
if (scan_progress_count == 3)
|
||||
{
|
||||
scan_progress_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drone_detected)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
// clear status line
|
||||
clearStatus();
|
||||
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP, String(drone_detected_frequency_start) + ">RF<" + String(drone_detected_frequency_end));
|
||||
}
|
||||
|
||||
if (ranges_count == 0)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, STATUS_TEXT_TOP, String(FREQ_BEGIN));
|
||||
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, STATUS_TEXT_TOP, String(FREQ_END));
|
||||
}
|
||||
else if (ranges_count > 0)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, STATUS_TEXT_TOP, String(SCAN_RANGES[scan_iterration] / 1000) + "-" + String(SCAN_RANGES[scan_iterration] % 1000));
|
||||
if (scan_iterration + 1 < iterations)
|
||||
if (drone_detected)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, STATUS_TEXT_TOP, String(SCAN_RANGES[scan_iterration + 1] / 1000) + "-" + String(SCAN_RANGES[scan_iterration + 1] % 1000));
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
// clear status line
|
||||
clearStatus();
|
||||
display_instance->drawString(start_scan_text, STATUS_TEXT_TOP,
|
||||
String(drone_detected_frequency_start) + ">RF<" + String(drone_detected_frequency_end));
|
||||
}
|
||||
}
|
||||
|
||||
if (!ui_initialized)
|
||||
{
|
||||
// X-axis
|
||||
display_instance->fillRect(0, HEIGHT, STEPS, X_AXIS_WEIGHT);
|
||||
if (ranges_count == 0)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, STATUS_TEXT_TOP, String(FREQ_BEGIN));
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, STATUS_TEXT_TOP, String(FREQ_END));
|
||||
}
|
||||
else if (ranges_count > 0)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display_instance->drawString(0, STATUS_TEXT_TOP,
|
||||
String(SCAN_RANGES[scan_iteration] / 1000) + "-" + String(SCAN_RANGES[scan_iteration] % 1000));
|
||||
if (scan_iteration + 1 < iterations)
|
||||
{
|
||||
display_instance->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display_instance->drawString(128, STATUS_TEXT_TOP,
|
||||
String(SCAN_RANGES[scan_iteration + 1] / 1000) + "-" + String(SCAN_RANGES[scan_iteration + 1] % 1000));
|
||||
}
|
||||
}
|
||||
if (!ui_initialized)
|
||||
{
|
||||
// X-axis
|
||||
display_instance->fillRect(0, HEIGHT, STEPS, X_AXIS_WEIGHT);
|
||||
// ticks
|
||||
#ifdef MAJOR_TICKS
|
||||
drawTicks(MAJOR_TICKS, MAJOR_TICK_LENGTH);
|
||||
drawTicks(MAJOR_TICKS, MAJOR_TICK_LENGTH);
|
||||
#endif
|
||||
}
|
||||
ui_initialized = true;
|
||||
}
|
||||
ui_initialized = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user