Merge pull request #378 from cyberman54/development
LED matrix display improvements
This commit is contained in:
commit
82fdfb9ca1
@ -9,8 +9,7 @@ extern uint8_t DisplayIsOn;
|
||||
extern HAS_DISPLAY u8x8;
|
||||
|
||||
void init_display(const char *Productname, const char *Version);
|
||||
void refreshtheDisplay(void);
|
||||
void refreshtheDisplay(bool nextPage);
|
||||
void refreshTheDisplay(bool nextPage = false);
|
||||
void draw_page(time_t t, uint8_t page);
|
||||
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb);
|
||||
|
||||
|
@ -8,8 +8,8 @@ extern uint8_t MatrixDisplayIsOn;
|
||||
|
||||
extern LEDMatrix matrix;
|
||||
|
||||
void init_matrix_display(const char *Productname, const char *Version);
|
||||
void refreshTheMatrixDisplay(void);
|
||||
void init_matrix_display(bool reverse = false);
|
||||
void refreshTheMatrixDisplay(bool nextPage = false);
|
||||
void DrawNumber(String strNum, uint8_t iDotPos = 0);
|
||||
uint8_t GetCharFromFont(char cChar);
|
||||
uint8_t GetCharWidth(char cChar);
|
||||
|
@ -20,9 +20,12 @@ struct FONT_INFO {
|
||||
const uint8_t *Bitmap;
|
||||
};
|
||||
|
||||
// Font data for Microsoft Sans Serif 11pt
|
||||
// Font data for Arial Narrow 17pt
|
||||
extern const uint8_t arialNarrow_17ptBitmaps[];
|
||||
extern const FONT_INFO arialNarrow_17ptFontInfo;
|
||||
extern const FONT_CHAR_INFO arialNarrow_17ptDescriptors[];
|
||||
|
||||
// Font data for Gill Sans MT Condensed 18pt
|
||||
extern const uint8_t gillSansMTCondensed_18ptBitmaps[];
|
||||
extern const FONT_INFO gillSansMTCondensed_18ptFontInfo;
|
||||
extern const FONT_CHAR_INFO gillSansMTCondensed_18ptDescriptors[];
|
||||
|
@ -23,8 +23,13 @@ void button_init(int pin) {
|
||||
|
||||
b->setOnClicked([]() {
|
||||
#ifdef HAS_DISPLAY
|
||||
refreshtheDisplay(true); // switch to next display page
|
||||
#else
|
||||
refreshTheDisplay(true); // switch to next display page
|
||||
#endif
|
||||
#ifdef HAS_MATRIX_DISPLAY
|
||||
refreshTheMatrixDisplay(true); // switch to next display page
|
||||
#endif
|
||||
|
||||
#if (!defined HAS_DISPLAY) && (!defined HAS_MATRIX_DISPLAY)
|
||||
payload.reset();
|
||||
payload.addButton(0x01);
|
||||
SendPayload(BUTTONPORT, prio_normal);
|
||||
|
@ -129,16 +129,17 @@ void init_display(const char *Productname, const char *Version) {
|
||||
} // mutex
|
||||
} // init_display
|
||||
|
||||
void refreshtheDisplay(bool nextPage) {
|
||||
void refreshTheDisplay(bool nextPage) {
|
||||
|
||||
static uint8_t DisplayPage = 0;
|
||||
const time_t t =
|
||||
myTZ.toLocal(now()); // note: call now() here *before* locking mutex!
|
||||
|
||||
// if display is switched off we don't refresh it to relax cpu
|
||||
if (!DisplayIsOn && (DisplayIsOn == cfg.screenon))
|
||||
return;
|
||||
|
||||
const time_t t =
|
||||
myTZ.toLocal(now()); // note: call now() here *before* locking mutex!
|
||||
|
||||
// block i2c bus access
|
||||
if (I2C_MUTEX_LOCK()) {
|
||||
|
||||
@ -160,8 +161,6 @@ void refreshtheDisplay(bool nextPage) {
|
||||
} // mutex
|
||||
} // refreshDisplay()
|
||||
|
||||
void refreshtheDisplay() { refreshtheDisplay(false); }
|
||||
|
||||
void draw_page(time_t t, uint8_t page) {
|
||||
|
||||
char timeState, buff[16];
|
||||
|
@ -36,7 +36,7 @@ void irqHandler(void *pvParameters) {
|
||||
// display needs refresh?
|
||||
#ifdef HAS_DISPLAY
|
||||
if (InterruptStatus & DISPLAY_IRQ)
|
||||
refreshtheDisplay();
|
||||
refreshTheDisplay();
|
||||
#endif
|
||||
|
||||
// LED Matrix display needs refresh?
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "globals.h"
|
||||
|
||||
#define NUMCHARS 5
|
||||
#define MATRIX_DISPLAY_PAGES (2) // number of display pages
|
||||
|
||||
// local Tag for logging
|
||||
static const char TAG[] = __FILE__;
|
||||
|
||||
uint8_t MatrixDisplayIsOn = 0;
|
||||
static unsigned long ulLastNumMacs = 0;
|
||||
static time_t ulLastTime = myTZ.toLocal(now());
|
||||
|
||||
LEDMatrix matrix(LED_MATRIX_LA_74138, LED_MATRIX_LB_74138, LED_MATRIX_LC_74138,
|
||||
LED_MATRIX_LD_74138, LED_MATRIX_EN_74138, LED_MATRIX_DATA_R1,
|
||||
@ -17,19 +19,27 @@ LEDMatrix matrix(LED_MATRIX_LA_74138, LED_MATRIX_LB_74138, LED_MATRIX_LC_74138,
|
||||
// Display Buffer 128 = 64 * 16 / 8
|
||||
uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / NUMCHARS];
|
||||
|
||||
// --- SELECT YOUR FONT HERE ---
|
||||
const FONT_INFO *ActiveFontInfo = &digital7_18ptFontInfo;
|
||||
//const FONT_INFO *ActiveFontInfo = &arialNarrow_17ptFontInfo;
|
||||
//const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_18ptFontInfo;
|
||||
//const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_16ptFontInfo;
|
||||
|
||||
const uint8_t *iaActiveFont = ActiveFontInfo->Bitmap;
|
||||
const FONT_CHAR_INFO *ActiveFontCharInfo = ActiveFontInfo->Descriptors;
|
||||
|
||||
void init_matrix_display(const char *Productname, const char *Version) {
|
||||
void init_matrix_display(bool reverse) {
|
||||
ESP_LOGI(TAG, "Initializing LED Matrix display");
|
||||
matrix.begin(displaybuf, LED_MATRIX_WIDTH, LED_MATRIX_HEIGHT);
|
||||
//matrix.reverse();
|
||||
if (reverse)
|
||||
matrix.reverse();
|
||||
matrix.clear();
|
||||
DrawNumber(String("0"));
|
||||
} // init_display
|
||||
|
||||
void refreshTheMatrixDisplay() {
|
||||
void refreshTheMatrixDisplay(bool nextPage) {
|
||||
static uint8_t DisplayPage = 0;
|
||||
char buff[16];
|
||||
|
||||
// if Matrixdisplay is switched off we don't refresh it to relax cpu
|
||||
if (!MatrixDisplayIsOn && (MatrixDisplayIsOn == cfg.screenon))
|
||||
@ -40,13 +50,38 @@ void refreshTheMatrixDisplay() {
|
||||
MatrixDisplayIsOn = cfg.screenon;
|
||||
}
|
||||
|
||||
if (ulLastNumMacs != macs.size()) {
|
||||
ulLastNumMacs = macs.size();
|
||||
if (nextPage) {
|
||||
DisplayPage =
|
||||
(DisplayPage >= MATRIX_DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1);
|
||||
matrix.clear();
|
||||
DrawNumber(String(macs.size()));
|
||||
ESP_LOGI(TAG, "Setting display to counter: %lu", macs.size());
|
||||
}
|
||||
|
||||
switch (DisplayPage % MATRIX_DISPLAY_PAGES) {
|
||||
|
||||
// page 0: pax
|
||||
// page 1: time
|
||||
|
||||
case 0:
|
||||
|
||||
if (ulLastNumMacs != macs.size()) {
|
||||
ulLastNumMacs = macs.size();
|
||||
matrix.clear();
|
||||
DrawNumber(String(ulLastNumMacs));
|
||||
}
|
||||
|
||||
case 1:
|
||||
|
||||
const time_t t = myTZ.toLocal(now());
|
||||
if (ulLastTime != t) {
|
||||
ulLastTime = t;
|
||||
matrix.clear();
|
||||
snprintf(buff, sizeof(buff), "%02d:%02d:%02d", hour(t), minute(t),
|
||||
second(t));
|
||||
DrawNumber(String(buff));
|
||||
}
|
||||
|
||||
} // switch page
|
||||
|
||||
matrix.scan();
|
||||
}
|
||||
|
||||
@ -54,12 +89,8 @@ void refreshTheMatrixDisplay() {
|
||||
void DrawChar(uint16_t x, uint16_t y, char cChar) {
|
||||
// Get address of char in font char descriptor from font descriptor
|
||||
auto CharDescAddress = (cChar - ActiveFontInfo->StartChar);
|
||||
|
||||
// Get offset of char into font bitmap
|
||||
uint16_t FontBitmapOffset = ActiveFontCharInfo[CharDescAddress].offset;
|
||||
// Serial.printf("Address of %c is %i, bitmap offset is %u\r\n", cChar,
|
||||
// CharDescAddress, FontBitmapOffset);
|
||||
|
||||
// Check font height, if it's less than matrix height we need to
|
||||
// add some empty lines to font does not stick to the top
|
||||
if (ActiveFontInfo->CharHeight < (LED_MATRIX_HEIGHT - y)) {
|
||||
@ -73,7 +104,6 @@ void DrawChar(uint16_t x, uint16_t y, char cChar) {
|
||||
|
||||
int iDst = (x / 8) + (y * 8);
|
||||
int Shift = x % 8;
|
||||
// Serial.printf("Got hex '%x'\r\n", pSrc);
|
||||
for (uint8_t i = 0; i < ActiveFontCharInfo[CharDescAddress].height; i++) {
|
||||
int iDigitA = iaActiveFont[FontBitmapOffset];
|
||||
|
||||
@ -102,16 +132,9 @@ void DrawNumber(String strNum, uint8_t iDotPos) {
|
||||
uint8_t iNumLength = strNum.length();
|
||||
uint8_t iDigitPos = 0;
|
||||
|
||||
// Serial.printf("Showing number '%s' (length: %i)\r\n", strNum.c_str(),
|
||||
// iNumLength);
|
||||
for (int i = 0; i < iNumLength; i++) {
|
||||
// Serial.printf("Showing char '%c' at x:%i y:%i\r\n",
|
||||
// strNum.charAt(i),
|
||||
// iDigitPos, 0);
|
||||
DrawChar(iDigitPos, 0, strNum.charAt(i));
|
||||
if (i + 1 == iDotPos) {
|
||||
// matrix.drawRect((iDigitPos * 8) - 1, 15, iDigitPos * 8,
|
||||
// 16, 1);
|
||||
iDigitPos = iDigitPos + GetCharWidth(strNum.charAt(i)) +
|
||||
ActiveFontInfo->SpaceWidth;
|
||||
DrawChar(iDigitPos, 0, '.');
|
||||
@ -134,10 +157,8 @@ uint8_t GetCharFromFont(char cChar) {
|
||||
uint8_t GetCharWidth(char cChar) {
|
||||
// Get address of char in font char descriptor from font descriptor
|
||||
auto CharDescAddress = (cChar - ActiveFontInfo->StartChar);
|
||||
|
||||
// Get offset of char into font bitmap
|
||||
auto CharDescriptor = ActiveFontCharInfo[CharDescAddress];
|
||||
// Serial.printf("Char %c is %i wide\r\n", cChar, CharDescriptor.width);
|
||||
return CharDescriptor.width;
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,35 @@ const uint8_t arialNarrow_17ptBitmaps[] = {
|
||||
0b00011100, 0b00000000, // ###
|
||||
};
|
||||
|
||||
// Character descriptors for Arial Narrow 17pt
|
||||
// { [Char width in bits], [Char height in bits], [Offset into
|
||||
// arialNarrow_17ptBitmaps in bytes] }
|
||||
const FONT_CHAR_INFO arialNarrow_17ptDescriptors[] = {
|
||||
{10, 16, 0}, // -
|
||||
{0, 0, 0}, // .
|
||||
{0, 0, 0}, // /
|
||||
{10, 16, 32}, // 0
|
||||
{10, 16, 64}, // 1
|
||||
{10, 16, 80}, // 2
|
||||
{10, 16, 112}, // 3
|
||||
{10, 16, 144}, // 4
|
||||
{10, 16, 176}, // 5
|
||||
{10, 16, 208}, // 6
|
||||
{10, 16, 240}, // 7
|
||||
{10, 16, 272}, // 8
|
||||
{10, 16, 304}, // 9
|
||||
};
|
||||
|
||||
// Font information for Arial Narrow 17pt
|
||||
|
||||
const FONT_INFO arialNarrow_17ptFontInfo = {
|
||||
16, // Character height
|
||||
'-', // Start character
|
||||
'9', // End character
|
||||
2, // Width, in pixels, of space character
|
||||
arialNarrow_17ptDescriptors, // Character descriptor array
|
||||
arialNarrow_17ptBitmaps}; // Character bitmap array
|
||||
|
||||
//
|
||||
// Font data for Gill Sans MT Condensed 18pt
|
||||
//
|
||||
@ -431,7 +460,7 @@ const FONT_CHAR_INFO gillSansMTCondensed_18ptDescriptors[] = {
|
||||
|
||||
// Font information for Gill Sans MT Condensed 18pt
|
||||
const FONT_INFO gillSansMTCondensed_18ptFontInfo = {
|
||||
2, // Character height
|
||||
16, // Character height
|
||||
'-', // Start character
|
||||
'9', // End character
|
||||
2, // Width, in pixels, of space character
|
||||
@ -642,7 +671,7 @@ const FONT_CHAR_INFO gillSansMTCondensed_16ptDescriptors[] = {
|
||||
|
||||
// Font information for Gill Sans MT Condensed 16pt
|
||||
const FONT_INFO gillSansMTCondensed_16ptFontInfo = {
|
||||
2, // Character height
|
||||
14, // Character height
|
||||
'-', // Start character
|
||||
'9', // End character
|
||||
2, // Width, in pixels, of space character
|
||||
|
@ -314,7 +314,7 @@ void setup() {
|
||||
#ifdef HAS_MATRIX_DISPLAY
|
||||
strcat_P(features, " LED_MATRIX");
|
||||
MatrixDisplayIsOn = cfg.screenon;
|
||||
init_matrix_display(PRODUCTNAME, PROGVERSION); // note: blocking call
|
||||
init_matrix_display(); // note: blocking call
|
||||
#endif
|
||||
|
||||
// show payload encoder
|
||||
|
Loading…
Reference in New Issue
Block a user