It works!!!

This commit is contained in:
2026-08-05 14:55:56 +02:00
parent 704126fd3f
commit d05144fb7e
4 changed files with 103 additions and 2 deletions
+74
View File
@@ -0,0 +1,74 @@
#include "config.hpp"
#include "hal/draw.hpp"
#include <array>
#include <cmath>
#include <cstdint>
struct color_stop {
double value;
draw::color_t color;
};
draw::color_t interpolateColor(double value,
const std::array<color_stop, 11> &stops) {
if (value <= stops.front().value)
return stops.front().color;
if (value >= stops.back().value)
return stops.back().color;
for (size_t i = 0; i < stops.size() - 1; ++i) {
if (value >= stops[i].value && value <= stops[i + 1].value) {
double t =
(value - stops[i].value) / (stops[i + 1].value - stops[i].value);
draw::color_t c0 = stops[i].color;
draw::color_t c1 = stops[i + 1].color;
draw::color_t result;
result.r = static_cast<uint8_t>(std::round(c0.r + t * (c1.r - c0.r)));
result.g = static_cast<uint8_t>(std::round(c0.g + t * (c1.g - c0.g)));
result.b = static_cast<uint8_t>(std::round(c0.b + t * (c1.b - c0.b)));
return result;
}
}
// Fallback
return stops.back().color;
}
#ifdef METRIC
draw::color_t get_altitude_color(uint32_t value) {
static constexpr std::array<color_stop, 11> stops = {{
#ifdef METRIC
{0, {220, 90, 20}},
{150, {245, 115, 25}},
{300, {250, 150, 30}},
{600, {245, 180, 20}},
{1200, {225, 200, 20}},
{1800, {175, 215, 30}},
{2400, {100, 225, 50}},
{3000, {40, 210, 110}},
{6000, {40, 175, 215}},
{9000, {50, 110, 240}},
{12000, {140, 50, 220}}
#endif
#ifndef METRIC
{0, {220, 90, 20}}, // Brown/Dark Orange
{500, {245, 115, 25}}, // Orange
{1000, {250, 150, 30}}, // Light Orange
{2000, {245, 180, 20}}, // Yellow-Orange
{4000, {225, 200, 20}}, // Yellow
{6000, {175, 215, 30}}, // Yellow-Green
{8000, {100, 225, 50}}, // Light Green
{10000, {40, 210, 110}}, // Teal/Cyan
{20000, {40, 175, 215}}, // Cyan-Blue
{30000, {50, 110, 240}}, // Blue
{40000, {140, 50, 220}} // Purple
#endif
}};
return interpolateColor(value, stops);
}
#endif
+4
View File
@@ -0,0 +1,4 @@
#pragma once
#include "hal/draw.hpp"
#include <cstdint>
draw::color_t get_altitude_color(uint32_t value);
+5
View File
@@ -0,0 +1,5 @@
#pragma once
template<typename T>
static inline T feet_to_meters(T ft) {
return static_cast<T>(ft * 0.3048);
}
+20 -2
View File
@@ -2,6 +2,7 @@
#include "core/color.h"
#include "core/config.hpp"
#include "core/const.hpp"
#include "core/units.hpp"
#include "hal/draw.hpp"
#include "hal/hal.hpp"
#include "hal/net.hpp"
@@ -12,6 +13,7 @@
#include <iostream>
#include "core/global.hpp"
#include "core/geo.hpp"
#include "core/gfx.hpp"
int main() {
if (hal::init() != 0) {
@@ -76,12 +78,28 @@ int main() {
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url));
if (aircraft!= nullptr) {
for(nlohmann::json &craft : aircraft["aircraft"]) {
uint32_t altitude;
try {
if(craft["alt_baro"].is_string()) {
altitude = 0;
} else {
altitude =craft["alt_baro"].get<uint32_t>();
#ifdef METRIC
altitude = feet_to_meters(altitude);
#endif
}
} catch(...) {
std::clog << YELLOW"[WARNING]" RESET " aircraft with no alt data detected!\n";
altitude = 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 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, {0xff,0x68,0x00});
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,{0xff,0x68,0x00});
draw::pixel(x_center, y_center, color);
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,color);
} catch(...) {
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n";
}