Merge pull request #378 from cyberman54/development

LED matrix display improvements
This commit is contained in:
Verkehrsrot 2019-05-31 13:21:15 +02:00 committed by GitHub
commit 82fdfb9ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 94 additions and 38 deletions

View File

@ -9,8 +9,7 @@ extern uint8_t DisplayIsOn;
extern HAS_DISPLAY u8x8; extern HAS_DISPLAY u8x8;
void init_display(const char *Productname, const char *Version); void init_display(const char *Productname, const char *Version);
void refreshtheDisplay(void); void refreshTheDisplay(bool nextPage = false);
void refreshtheDisplay(bool nextPage);
void draw_page(time_t t, uint8_t page); void draw_page(time_t t, uint8_t page);
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb); void DisplayKey(const uint8_t *key, uint8_t len, bool lsb);

View File

@ -8,8 +8,8 @@ extern uint8_t MatrixDisplayIsOn;
extern LEDMatrix matrix; extern LEDMatrix matrix;
void init_matrix_display(const char *Productname, const char *Version); void init_matrix_display(bool reverse = false);
void refreshTheMatrixDisplay(void); void refreshTheMatrixDisplay(bool nextPage = false);
void DrawNumber(String strNum, uint8_t iDotPos = 0); void DrawNumber(String strNum, uint8_t iDotPos = 0);
uint8_t GetCharFromFont(char cChar); uint8_t GetCharFromFont(char cChar);
uint8_t GetCharWidth(char cChar); uint8_t GetCharWidth(char cChar);

View File

@ -20,9 +20,12 @@ struct FONT_INFO {
const uint8_t *Bitmap; 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 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 uint8_t gillSansMTCondensed_18ptBitmaps[];
extern const FONT_INFO gillSansMTCondensed_18ptFontInfo; extern const FONT_INFO gillSansMTCondensed_18ptFontInfo;
extern const FONT_CHAR_INFO gillSansMTCondensed_18ptDescriptors[]; extern const FONT_CHAR_INFO gillSansMTCondensed_18ptDescriptors[];

View File

@ -23,8 +23,13 @@ void button_init(int pin) {
b->setOnClicked([]() { b->setOnClicked([]() {
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
refreshtheDisplay(true); // switch to next display page refreshTheDisplay(true); // switch to next display page
#else #endif
#ifdef HAS_MATRIX_DISPLAY
refreshTheMatrixDisplay(true); // switch to next display page
#endif
#if (!defined HAS_DISPLAY) && (!defined HAS_MATRIX_DISPLAY)
payload.reset(); payload.reset();
payload.addButton(0x01); payload.addButton(0x01);
SendPayload(BUTTONPORT, prio_normal); SendPayload(BUTTONPORT, prio_normal);

View File

@ -129,16 +129,17 @@ void init_display(const char *Productname, const char *Version) {
} // mutex } // mutex
} // init_display } // init_display
void refreshtheDisplay(bool nextPage) { void refreshTheDisplay(bool nextPage) {
static uint8_t DisplayPage = 0; 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 display is switched off we don't refresh it to relax cpu
if (!DisplayIsOn && (DisplayIsOn == cfg.screenon)) if (!DisplayIsOn && (DisplayIsOn == cfg.screenon))
return; return;
const time_t t =
myTZ.toLocal(now()); // note: call now() here *before* locking mutex!
// block i2c bus access // block i2c bus access
if (I2C_MUTEX_LOCK()) { if (I2C_MUTEX_LOCK()) {
@ -160,8 +161,6 @@ void refreshtheDisplay(bool nextPage) {
} // mutex } // mutex
} // refreshDisplay() } // refreshDisplay()
void refreshtheDisplay() { refreshtheDisplay(false); }
void draw_page(time_t t, uint8_t page) { void draw_page(time_t t, uint8_t page) {
char timeState, buff[16]; char timeState, buff[16];

View File

@ -36,7 +36,7 @@ void irqHandler(void *pvParameters) {
// display needs refresh? // display needs refresh?
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
if (InterruptStatus & DISPLAY_IRQ) if (InterruptStatus & DISPLAY_IRQ)
refreshtheDisplay(); refreshTheDisplay();
#endif #endif
// LED Matrix display needs refresh? // LED Matrix display needs refresh?

View File

@ -3,12 +3,14 @@
#include "globals.h" #include "globals.h"
#define NUMCHARS 5 #define NUMCHARS 5
#define MATRIX_DISPLAY_PAGES (2) // number of display pages
// local Tag for logging // local Tag for logging
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
uint8_t MatrixDisplayIsOn = 0; uint8_t MatrixDisplayIsOn = 0;
static unsigned long ulLastNumMacs = 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, 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, 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 // Display Buffer 128 = 64 * 16 / 8
uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / NUMCHARS]; uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / NUMCHARS];
// --- SELECT YOUR FONT HERE ---
const FONT_INFO *ActiveFontInfo = &digital7_18ptFontInfo; 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 uint8_t *iaActiveFont = ActiveFontInfo->Bitmap;
const FONT_CHAR_INFO *ActiveFontCharInfo = ActiveFontInfo->Descriptors; 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"); ESP_LOGI(TAG, "Initializing LED Matrix display");
matrix.begin(displaybuf, LED_MATRIX_WIDTH, LED_MATRIX_HEIGHT); matrix.begin(displaybuf, LED_MATRIX_WIDTH, LED_MATRIX_HEIGHT);
//matrix.reverse(); if (reverse)
matrix.reverse();
matrix.clear(); matrix.clear();
DrawNumber(String("0")); DrawNumber(String("0"));
} // init_display } // 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 Matrixdisplay is switched off we don't refresh it to relax cpu
if (!MatrixDisplayIsOn && (MatrixDisplayIsOn == cfg.screenon)) if (!MatrixDisplayIsOn && (MatrixDisplayIsOn == cfg.screenon))
@ -40,13 +50,38 @@ void refreshTheMatrixDisplay() {
MatrixDisplayIsOn = cfg.screenon; MatrixDisplayIsOn = cfg.screenon;
} }
if (ulLastNumMacs != macs.size()) { if (nextPage) {
ulLastNumMacs = macs.size(); DisplayPage =
(DisplayPage >= MATRIX_DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1);
matrix.clear(); 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(); matrix.scan();
} }
@ -54,12 +89,8 @@ void refreshTheMatrixDisplay() {
void DrawChar(uint16_t x, uint16_t y, char cChar) { void DrawChar(uint16_t x, uint16_t y, char cChar) {
// Get address of char in font char descriptor from font descriptor // Get address of char in font char descriptor from font descriptor
auto CharDescAddress = (cChar - ActiveFontInfo->StartChar); auto CharDescAddress = (cChar - ActiveFontInfo->StartChar);
// Get offset of char into font bitmap // Get offset of char into font bitmap
uint16_t FontBitmapOffset = ActiveFontCharInfo[CharDescAddress].offset; 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 // 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 // add some empty lines to font does not stick to the top
if (ActiveFontInfo->CharHeight < (LED_MATRIX_HEIGHT - y)) { 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 iDst = (x / 8) + (y * 8);
int Shift = x % 8; int Shift = x % 8;
// Serial.printf("Got hex '%x'\r\n", pSrc);
for (uint8_t i = 0; i < ActiveFontCharInfo[CharDescAddress].height; i++) { for (uint8_t i = 0; i < ActiveFontCharInfo[CharDescAddress].height; i++) {
int iDigitA = iaActiveFont[FontBitmapOffset]; int iDigitA = iaActiveFont[FontBitmapOffset];
@ -102,16 +132,9 @@ void DrawNumber(String strNum, uint8_t iDotPos) {
uint8_t iNumLength = strNum.length(); uint8_t iNumLength = strNum.length();
uint8_t iDigitPos = 0; uint8_t iDigitPos = 0;
// Serial.printf("Showing number '%s' (length: %i)\r\n", strNum.c_str(),
// iNumLength);
for (int i = 0; i < iNumLength; i++) { 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)); DrawChar(iDigitPos, 0, strNum.charAt(i));
if (i + 1 == iDotPos) { if (i + 1 == iDotPos) {
// matrix.drawRect((iDigitPos * 8) - 1, 15, iDigitPos * 8,
// 16, 1);
iDigitPos = iDigitPos + GetCharWidth(strNum.charAt(i)) + iDigitPos = iDigitPos + GetCharWidth(strNum.charAt(i)) +
ActiveFontInfo->SpaceWidth; ActiveFontInfo->SpaceWidth;
DrawChar(iDigitPos, 0, '.'); DrawChar(iDigitPos, 0, '.');
@ -134,10 +157,8 @@ uint8_t GetCharFromFont(char cChar) {
uint8_t GetCharWidth(char cChar) { uint8_t GetCharWidth(char cChar) {
// Get address of char in font char descriptor from font descriptor // Get address of char in font char descriptor from font descriptor
auto CharDescAddress = (cChar - ActiveFontInfo->StartChar); auto CharDescAddress = (cChar - ActiveFontInfo->StartChar);
// Get offset of char into font bitmap // Get offset of char into font bitmap
auto CharDescriptor = ActiveFontCharInfo[CharDescAddress]; auto CharDescriptor = ActiveFontCharInfo[CharDescAddress];
// Serial.printf("Char %c is %i wide\r\n", cChar, CharDescriptor.width);
return CharDescriptor.width; return CharDescriptor.width;
} }

View File

@ -205,6 +205,35 @@ const uint8_t arialNarrow_17ptBitmaps[] = {
0b00011100, 0b00000000, // ### 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 // 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 // Font information for Gill Sans MT Condensed 18pt
const FONT_INFO gillSansMTCondensed_18ptFontInfo = { const FONT_INFO gillSansMTCondensed_18ptFontInfo = {
2, // Character height 16, // Character height
'-', // Start character '-', // Start character
'9', // End character '9', // End character
2, // Width, in pixels, of space 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 // Font information for Gill Sans MT Condensed 16pt
const FONT_INFO gillSansMTCondensed_16ptFontInfo = { const FONT_INFO gillSansMTCondensed_16ptFontInfo = {
2, // Character height 14, // Character height
'-', // Start character '-', // Start character
'9', // End character '9', // End character
2, // Width, in pixels, of space character 2, // Width, in pixels, of space character
@ -900,4 +929,4 @@ const FONT_INFO digital7_18ptFontInfo = {
2, // Width, in pixels, of space character 2, // Width, in pixels, of space character
digital7_18ptDescriptors, // Character descriptor array digital7_18ptDescriptors, // Character descriptor array
digital7_18ptBitmaps, // Character bitmap array digital7_18ptBitmaps, // Character bitmap array
}; };

View File

@ -314,7 +314,7 @@ void setup() {
#ifdef HAS_MATRIX_DISPLAY #ifdef HAS_MATRIX_DISPLAY
strcat_P(features, " LED_MATRIX"); strcat_P(features, " LED_MATRIX");
MatrixDisplayIsOn = cfg.screenon; MatrixDisplayIsOn = cfg.screenon;
init_matrix_display(PRODUCTNAME, PROGVERSION); // note: blocking call init_matrix_display(); // note: blocking call
#endif #endif
// show payload encoder // show payload encoder