v.0.0.4 uint8_t charWidth(const uint8_t *charMatrix);
This commit is contained in:
@@ -12,44 +12,3 @@ const uint8_t *getFontChar(char c)
|
||||
}
|
||||
return font_5x7[52]; // Return space if not found (index of ' ')
|
||||
}
|
||||
|
||||
// Function to get character width
|
||||
uint8_t getCharWidth(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '!':
|
||||
case '.':
|
||||
case ':':
|
||||
case ';':
|
||||
case '\'':
|
||||
case '|':
|
||||
case ' ':
|
||||
return 1;
|
||||
case 'I':
|
||||
case 'i':
|
||||
case 'j':
|
||||
case 'l':
|
||||
case '(':
|
||||
case ')':
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
// Nachher (Korrektur):
|
||||
case 176: // '°' als ASCII Code
|
||||
case 149: // '•' als ASCII Code
|
||||
return 3;
|
||||
case 'a':
|
||||
case 'c':
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'k':
|
||||
case '<':
|
||||
case '>':
|
||||
case '`':
|
||||
return 4;
|
||||
default:
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,5 @@ const char font_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0
|
||||
|
||||
// Declarations only
|
||||
const uint8_t *getFontChar(char c);
|
||||
uint8_t getCharWidth(char c);
|
||||
|
||||
#endif
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user