27 static const uint8_t digitTable7Seg[]={0b10111110, 0b00000110, 0b01111100, 0b01011110, 0b11000110,
28 0b11011010, 0b11111010, 0b00001110, 0b11111110, 0b11011110};
30 static const uint8_t charTable7Seg[]={
32 0b11101110, 0b11110010, 0b01110000, 0b01110110, 0b11111000, 0b11101000,
34 0b10111010, 0b11100110, 0b00000010, 0b00110110, 0b11100101, 0b10110000,
36 0b10101110, 0b01100010, 0b01110010, 0b11101100, 0b11001111, 0b01100000,
38 0b11011010, 0b11110000, 0b10110110, 0b00110010, 0b10110111, 0b11100110,
40 0b11100100, 0b01111100 };
44 static const uint8_t cmdBIAS = 0x52;
45 static const uint8_t cmdSYS_DIS = 0X00;
46 static const uint8_t cmdSYS_EN = 0X02;
47 static const uint8_t cmdLCD_OFF = 0X04;
48 static const uint8_t cmdLCD_ON = 0X06;
49 static const uint8_t cmdWDT_DIS = 0X0A;
50 static const uint8_t cmdRC_256K = 0X30;
57 uint8_t lcdBacklightPin;
58 uint8_t pwmIndexEsp32;
65 static const long clearDelayMs = 2;
66 static const long printDelayMs = 2;
67 static const long writeDelayUs = 4;
73 uint8_t *outputBuffer;
81 enum LcdType {lcd12digit_7segment, lcd10digit_16segment};
82 static const uint8_t frameBufferSize=12;
83 uint16_t frameBuffer[frameBufferSize];
85 Ht162xDigits(LcdType lcdType, uint8_t csPin, uint8_t wrPin, uint8_t dataPin, uint8_t lcdBacklightPin=-1, uint8_t pwmIndexEsp32=-1)
86 : name(name), lcdType(lcdType), csPin(csPin), wrPin(wrPin), dataPin(dataPin), lcdBacklightPin(lcdBacklightPin), pwmIndexEsp32(pwmIndexEsp32) {
95 case LcdType::lcd12digit_7segment:
101 case LcdType::lcd10digit_16segment:
117 pinMode(csPin, OUTPUT);
118 pinMode(wrPin, OUTPUT);
119 pinMode(dataPin, OUTPUT);
120 if (lcdBacklightPin!=-1) pinMode(lcdBacklightPin, OUTPUT);
123 case LcdType::lcd12digit_7segment:
125 writeCmd(cmdRC_256K);
126 writeCmd(cmdSYS_DIS);
127 writeCmd(cmdWDT_DIS);
132 case LcdType::lcd10digit_16segment:
134 writeCmd(cmdRC_256K);
135 writeCmd(cmdSYS_DIS);
136 writeCmd(cmdWDT_DIS);
154 driver.setPowerSave(powersave);
161 driver.setIntensity(intensity);
169 driver.setTestMode(testmode);
211 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t pattern = B00000000) {
212 x = x < 0 ? 0 : x >= _width ? _width - 1 : x;
213 y = y < 0 ? 0 : y >= _height ? _height - 1 : y;
214 w = w < 0 ? 0 : w >= _width - x ? _width - x : w;
215 h = h < 0 ? 0 : h >= _height - y ? _height - y : h;
217 for (int16_t yy = y; yy < y + h; yy++) {
218 memset(bitmap + yy * _width + x, pattern, w);
235 bool printFormatted(int16_t x, int16_t y, int16_t w, int16_t align, String content) {
236 uint8_t shadowBuffer[8];
237 x = x < 0 ? 0 : x >= _width ? _width - 1 : x;
238 y = y < 0 ? 0 : y >= _height ? _height - 1 : y;
239 w = w < 0 ? 0 : w >= _width - x ? _width - x : w;
240 memset(bitmap + y * _width + x, B00000000, w);
241 uint8_t *pDst = shadowBuffer;
242 const unsigned char *pSrc = (
unsigned char *)content.c_str();
243 while (pDst < shadowBuffer + 8 && *pSrc) {
246 }
else if (*pSrc ==
'.' || *pSrc ==
',') {
247 if (pDst == shadowBuffer) {
253 }
else if (*pSrc ==
' ') {
255 }
else if (*pSrc ==
'-') {
257 }
else if (*pSrc ==
'_') {
259 }
else if (*pSrc ==
'=') {
261 }
else if (*pSrc >=
'0' && *pSrc <=
'9') {
262 *pDst = pgm_read_byte_near(digitTable7Seg + *pSrc -
'0');
263 }
else if (*pSrc >=
'A' && *pSrc <=
'Z') {
264 *pDst = pgm_read_byte_near(charTable7Seg + *pSrc -
'A');
265 }
else if (*pSrc >=
'a' && *pSrc <=
'z') {
266 *pDst = pgm_read_byte_near(charTable7Seg + *pSrc -
'a');
273 int16_t size = pDst - shadowBuffer;
275 pDst = bitmap + (y * length) + x;
280 memcpy(pDst, shadowBuffer, min(w, size));
286 offs = (size - w) / 2;
287 memcpy(pDst, shadowBuffer + offs, w);
290 offs = (w - size) / 2;
291 memcpy(pDst + offs, shadowBuffer, size);
299 memcpy(pDst, shadowBuffer + offs, w);
303 memcpy(pDst + offs, shadowBuffer, size);
307 return *pSrc == 0 && size <= w;
317 if (bitmap !=
nullptr) {
318 for (uint8_t digit = 0; digit < length; digit++) {
319 uint16_t endOffset = digit;
320 uint16_t startOffset = bitmapSize + endOffset;
321 uint8_t *pPtr = outputBuffer;
323 startOffset -= length;
325 pPtr[1] = bitmap[startOffset];
327 }
while (startOffset > endOffset);
328 driver.sendBlock(outputBuffer, pPtr - outputBuffer);
337 if (bitmap !=
nullptr) {
338 memset(bitmap, pattern, length * driver.getChainLen());
383 uint8_t
getCharLen(
unsigned char c,
bool firstChar =
false) {
386 }
else if (c ==
'.' || c ==
',') {
387 return firstChar ? 1 : 0;
393 virtual size_t write(uint8_t c) {
396 }
else if (c ==
'\n') {
400 if (wrap && cursor_x >= _width) {
404 if (cursor_x >= _width || cursor_y >= _height) {
408 if (cursor_x < 0 || cursor_y < 0) {
413 uint8_t index = cursor_y * _width + cursor_x;
416 }
else if (c ==
'.' || c ==
',') {
418 bitmap[index] = B10000000;
420 bitmap[index - 1] |= B10000000;
423 }
else if (c ==
' ') {
424 bitmap[index] = B00000000;
425 }
else if (c ==
'-') {
426 bitmap[index] = B00000001;
427 }
else if (c ==
'_') {
428 bitmap[index] = B00001000;
429 }
else if (c ==
'=') {
430 bitmap[index] = B00001001;
431 }
else if (c >=
'0' && c <=
'9') {
432 bitmap[index] = pgm_read_byte_near(digitTable7Seg + c -
'0');
433 }
else if (c >=
'A' && c <=
'Z') {
434 bitmap[index] = pgm_read_byte_near(charTable7Seg + c -
'A');
435 }
else if (c >=
'a' && c <=
'z') {
436 bitmap[index] = pgm_read_byte_near(charTable7Seg + c -
'a');
438 bitmap[index] = B00001000;
The HT162X Digits Display Class.
Definition: ht162x_digits.h:25
int16_t getCursorY() const
Definition: ht162x_digits.h:375
void setCursorX(int16_t x)
Definition: ht162x_digits.h:184
int16_t height() const
Definition: ht162x_digits.h:354
int16_t getCursorX() const
Definition: ht162x_digits.h:368
virtual void fillScreen(uint8_t pattern)
Definition: ht162x_digits.h:336
void begin()
Definition: ht162x_digits.h:115
int16_t width() const
Definition: ht162x_digits.h:347
void setIntensity(uint8_t intensity)
Definition: ht162x_digits.h:160
void setCursorY(int16_t y)
Definition: ht162x_digits.h:191
void setCursor(int16_t x, int16_t y)
Definition: ht162x_digits.h:176
void setTextWrap(bool w)
Definition: ht162x_digits.h:199
void setPowerSave(bool powersave)
Definition: ht162x_digits.h:153
bool printFormatted(int16_t x, int16_t y, int16_t w, int16_t align, String content)
Definition: ht162x_digits.h:235
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t pattern=B00000000)
Definition: ht162x_digits.h:211
Ht162xDigits(LcdType lcdType, uint8_t csPin, uint8_t wrPin, uint8_t dataPin, uint8_t lcdBacklightPin=-1, uint8_t pwmIndexEsp32=-1)
Definition: ht162x_digits.h:85
void setTestMode(bool testmode)
Definition: ht162x_digits.h:168
uint8_t getCharLen(unsigned char c, bool firstChar=false)
Definition: ht162x_digits.h:383
void write()
Definition: ht162x_digits.h:316
bool getTextWrap() const
Definition: ht162x_digits.h:361
@ digit0
Digit 0.
Definition: max72xx.h:24
The muwerk namespace.
Definition: display_digits_max72xx.h:10