diff --git a/Kconfig b/Kconfig index d093434..973a008 100644 --- a/Kconfig +++ b/Kconfig @@ -63,6 +63,11 @@ config VECTOR_FOLLOW_TRACK_RATE This option will turn the vector from line into curve. This is of course be more computationaly expensive. +config CHARACTER_SPACING + int "Spacing between character in pixels" + range 1 255 + default 1 + comment "Receiver configuration" config FALLBACK_LAT diff --git a/res/5x7_dotmatrix_charset.h b/res/5x7_dotmatrix_charset.h new file mode 100644 index 0000000..d4c77a4 --- /dev/null +++ b/res/5x7_dotmatrix_charset.h @@ -0,0 +1,16 @@ +/* Auto-generated by export-alpha-bitmap GIMP plugin */ +/* 1 = opaque, 0 = transparent. MSB-first, rows padded to a byte. */ + +#define _5X7_DOTMATRIX_CHARSET_WIDTH 310 +#define _5X7_DOTMATRIX_CHARSET_HEIGHT 7 +#define _5X7_DOTMATRIX_CHARSET_BYTES_PER_ROW 39 + +static const unsigned char _5x7_dotmatrix_charset[273] = { + 0x27, 0x9D, 0xEF, 0xFD, 0xD1, 0x71, 0xE3, 0x08, 0xC5, 0xDE, 0x77, 0x9D, 0xF8, 0xC6, 0x31, 0x8F, 0xC1, 0x00, 0x04, 0x06, 0x04, 0x08, 0x28, 0x30, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x07, 0x11, 0xCE, 0x17, 0xCD, 0xF7, 0x38, + 0x52, 0x62, 0x98, 0x42, 0x31, 0x20, 0xA5, 0x0D, 0xC6, 0x31, 0x8C, 0x62, 0x48, 0xC6, 0x31, 0x88, 0x41, 0x00, 0x04, 0x09, 0x04, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, 0xB2, 0x31, 0x34, 0x10, 0x18, 0xC4, + 0x8A, 0x60, 0x98, 0x42, 0x11, 0x20, 0xA9, 0x0A, 0xE6, 0x31, 0x8C, 0x60, 0x48, 0xC6, 0x2A, 0x88, 0x9D, 0x67, 0x35, 0xC8, 0x7D, 0x88, 0x69, 0x13, 0x56, 0x77, 0x9B, 0x67, 0x72, 0x31, 0x8C, 0x63, 0xF9, 0x90, 0x21, 0x57, 0xA0, 0x28, 0xC4, + 0x8B, 0xA0, 0x9F, 0x7A, 0x7F, 0x20, 0xB1, 0x0A, 0xD6, 0x3E, 0x8F, 0x9C, 0x48, 0xC6, 0xA4, 0x51, 0x03, 0x98, 0x4E, 0x3C, 0x8E, 0x58, 0x2A, 0x12, 0xB9, 0x8C, 0x67, 0x98, 0x22, 0x31, 0x8A, 0xA2, 0x2A, 0x90, 0xC6, 0x90, 0x7C, 0x47, 0x3C, + 0xFA, 0x60, 0x98, 0x42, 0x31, 0x20, 0xA9, 0x08, 0xCE, 0x30, 0xAD, 0x02, 0x48, 0xC6, 0xAA, 0x22, 0x1F, 0x18, 0x47, 0xE8, 0x7C, 0x48, 0x2C, 0x12, 0xB1, 0x8F, 0x9F, 0x07, 0x22, 0x31, 0xA9, 0x1E, 0x4C, 0x91, 0x01, 0xF8, 0x62, 0x88, 0x84, + 0x8A, 0x62, 0x98, 0x42, 0x31, 0x24, 0xA5, 0x08, 0xC6, 0x30, 0x94, 0xA2, 0x48, 0xAA, 0xB1, 0x24, 0x23, 0x18, 0xC6, 0x08, 0x0C, 0x49, 0x2A, 0x12, 0xB1, 0x8C, 0x03, 0x00, 0xA6, 0x6A, 0xAA, 0x82, 0x88, 0x92, 0x11, 0x14, 0x62, 0x88, 0x88, + 0x8F, 0x9D, 0xEF, 0xC1, 0xF1, 0x73, 0x23, 0xF8, 0xC5, 0xD0, 0x6C, 0x5C, 0x47, 0x11, 0x51, 0x27, 0xDF, 0xE7, 0x3D, 0xC8, 0x74, 0x5C, 0xC9, 0x3A, 0xB1, 0x74, 0x03, 0x0F, 0x19, 0xA4, 0x54, 0x5D, 0xF7, 0x3B, 0xEE, 0x13, 0x9C, 0x87, 0x30 +}; diff --git a/src/core/font.hpp b/src/core/font.hpp new file mode 100644 index 0000000..26ab821 --- /dev/null +++ b/src/core/font.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "hal/draw.hpp" +#include +#include + +#define FONT_HEIGHT 7 +#define FONT_WIDTH 5 + +namespace font { +void putchar(char c, uint16_t x, uint16_t y, draw::color_t color); +void puts(const std::string &s, uint16_t x, uint16_t y, draw::color_t color); +} // namespace font \ No newline at end of file diff --git a/src/core/gfx.cpp b/src/core/gfx.cpp index cea712d..9ef3629 100644 --- a/src/core/gfx.cpp +++ b/src/core/gfx.cpp @@ -1,4 +1,7 @@ +#include "../res/5x7_dotmatrix_charset.h" #include "config.hpp" +#include "core/font.hpp" +#include "core/helpers.hpp" #include "hal/draw.hpp" #include #include @@ -71,4 +74,106 @@ draw::color_t get_altitude_color(uint32_t value) { }}; return interpolateColor(value, stops); } -#endif \ No newline at end of file +#endif + +enum letter_id { + LETTER_A, + LETTER_B, + LETTER_C, + LETTER_D, + LETTER_E, + LETTER_F, + LETTER_G, + LETTER_H, + LETTER_I, + LETTER_J, + LETTER_K, + LETTER_L, + LETTER_M, + LETTER_N, + LETTER_O, + LETTER_P, + LETTER_Q, + LETTER_R, + LETTER_S, + LETTER_T, + LETTER_U, + LETTER_V, + LETTER_W, + LETTER_X, + LETTER_Y, + LETTER_Z, + LETTER_a, + LETTER_b, + LETTER_c, + LETTER_d, + LETTER_e, + LETTER_f, + LETTER_g, + LETTER_h, + LETTER_i, + LETTER_j, + LETTER_k, + LETTER_l, + LETTER_m, + LETTER_n, + LETTER_o, + LETTER_p, + LETTER_q, + LETTER_r, + LETTER_s, + LETTER_t, + LETTER_u, + LETTER_v, + LETTER_w, + LETTER_x, + LETTER_y, + LETTER_z, + LETTER_0, + LETTER_1, + LETTER_2, + LETTER_3, + LETTER_4, + LETTER_5, + LETTER_6, + LETTER_7, + LETTER_8, + LETTER_9 +}; + +namespace font { +void putchar(const char c, uint16_t x, uint16_t y, const draw::color_t color) { + uint8_t char_index; + if (c >= 'a' && c <= 'z') { + char_index = (c - 'a') + LETTER_a; +} else if (c >= 'A' && c <= 'Z') { + char_index = (c - 'A') + LETTER_A; +} else if (c >= '0' && c <= '9') { + char_index = (c - '0') + LETTER_0; +} else { + return; // unsupported character +} + const uint16_t character_bit_offset = char_index * FONT_WIDTH; + const uint16_t x_orig = x; + for (uint8_t i = 0; i < FONT_HEIGHT; i++) { + x = x_orig; + for (uint8_t j = 0; j < FONT_WIDTH; j++) { + if (get_Nth_bit_in_grid(_5x7_dotmatrix_charset, + static_cast( + character_bit_offset + j), + static_cast(i), + static_cast( + _5X7_DOTMATRIX_CHARSET_WIDTH))) { + draw::pixel(x, y, color); + } + x++; + } + y++; + } +} +void puts(const std::string &s, uint16_t x, uint16_t y, 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); + } +} +} // namespace font \ No newline at end of file diff --git a/src/core/helpers.hpp b/src/core/helpers.hpp new file mode 100644 index 0000000..e6ac1bc --- /dev/null +++ b/src/core/helpers.hpp @@ -0,0 +1,9 @@ +#pragma once + +template +// all arguments are in bits +static inline bool get_Nth_bit_in_grid(const void *p, T col_x, T row_y, + T grid_width) { + const unsigned char *bytes = static_cast(p); + return (bytes[row_y * ((grid_width + 7) / 8) + (col_x / 8)] >> (7 - (col_x % 8))) & 1; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f8df885..b999e0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "../res/station.h" #include "core/color.h" #include "core/config.hpp" +#include "core/font.hpp" #include "core/units.hpp" #include "hal/draw.hpp" #include "hal/hal.hpp" @@ -12,6 +13,7 @@ #include #include #include +#include #include "core/global.hpp" #include "core/geo.hpp" #include "core/gfx.hpp" @@ -146,6 +148,7 @@ int main() { 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); } catch(...) { std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n"; }