v.0.0.4 uint8_t charWidth(const uint8_t *charMatrix);

This commit is contained in:
tiijay
2025-11-04 14:08:51 +01:00
parent ef341ea7ea
commit 6377983edd
4 changed files with 17 additions and 44 deletions

View File

@@ -10,6 +10,18 @@ LedMatrix::~LedMatrix()
{
}
template <size_t N>
uint8_t LedMatrix::charWidth(const uint8_t *charMatrix)
{
uint8_t max_val = 0;
for (size_t i = 0; i < N; i++)
{
if (charMatrix[i] > max_val)
max_val = charMatrix[i];
}
return (max_val == 0) ? 0 : (32 - __builtin_clz(max_val));
}
void LedMatrix::drawPixel(int x, int y, CRGB color)
{
if (x >= 0 && x < 64 && y >= 0 && y < 64)
@@ -21,9 +33,9 @@ void LedMatrix::drawPixel(int x, int y, CRGB color)
uint8_t LedMatrix::drawChar(int x, int y, char c, CRGB color)
{
u_int8_t char_width_pixel = getCharWidth(c);
const uint8_t *fontData = getFontChar(c);
const u_int8_t char_width_pixel = charWidth<7>(fontData);
for (int row = 0; row < 7; row++)
{
uint8_t line = fontData[row];

View File

@@ -19,6 +19,9 @@ private:
uint16_t num_leds; // default 64x64 = 4096 LEDs
vector<CRGB> leds; // Automatic memory management
template <size_t N>
uint8_t charWidth(const uint8_t *charMatrix);
public:
LedMatrix(uint8_t h = 64, uint8_t w = 64);