v.0.0.7 font_16x16

This commit is contained in:
tiijay
2025-11-05 11:42:33 +01:00
parent 2589cc3533
commit b7f5e924e0
9 changed files with 423 additions and 43 deletions

View File

@@ -10,10 +10,11 @@ LedMatrix::~LedMatrix()
{
}
// N entspricht Font-Height
template <size_t N>
uint8_t LedMatrix::charWidth(const uint8_t *charMatrix)
uint8_t LedMatrix::charWidth(const uint16_t *charMatrix)
{
uint8_t max_val = 0;
uint16_t max_val = 0;
for (size_t i = 0; i < N; i++)
{
if (charMatrix[i] > max_val)
@@ -29,6 +30,9 @@ uint8_t LedMatrix::charWidth(const uint8_t *charMatrix)
// Deshalb 32 - Wert
// bei 8 -> 32-28 = 4.Bit
// bei 2 -> 32-20 = 2.Bit
Serial.printf("max_val: [0x%04X] -> %d\n\r", max_val, (32 - __builtin_clz(max_val)));
return (max_val == 0) ? 0 : (32 - __builtin_clz(max_val));
}
@@ -43,23 +47,25 @@ void LedMatrix::drawPixel(int x, int y, CRGB color)
uint8_t LedMatrix::drawChar(int x, int y, char c, CRGB color)
{
const uint8_t *fontData = getFontChar(c);
const u_int8_t char_width_pixel = charWidth<7>(fontData);
const uint16_t *fontData = getFontChar_16x16(c);
const u_int8_t char_width_pixel = charWidth<16>(fontData);
const u_int8_t font_height = fontHeight_16x16();
const u_int8_t font_width = 16;
for (int row = 0; row < 7; row++)
for (u_int8_t row = 0; row < font_height; row++)
{
uint8_t line = fontData[row];
uint16_t line = fontData[row];
uint8_t mtx_col_offset = 0;
// Start Column in der Zeichen-Matrix
// Abhängig von Zeichen-Breite
// Bsp: Font hat Breite von 5, Zeichen hat Breite 3
// --> dann brauchen wir nur die Spalten 2-4
// denn die Spalten 0 u. 1 haben keine gesetzten Bits
uint8_t start_col = 5 - char_width_pixel;
for (int col = start_col; col < 5; col++)
uint8_t start_col = font_width - char_width_pixel;
for (int col = start_col; col < font_width; col++)
{
drawPixel(x + mtx_col_offset, y + row, CRGB::SlateGrey);
if (line & (1 << (4 - col)))
if (line & (1 << ((font_width - 1) - col)))
{
drawPixel(x + mtx_col_offset, y + row, color);
}
@@ -83,21 +89,21 @@ void LedMatrix::drawText(int x, int y, const char *text, CRGB color)
}
}
vector<uint8_t> LedMatrix::number_to_bitarray_msb(uint16_t number, int bits, boolean four_bits)
vector<uint16_t> LedMatrix::number_to_bitarray_msb(uint16_t number, int bits, boolean four_bits)
{
/** Convert 8/16-bit number to bit array (MSB first) */
std::vector<uint8_t> byte;
byte.reserve(bits);
std::vector<uint16_t> two_bytes;
two_bytes.reserve(bits);
for (int i = bits - 1; i >= 0; i--)
{
byte.push_back((number >> i) & 1);
two_bytes.push_back((number >> i) & 1);
}
// Debug, Ausgabe des Bytes
Serial.printf("[0x%02X] ", number);
Serial.printf("[0x%04X] ", number);
uint8_t idx = 0;
for (auto bit : byte)
for (auto bit : two_bytes)
{
Serial.printf("%d", bit);
idx++;
@@ -106,5 +112,5 @@ vector<uint8_t> LedMatrix::number_to_bitarray_msb(uint16_t number, int bits, boo
}
Serial.println();
return byte;
return two_bytes;
}

View File

@@ -7,7 +7,9 @@ using namespace std;
#include <FastLED.h>
#include <vector>
#include <font_5x7.h>
// #include <font_5x7.h>
// #include <font_8x8.h>
#include <font_16x16.h>
class LedMatrix : public CFastLED
{
@@ -20,7 +22,7 @@ private:
vector<CRGB> leds; // Automatic memory management
template <size_t N>
uint8_t charWidth(const uint8_t *charMatrix);
uint8_t charWidth(const uint16_t *charMatrix);
public:
LedMatrix(uint8_t h = 64, uint8_t w = 64);
@@ -32,7 +34,7 @@ public:
// Draw text string
void drawText(int x, int y, const char *text, CRGB color);
vector<uint8_t> number_to_bitarray_msb(uint16_t number, int bits = 8, boolean four_bits = false);
vector<uint16_t> number_to_bitarray_msb(uint16_t number, int bits = 8, boolean four_bits = false);
};
#endif