add text
This commit is contained in:
+106
-1
@@ -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 <array>
|
||||
#include <cmath>
|
||||
@@ -71,4 +74,106 @@ draw::color_t get_altitude_color(uint32_t value) {
|
||||
}};
|
||||
return interpolateColor(value, stops);
|
||||
}
|
||||
#endif
|
||||
#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<typeof(character_bit_offset)>(
|
||||
character_bit_offset + j),
|
||||
static_cast<typeof(character_bit_offset)>(i),
|
||||
static_cast<typeof(character_bit_offset)>(
|
||||
_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
|
||||
Reference in New Issue
Block a user