add usage of text

This commit is contained in:
2026-08-07 15:37:13 +02:00
parent eeb2aac75c
commit 95225a5811
4 changed files with 148 additions and 96 deletions
+4
View File
@@ -68,6 +68,10 @@ config CHARACTER_SPACING
range 1 255 range 1 255
default 1 default 1
config NO_CALLSIGN_IDENTIFICATION
string "Callsign used for aircraft with unknown callsign"
default "UNK"
comment "Receiver configuration" comment "Receiver configuration"
config FALLBACK_LAT config FALLBACK_LAT
+3 -5
View File
@@ -42,7 +42,7 @@ draw::color_t interpolateColor(double value,
return stops.back().color; return stops.back().color;
} }
#ifdef CONFIG_METRIC
draw::color_t get_altitude_color(uint32_t value) { draw::color_t get_altitude_color(uint32_t value) {
static constexpr std::array<color_stop, 11> stops = {{ static constexpr std::array<color_stop, 11> stops = {{
#ifdef CONFIG_METRIC #ifdef CONFIG_METRIC
@@ -57,8 +57,7 @@ draw::color_t get_altitude_color(uint32_t value) {
{6000, {40, 175, 215}}, {6000, {40, 175, 215}},
{9000, {50, 110, 240}}, {9000, {50, 110, 240}},
{12000, {140, 50, 220}} {12000, {140, 50, 220}}
#endif #else
#ifndef CONFIG_METRIC
{0, {220, 90, 20}}, // Brown/Dark Orange {0, {220, 90, 20}}, // Brown/Dark Orange
{500, {245, 115, 25}}, // Orange {500, {245, 115, 25}}, // Orange
{1000, {250, 150, 30}}, // Light Orange {1000, {250, 150, 30}}, // Light Orange
@@ -74,7 +73,6 @@ draw::color_t get_altitude_color(uint32_t value) {
}}; }};
return interpolateColor(value, stops); return interpolateColor(value, stops);
} }
#endif
enum letter_id { enum letter_id {
LETTER_A, LETTER_A,
@@ -171,7 +169,7 @@ void putchar(const char c, uint16_t x, uint16_t y, const draw::color_t color) {
y++; y++;
} }
} }
void puts(const std::string &s, uint16_t x, uint16_t y, draw::color_t color) { void puts(const std::string &s, const uint16_t x, const uint16_t y, const draw::color_t color) {
for (size_t i = 0; i < s.length(); i++) { for (size_t i = 0; i < s.length(); i++) {
putchar(s[i], x+((FONT_WIDTH+CONFIG_CHARACTER_SPACING)*i), y, color); putchar(s[i], x+((FONT_WIDTH+CONFIG_CHARACTER_SPACING)*i), y, color);
} }
+9 -2
View File
@@ -1,9 +1,16 @@
#pragma once #pragma once
#include "config.hpp"
template<typename T> template<typename T>
static inline T feet_to_meters(T ft) { static inline T feet_to_meters(T ft) {
return static_cast<T>(ft * 0.3048); return static_cast<T>(ft * 0.3048);
} }
template<typename T> template<typename T>
static inline T knot_to_km(T kn) { static inline T knot_to_km(T kt) {
return static_cast<T>(kn * 0.5399568); return static_cast<T>(kt * 1.852);
} }
#ifdef CONFIG_METRIC
#define SPEED_UNIT "kmph"
#else
#define SPEED_UNIT "knot"
#endif
+92 -49
View File
@@ -2,36 +2,35 @@
#include "core/color.h" #include "core/color.h"
#include "core/config.hpp" #include "core/config.hpp"
#include "core/font.hpp" #include "core/font.hpp"
#include "core/geo.hpp"
#include "core/gfx.hpp"
#include "core/global.hpp"
#include "core/units.hpp" #include "core/units.hpp"
#include "hal/draw.hpp" #include "hal/draw.hpp"
#include "hal/hal.hpp" #include "hal/hal.hpp"
#include "hal/net.hpp" #include "hal/net.hpp"
#include "nlohmann/json_fwd.hpp" #include "nlohmann/json_fwd.hpp"
#include <cmath>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <cmath>
#include <format> #include <format>
#include <iostream> #include <iostream>
#include <numbers> #include <numbers>
#include <string> #include <string>
#include "core/global.hpp"
#include "core/geo.hpp"
#include "core/gfx.hpp"
#ifndef CONFIG_AUTOSCALE #ifndef CONFIG_AUTOSCALE
constexpr constexpr
#endif #endif
uint16_t max_range = CONFIG_MAX_RANGE; uint16_t max_range = CONFIG_MAX_RANGE;
int main() { int main() {
if (hal::init() != 0) { if (hal::init() != 0) {
return 1; return 1;
} }
const auto [screen_w, screen_h] = hal::get_screen_size(); const auto [screen_w, screen_h] = hal::get_screen_size();
#ifndef CONFIG_AUTOSCALE #ifndef CONFIG_AUTOSCALE
const const
#endif #endif
float pixels_per_km = float pixels_per_km =
static_cast<float>(screen_h > screen_w ? screen_w : screen_h) / static_cast<float>(screen_h > screen_w ? screen_w : screen_h) /
(max_range * 2); (max_range * 2);
@@ -85,85 +84,129 @@ int main() {
} }
} }
#ifdef CONFIG_AUTOSCALE #ifdef CONFIG_AUTOSCALE
{ {
// fardest aircraft in km // fardest aircraft in km
uint16_t fardest_aircraft_distance_linear = 0; uint16_t fardest_aircraft_distance_linear = 0;
#endif #endif
{ // draw planes { // draw planes
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", CONFIG_BASE_URL)); nlohmann::json aircraft = net::http_get_json(
if (aircraft!= nullptr) { std::format("{}/aircraft.json", CONFIG_BASE_URL));
for(nlohmann::json &craft : aircraft["aircraft"]) { if (aircraft != nullptr) {
for (nlohmann::json &craft : aircraft["aircraft"]) {
uint32_t altitude; uint32_t altitude;
try { try {
if(craft["alt_baro"].is_string()) { if (craft["alt_baro"].is_string()) {
altitude = 0; altitude = 0;
} else { } else {
altitude =craft["alt_baro"].get<uint32_t>(); altitude = craft["alt_baro"].get<uint32_t>();
#ifdef CONFIG_METRIC #ifdef CONFIG_METRIC
altitude = feet_to_meters(altitude); altitude = feet_to_meters(altitude);
#endif #endif
} }
} catch(...) { } catch (...) {
std::clog << YELLOW"[WARNING]" RESET " aircraft with no alt data detected!\n"; std::clog << YELLOW "[WARNING]" RESET
" aircraft with no alt data detected!\n";
altitude = 0; altitude = 0;
} }
#ifndef CONFIG_METRIC
// aircraft gorund speed in km/h // aircraft ground speed in knots
float speed_knot;
#endif
// aircraft ground speed in km/h
float speed; float speed;
// aircraft track in degreees // aircraft track in degreees
float track; float track;
try { try {
#ifdef CONFIG_METRIC
speed = knot_to_km(craft["gs"].get<float>()); speed = knot_to_km(craft["gs"].get<float>());
#else
speed_knot = craft["gs"].get<float>();
speed = knot_to_km(speed_knot);
#endif
track = craft["track"].get<float>(); track = craft["track"].get<float>();
} catch(...) { } catch (...) {
std::clog << YELLOW"[WARNING]" RESET " aircraft with no ground speed or track data detected!\n"; std::clog << YELLOW
"[WARNING]" RESET
" aircraft with no ground speed or track data detected!\n";
speed = 0; speed = 0;
} }
draw::color_t color= get_altitude_color(altitude); draw::color_t color = get_altitude_color(altitude);
try { try {
const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get<double>(), craft["lon"].get<double>()); const auto [x_offset, y_offset] = get_offset_from_station(
#ifdef CONFIG_AUTOSCALE craft["lat"].get<double>(), craft["lon"].get<double>());
if(std::abs(x_offset)/1000 > fardest_aircraft_distance_linear) { #ifdef CONFIG_AUTOSCALE
fardest_aircraft_distance_linear = std::abs(x_offset)/1000; if (std::abs(x_offset) / 1000 >
fardest_aircraft_distance_linear) {
fardest_aircraft_distance_linear = std::abs(x_offset) / 1000;
} }
if(std::abs(y_offset)/1000 > fardest_aircraft_distance_linear) { if (std::abs(y_offset) / 1000 >
fardest_aircraft_distance_linear = std::abs(y_offset)/1000; fardest_aircraft_distance_linear) {
fardest_aircraft_distance_linear = std::abs(y_offset) / 1000;
} }
#endif #endif
const uint16_t x_center = middle_x+((x_offset/1000)*pixels_per_km); const uint16_t x_center =
const uint16_t y_center = middle_y+((y_offset/1000)*pixels_per_km); middle_x + ((x_offset / 1000) * pixels_per_km);
const uint16_t y_center =
middle_y + ((y_offset / 1000) * pixels_per_km);
// draw::pixel(x_center, y_center, color); // draw::pixel(x_center, y_center, color);
//speed in pixels per hour // speed in pixels per hour
const float speed_pph = speed* pixels_per_km; const float speed_pph = speed * pixels_per_km;
// lenght of Time-Based Vector // lenght of Time-Based Vector
const float vector_lenght = (speed_pph/60) * CONFIG_TIME_BASED_VECTOR_LENGHT; const float vector_lenght =
(speed_pph / 60) * CONFIG_TIME_BASED_VECTOR_LENGHT;
// track in radians // track in radians
const float track_rad = std::fmod((track-90),365.0f) * (static_cast<float>(std::numbers::pi)/180.0f); const float track_rad =
std::fmod((track - 90), 365.0f) *
(static_cast<float>(std::numbers::pi) / 180.0f);
draw::line(x_center, y_center,
x_center + (vector_lenght * std::cos(track_rad)),
y_center + (vector_lenght * std::sin(track_rad)),
color);
draw::rhombus(x_center, y_center, 8 /*TODO: remove magic*/,
color);
draw::line(x_center, y_center,x_center + (vector_lenght*std::cos(track_rad)), y_center + (vector_lenght*std::sin(track_rad)), color); {
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,color); std::string callsign;
font::puts("TEST123", x_center+10, y_center, color); try {
} catch(...) { callsign = craft["flight"].get<std::string>();
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n"; } catch (...) {
std::clog << YELLOW "[WARNING]" RESET
" aircraft with no callsign detected!\n";
callsign = CONFIG_NO_CALLSIGN_IDENTIFICATION;
}
// print some info
font::puts(callsign, x_center + 10 /*TODO: remove magic*/, y_center, color);
font::puts(std::to_string(static_cast<uint16_t>(
#ifdef CONFIG_METRIC
speed
#else
speed_knot
#endif
)) + SPEED_UNIT, x_center + 10 /*TODO: remove magic*/, y_center + FONT_HEIGHT +CONFIG_CHARACTER_SPACING, color);
}
} catch (...) {
std::clog << YELLOW "[WARNING]" RESET
" aircraft with no lat/lon data detected!\n";
} }
} }
} else { } else {
// TODO draw vizual error // TODO draw vizual error
std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n"; std::cerr << RED "[ERROR]" RESET " failed to get aircraft\n";
} }
} }
#ifdef CONFIG_AUTOSCALE #ifdef CONFIG_AUTOSCALE
if (fardest_aircraft_distance_linear > 0) { if (fardest_aircraft_distance_linear > 0) {
for(uint16_t i = CONFIG_FIRST_RING_DISTANCE; i < UINT16_MAX; i*=2) { for (uint16_t i = CONFIG_FIRST_RING_DISTANCE; i < UINT16_MAX; i *= 2) {
if (i+(CONFIG_RANGE_PADDING/2) >= fardest_aircraft_distance_linear) { if (i + (CONFIG_RANGE_PADDING / 2) >=
max_range = i+CONFIG_RANGE_PADDING; fardest_aircraft_distance_linear) {
max_range = i + CONFIG_RANGE_PADDING;
pixels_per_km = pixels_per_km =
static_cast<float>(screen_h > screen_w ? screen_w : screen_h) / static_cast<float>(screen_h > screen_w ? screen_w : screen_h) /
(max_range * 2); (max_range * 2);
@@ -172,7 +215,7 @@ int main() {
} }
} }
} }
#endif #endif
hal::end_frame(); hal::end_frame();
} }