#include "../res/station.h" #include "core/color.h" #include "core/config.hpp" #include "core/const.hpp" #include "hal/draw.hpp" #include "hal/hal.hpp" #include "hal/net.hpp" #include "nlohmann/json_fwd.hpp" #include #include #include #include #include "core/global.hpp" #include "core/geo.hpp" int main() { if (hal::init() != 0) { return 1; } const auto [screen_w, screen_h] = hal::get_screen_size(); const float pixels_per_km = static_cast(screen_h > screen_w ? screen_w : screen_h) / (max_range * 2); bool odd_even = true; const uint16_t middle_x = (screen_w / 2); const uint16_t middle_y = (screen_h / 2); { nlohmann::json receiver = net::http_get_json(std::format("{}/receiver.json", base_url)); try { receiver_lat = receiver["lat"].get(); receiver_lon = receiver["lon"].get(); } catch (...) { receiver_lat = FALLBACK_LAT; receiver_lon = FALLBACK_LON; std::cerr << BLUE "[INFO]" RESET " using fallback lat/lon\n"; } } while (true) { hal::start_frame(); { // sing of life draw::rect_t rect = {10, 10, static_cast(screen_w - 10), 0}; draw::filled_rect(&rect, {static_cast(odd_even ? 0x0 : 0xff), 0, 0xff}); odd_even = !odd_even; } { // draw station uint16_t y = middle_y - STATION_HEIGHT / 2; for (uint8_t i = 0; i < STATION_HEIGHT; i++) { uint16_t x = middle_x - STATION_WIDTH / 2; for (uint8_t j = 0; j < STATION_WIDTH; j++) { uint8_t byte = station[i * STATION_BYTES_PER_ROW + j / 8]; if ((byte >> (7 - (j % 8))) & 1) { draw::pixel(x, y, {0xff, 0xff, 0xff}); } x++; } y++; } } { // draw rings for (uint16_t r = first_ring_distance; r <= max_range; r *= 2) { draw::circle(middle_x, middle_y, r * pixels_per_km, {0xff, 0xff, 0xff}); } } { // draw planes nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url)); if (aircraft!= nullptr) { for(nlohmann::json &craft : aircraft["aircraft"]) { try { const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get(), craft["lon"].get()); 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}); } catch(...) { std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n"; } } } else { // TODO draw vizual error std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n"; } } hal::end_frame(); } }