v.0.0.2 number_to_bitarray_msb
This commit is contained in:
@@ -21,12 +21,16 @@ void LedMatrix::drawPixel(int x, int y, CRGB color)
|
||||
|
||||
void LedMatrix::drawChar(int x, int y, char c, CRGB color)
|
||||
{
|
||||
u_int8_t char_width_pixel = getCharWidth(c);
|
||||
// Serial.printf("Char '%c' -> width %d\n\r", c, char_width_pixel);
|
||||
|
||||
const uint8_t *fontData = getFontChar(c);
|
||||
for (int row = 0; row < 7; row++)
|
||||
{
|
||||
uint8_t line = fontData[row];
|
||||
for (int col = 0; col < 5; col++)
|
||||
for (int col = 0; col < 5 /*char_width_pixel*/; col++)
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::SlateGrey);
|
||||
if (line & (1 << (4 - col)))
|
||||
{
|
||||
drawPixel(x + col, y + row, color);
|
||||
@@ -35,17 +39,60 @@ void LedMatrix::drawChar(int x, int y, char c, CRGB color)
|
||||
}
|
||||
}
|
||||
|
||||
void LedMatrix::_drawChar_(int x, int y, char c, CRGB color)
|
||||
{
|
||||
u_int8_t char_width_pixel = getCharWidth(c);
|
||||
// Serial.printf("Char '%c' -> width %d\n\r", c, char_width_pixel);
|
||||
|
||||
const uint8_t *fontData = getFontChar(c);
|
||||
for (int row = 0; row < 7; row++)
|
||||
{
|
||||
uint8_t line = fontData[row];
|
||||
for (int col = 5 - char_width_pixel; col < 5; col++)
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::SlateGrey);
|
||||
if (line & (1 << (4 - col)))
|
||||
{
|
||||
drawPixel(x + col, y + row, CRGB::GhostWhite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw text string
|
||||
void LedMatrix::drawText(int x, int y, const char *text, CRGB color)
|
||||
{
|
||||
int cursorX = x;
|
||||
for (int i = 0; text[i] != '\0'; i++)
|
||||
{
|
||||
u_int8_t w = getCharWidth(text[i]);
|
||||
// Debug output
|
||||
Serial.printf("Char %d: '%c' -> width %d at X=%d\n\r",
|
||||
i, text[i], w, cursorX);
|
||||
drawChar(cursorX, y, text[i], color);
|
||||
_drawChar_(cursorX, 8 + y, text[i], color);
|
||||
cursorX += 6; // 5 pixels width + 1 pixel spacing
|
||||
}
|
||||
}
|
||||
|
||||
vector<uint8_t> LedMatrix::number_to_bitarray_msb(uint16_t number, int bits)
|
||||
{
|
||||
/** Convert 8/16-bit number to bit array (MSB first) */
|
||||
std::vector<uint8_t> byte;
|
||||
byte.reserve(bits);
|
||||
|
||||
for (int i = bits - 1; i >= 0; i--)
|
||||
{
|
||||
byte.push_back((number >> i) & 1);
|
||||
}
|
||||
|
||||
// Debug, Ausgabe des Bytes
|
||||
Serial.printf("0x%02X\n\r", number);
|
||||
uint8_t idx = 0;
|
||||
for (auto bit : byte)
|
||||
{
|
||||
Serial.printf("%d", bit);
|
||||
idx++;
|
||||
if (!(idx % 4))
|
||||
Serial.printf(" ");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
return byte;
|
||||
}
|
||||
@@ -26,8 +26,11 @@ public:
|
||||
|
||||
void drawPixel(int x, int y, CRGB color);
|
||||
void drawChar(int x, int y, char c, CRGB color);
|
||||
void _drawChar_(int x, int y, char c, CRGB color);
|
||||
// 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);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user