add usage of text
This commit is contained in:
@@ -68,6 +68,10 @@ config CHARACTER_SPACING
|
||||
range 1 255
|
||||
default 1
|
||||
|
||||
config NO_CALLSIGN_IDENTIFICATION
|
||||
string "Callsign used for aircraft with unknown callsign"
|
||||
default "UNK"
|
||||
|
||||
comment "Receiver configuration"
|
||||
|
||||
config FALLBACK_LAT
|
||||
|
||||
+3
-5
@@ -42,7 +42,7 @@ draw::color_t interpolateColor(double value,
|
||||
return stops.back().color;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_METRIC
|
||||
|
||||
draw::color_t get_altitude_color(uint32_t value) {
|
||||
static constexpr std::array<color_stop, 11> stops = {{
|
||||
#ifdef CONFIG_METRIC
|
||||
@@ -57,8 +57,7 @@ draw::color_t get_altitude_color(uint32_t value) {
|
||||
{6000, {40, 175, 215}},
|
||||
{9000, {50, 110, 240}},
|
||||
{12000, {140, 50, 220}}
|
||||
#endif
|
||||
#ifndef CONFIG_METRIC
|
||||
#else
|
||||
{0, {220, 90, 20}}, // Brown/Dark Orange
|
||||
{500, {245, 115, 25}}, // Orange
|
||||
{1000, {250, 150, 30}}, // Light Orange
|
||||
@@ -74,7 +73,6 @@ draw::color_t get_altitude_color(uint32_t value) {
|
||||
}};
|
||||
return interpolateColor(value, stops);
|
||||
}
|
||||
#endif
|
||||
|
||||
enum letter_id {
|
||||
LETTER_A,
|
||||
@@ -171,7 +169,7 @@ void putchar(const char c, uint16_t x, uint16_t y, const draw::color_t color) {
|
||||
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++) {
|
||||
putchar(s[i], x+((FONT_WIDTH+CONFIG_CHARACTER_SPACING)*i), y, color);
|
||||
}
|
||||
|
||||
+9
-2
@@ -1,9 +1,16 @@
|
||||
#pragma once
|
||||
#include "config.hpp"
|
||||
template<typename T>
|
||||
static inline T feet_to_meters(T ft) {
|
||||
return static_cast<T>(ft * 0.3048);
|
||||
}
|
||||
template<typename T>
|
||||
static inline T knot_to_km(T kn) {
|
||||
return static_cast<T>(kn * 0.5399568);
|
||||
static inline T knot_to_km(T kt) {
|
||||
return static_cast<T>(kt * 1.852);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_METRIC
|
||||
#define SPEED_UNIT "kmph"
|
||||
#else
|
||||
#define SPEED_UNIT "knot"
|
||||
#endif
|
||||
+66
-23
@@ -2,28 +2,27 @@
|
||||
#include "core/color.h"
|
||||
#include "core/config.hpp"
|
||||
#include "core/font.hpp"
|
||||
#include "core/geo.hpp"
|
||||
#include "core/gfx.hpp"
|
||||
#include "core/global.hpp"
|
||||
#include "core/units.hpp"
|
||||
#include "hal/draw.hpp"
|
||||
#include "hal/hal.hpp"
|
||||
#include "hal/net.hpp"
|
||||
#include "nlohmann/json_fwd.hpp"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <numbers>
|
||||
#include <string>
|
||||
#include "core/global.hpp"
|
||||
#include "core/geo.hpp"
|
||||
#include "core/gfx.hpp"
|
||||
|
||||
#ifndef CONFIG_AUTOSCALE
|
||||
constexpr
|
||||
#endif
|
||||
uint16_t max_range = CONFIG_MAX_RANGE;
|
||||
|
||||
|
||||
int main() {
|
||||
if (hal::init() != 0) {
|
||||
return 1;
|
||||
@@ -92,7 +91,8 @@ int main() {
|
||||
#endif
|
||||
|
||||
{ // draw planes
|
||||
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", CONFIG_BASE_URL));
|
||||
nlohmann::json aircraft = net::http_get_json(
|
||||
std::format("{}/aircraft.json", CONFIG_BASE_URL));
|
||||
if (aircraft != nullptr) {
|
||||
for (nlohmann::json &craft : aircraft["aircraft"]) {
|
||||
|
||||
@@ -107,52 +107,94 @@ int main() {
|
||||
#endif
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
// aircraft gorund speed in km/h
|
||||
#ifndef CONFIG_METRIC
|
||||
// aircraft ground speed in knots
|
||||
float speed_knot;
|
||||
#endif
|
||||
// aircraft ground speed in km/h
|
||||
float speed;
|
||||
// aircraft track in degreees
|
||||
float track;
|
||||
try {
|
||||
#ifdef CONFIG_METRIC
|
||||
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>();
|
||||
} 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;
|
||||
}
|
||||
draw::color_t color = get_altitude_color(altitude);
|
||||
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(
|
||||
craft["lat"].get<double>(), craft["lon"].get<double>());
|
||||
#ifdef CONFIG_AUTOSCALE
|
||||
if(std::abs(x_offset)/1000 > fardest_aircraft_distance_linear) {
|
||||
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) {
|
||||
fardest_aircraft_distance_linear = std::abs(y_offset) / 1000;
|
||||
}
|
||||
#endif
|
||||
const uint16_t x_center = middle_x+((x_offset/1000)*pixels_per_km);
|
||||
const uint16_t y_center = middle_y+((y_offset/1000)*pixels_per_km);
|
||||
const uint16_t x_center =
|
||||
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);
|
||||
|
||||
// speed in pixels per hour
|
||||
const float speed_pph = speed * pixels_per_km;
|
||||
// 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
|
||||
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);
|
||||
font::puts("TEST123", x_center+10, y_center, color);
|
||||
{
|
||||
std::string callsign;
|
||||
try {
|
||||
callsign = craft["flight"].get<std::string>();
|
||||
} catch (...) {
|
||||
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n";
|
||||
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 {
|
||||
// TODO draw vizual error
|
||||
@@ -162,7 +204,8 @@ int main() {
|
||||
#ifdef CONFIG_AUTOSCALE
|
||||
if (fardest_aircraft_distance_linear > 0) {
|
||||
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) >=
|
||||
fardest_aircraft_distance_linear) {
|
||||
max_range = i + CONFIG_RANGE_PADDING;
|
||||
pixels_per_km =
|
||||
static_cast<float>(screen_h > screen_w ? screen_w : screen_h) /
|
||||
|
||||
Reference in New Issue
Block a user