Files
p-rad/src/main.cpp
T
2026-08-04 18:02:10 +02:00

77 lines
2.0 KiB
C++

#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 <cstdint>
#include <cstdio>
#include <format>
#include <iostream>
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<float>(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);
float receiver_lat;
float receiver_lon;
{
nlohmann::json receiver =
net::http_get_json(std::format("{}/receiver.json", base_url));
try {
receiver_lat = receiver["lat"].get<float>();
receiver_lon = receiver["lon"].get<float>();
} 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<uint16_t>(screen_w - 10), 0};
draw::filled_rect(&rect,
{static_cast<uint8_t>(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});
}
}
hal::end_frame();
}
}