Seven Segments Displays Agnostic Library for ESP32 (Arduino) v3.2.0
A library that provides a class that models a Seven Segment Display and provides an unified API through it's members independently of the display technology.
Loading...
Searching...
No Matches
SevenSegDispHw.h
Go to the documentation of this file.
1
41#ifndef sevenSegDispHw_ESP32_H
42#define sevenSegDispHw_ESP32_H
43
44#include "Arduino.h"
45#include <stdint.h>
46#include <ShiftRegGPIOXpander_ESP32.h>
47
48//============================================================> Class declarations separator
49
62 static uint8_t _dspHwSerialNum;
63private:
64 virtual void _unAbstract() = 0; // Makes this an Abstract class. For the subclasses to be instantiable they'll have to implement the _unAbstract() method.
65
66protected:
67 uint8_t* _ioPins{};
68 uint8_t* _digitPosPtr{nullptr};
69 uint8_t _dspDigitsQty{}; // Display size in digits
70 bool _commAnode {true}; // SevenSegDisplays objects need this info to build the right segments to represent each character
71 const uint8_t _dspDigitsQtyMax{0};
72
73 uint8_t _allLedsOff{};
74 uint8_t _brghtnssLvl{0};
75 uint8_t _brghtnssLvlMax{0};
76 uint8_t _brghtnssLvlMin{0};
77 uint8_t* _dspBlankBuffPtr{nullptr};
78 uint8_t* _dspBuffPtr{nullptr};
79 uint8_t* _dspBuffPtrBkp{nullptr};
80 SevenSegDispHw* _dspHwInstance{nullptr};
81 uint8_t _dspHwInstNbr{0};
82 bool _isOn{false};
83 uint8_t* _xcdDspBuffPtr{nullptr};
84 uint8_t _xcdDspDigitsQty{};
85
86public:
105 SevenSegDispHw(uint8_t* ioPins, uint8_t dspDigits = 4, bool commAnode = true, uint8_t dspDigitsQtyMax = 0);
109 virtual ~SevenSegDispHw();
125 virtual bool begin(uint32_t updtLps = 0);
134 virtual bool end();
144 virtual uint8_t getBrghtnssLvl();
154 virtual uint8_t getBrghtnssMaxLvl();
164 virtual uint8_t getBrghtnssMinLvl();
173 bool getCommAnode();
183 uint8_t* getDspBuffPtr();
193 uint8_t getHwDspDigitsQty();
202 virtual bool getIsOn();
208 uint8_t* getxcdDspBuffPtr();
216 virtual void ntfyUpdDsply();
227 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
247 virtual bool setDigitsOrder(uint8_t* newOrderPtr);
261 void setDspBuffPtr(uint8_t* newDspBuffPtr);
270 virtual void turnOff();
276 virtual void turnOn();
286 virtual void turnOn(const uint8_t &newBrghtnssLvl);
287};
288
289//============================================================> Class declarations separator
290
296class SevenSegDynamic: public SevenSegDispHw{
297 static void tmrCbRfrshDyn(TimerHandle_t rfrshTmrCbArg);
298
299private:
300 virtual void _unAbstract() = 0; // Makes this an Abstract class.
301
302protected:
303 TimerHandle_t _dynDspRfrshTmrHndl{NULL};
304 uint8_t _firstRefreshed{0};
305 String _rfrshTmrName{""};
306
307 void _refresh();
308
309public:
310 SevenSegDynamic();
311 SevenSegDynamic(uint8_t* ioPins, uint8_t dspDigits, bool commAnode, uint8_t dspDigitsQtyMax = 0);
312 virtual ~SevenSegDynamic();
324 virtual bool begin(uint32_t updtLps=0);
331 virtual bool end();
332};
333
334//============================================================> Class declarations separator
335
344class SevenSegDynHC595: public SevenSegDynamic{
345 static void tmrCbRfrshDynHC595(TimerHandle_t rfrshTmrCbArg);
346
347private:
348 const uint8_t _sclkIndx {0};
349 const uint8_t _rclkIndx {1};
350 const uint8_t _dioIndx {2};
351
352 ShiftRegGPIOXpander* _drvrShftRegPtr{nullptr};
353 uint8_t* _drvrShftRegSndPtr{nullptr};
354 uint8_t _sclk {};
355 uint8_t _rclk {};
356 uint8_t _dio {};
357
358 virtual void _unAbstract();
359
360protected:
361 const uint8_t _dspDigitsQtyMax{8};
362 TimerHandle_t _dynHC595DspRfrshTmrHndl{NULL};
363
364 void _refresh();
365
366public:
374 SevenSegDynHC595(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
379 virtual ~SevenSegDynHC595();
395 virtual bool begin(uint32_t updtLps = 0);
411 bool end();
412};
413
414//============================================================> Class declarations separator
415
428class SevenSegDynDummy: public SevenSegDynamic{
429 static void tmrCbRfrshDynDummy(TimerHandle_t rfrshTmrCbArg);
430
431private:
432 virtual void _unAbstract();
433
434protected:
435 // static TimerHandle_t _dynDummyDspRfrshTmrHndl;
436 TimerHandle_t _dynDummyDspRfrshTmrHndl{NULL};
437
438 void _refresh();
439 virtual void send(const uint8_t &segments, const uint8_t &port);
440
441public:
448 SevenSegDynDummy(uint8_t dspDigits = 4, bool commAnode = true);
452 virtual ~SevenSegDynDummy();
467 bool begin(uint32_t updtLps = 0);
473 bool end();
474
475 virtual void turnOff();
476
477 virtual void turnOn();
478
479};
480
481//============================================================> Class declarations separator
482
501class SevenSegStatic: public SevenSegDispHw{
502private:
503 virtual void _unAbstract() = 0; // Makes this an Abstract class.
504
505public:
506 SevenSegStatic();
507 SevenSegStatic(uint8_t* ioPins, uint8_t dspDigits = 4, bool commAnode = true, uint8_t dspDigitsQtyMax = 0);
508 virtual ~SevenSegStatic();
509};
510
511//============================================================> Class declarations separator
512
522class SevenSegStatHC595: public SevenSegStatic{
523private:
524 const uint8_t _sclkIndx {0};
525 const uint8_t _rclkIndx {1};
526 const uint8_t _dioIndx {2};
527
528 ShiftRegGPIOXpander* _dsplyHwShftRegPtr{nullptr};
529 uint8_t* _lclDspBuffPtr{nullptr};
530 uint8_t _sclk {};
531 uint8_t _rclk {};
532 uint8_t _dio {};
533
534 virtual void _unAbstract();
535 void _updDsplyCntnt();
536
537 public:
549 SevenSegStatHC595(uint8_t* ioPins, uint8_t dspDigits = 4, bool commAnode = true);
553 virtual ~SevenSegStatHC595();
554
555 virtual bool begin(uint32_t updtLps = 0);
559 virtual void ntfyUpdDsply();
560};
561
562//============================================================> Class declarations separator
563
587class SevenSegTM163X: public SevenSegStatic{
588private:
589 const uint8_t _clkIndx {0};
590 const uint8_t _dioIndx {1};
591 const uint8_t _hwBrghtnssLvlMax{0x07};
592 const uint8_t _hwBrghtnssLvlMin{0x00};
593 uint32_t _txClkTckTm{2};
594 uint8_t _clk {};
595 uint8_t _dio {};
596
597 virtual void _unAbstract() = 0; // Makes this an Abstract class explicitly for documentation generation.
598 void _updLclBffrCntnt();
599
600protected:
601 uint8_t* _lclDspBuffPtr{nullptr};
602 uint8_t _dspDigitsQtyMax{}; // Maximum display size in digits
603
604 void _txStart();
605 void _txAsk();
606 void _txStop();
607 void _txWrByte(uint8_t data);
608 virtual void _sendBffr();
609 virtual bool _sendByte(uint8_t data);
610
611 public:
624 SevenSegTM163X(uint8_t* ioPins, uint8_t dspDigits, bool commAnode, uint8_t dspDigitsQtyMax = 0);
638 bool begin(uint32_t updtLps = 0);
644 bool end();
654 virtual uint8_t getBrghtnssLvl();
658 virtual void ntfyUpdDsply();
667 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
673 virtual void turnOff();
679 virtual void turnOn();
687 virtual void turnOn(const uint8_t &newBrghtnssLvl);
688};
689
690//============================================================> Class declarations separator
691
701private:
702 virtual void _unAbstract();
703
704protected:
705 const uint8_t _dspDigitsQtyMax{4}; // Maximum display controller managing digits capabilities
706
707public:
719 SevenSegTM1636(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
723 virtual ~SevenSegTM1636();
724};
725
726//============================================================> Class declarations separator
727
737private:
738 const uint8_t _dspDigitsQtyMax{6}; // Maximum display size in digits
739 virtual void _unAbstract();
740
741public:
753 SevenSegTM1637(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
758};
759
760//============================================================> Class declarations separator
761
771private:
772 const uint8_t _dspDigitsQtyMax{8}; // Maximum display size in digits
773 virtual void _unAbstract();
774
775public:
787 SevenSegTM1639(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
792};
793
794//============================================================> Class declarations separator
795
832class SevenSegMax7219: public SevenSegStatic{
833 // Address Map Constants
834 const uint8_t _NoOpAddr{0x00};
835 const uint8_t _DspPortsBaseAddr{0x01};
836 const uint8_t _DecodeModeAddr{0x09};
837 const uint8_t _BrghtnsSettAddr{0x0A};
838 const uint8_t _ScanLimitAddr{0x0B};
839 const uint8_t _ShutDownAddr{0x0C};
840 const uint8_t _DspTestAddr{0x0F};
841
842 // Valid parameters constants
843 const uint8_t _DisplayTestMode{0x01};
844 const uint8_t _NoDecode{0x00};
845 const uint8_t _NormalOp{0x00};
846 const uint8_t _TurnOff{0x00};
847 const uint8_t _TurnOn{0x01};
848
849private:
850 const uint8_t _clkIndx {0};
851 const uint8_t _dinIndx {1};
852 const uint8_t _csIndx {2};
853
854 const uint8_t _dspDigitsQtyMax{8};
855 const uint8_t _hwBrghtnssLvlMax{0x0F};
856 const uint8_t _hwBrghtnssLvlMin{0x00};
857
858 uint8_t _clk {}; // Serial clock max. rate 10 MHz. Data is shifted into the chip on **clk rising edge**
859 uint8_t _din {}; // Data value to get into the chip reg, must be set before the clk rising edge to be accepted.
860 uint8_t _cs {}; // The data in the internal 16 bits are accepted to be loaded while _cs is low, and will be latched and exposed to pins at _cs rising edge.
861
862 uint8_t _cnvrtStdDgtTo72xxDgt(const uint8_t &StdDgt);
863 virtual void _unAbstract();
864 void _updLclBffrCntnt();
865
866protected:
867 uint8_t* _lclDspBuffPtr{nullptr};
868
869 virtual void _sendByte(const uint8_t &val, const bool &MSbFrst = true);
870 virtual void _sendAddrData(const uint8_t &address, const uint8_t &data, const bool &MSbFrst = true);
871 virtual void _sendBffr();
872
873public:
886 SevenSegMax7219(uint8_t* ioPins, uint8_t dspDigits);
902 bool begin(uint32_t updtLps = 0);
910 bool end();
917 virtual bool getIsOn();
921 virtual void ntfyUpdDsply();
927 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
935 virtual void turnOff();
941 virtual void turnOn();
949 virtual void turnOn(const uint8_t &newBrghtnssLvl);
950};
951
952//============================================================> Class declarations separator
953
954#endif
Base abstract class models a generic Seven Segment display hardware.
Definition SevenSegDispHw.h:61
virtual void ntfyUpdDsply()
Notifies the SevenSegDispHw component object of a change of content available in the display buffer,...
Definition SevenSegDispHw.cpp:126
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:174
virtual uint8_t getBrghtnssLvl()
Returns the current display brightness level setting for the display.
Definition SevenSegDispHw.cpp:86
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, turning the display off and fre...
Definition SevenSegDispHw.cpp:76
virtual ~SevenSegDispHw()
Class destructor.
Definition SevenSegDispHw.cpp:60
uint8_t * getDspBuffPtr()
Returns a pointer to the display buffer.
Definition SevenSegDispHw.cpp:106
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display.
Definition SevenSegDispHw.cpp:131
SevenSegDispHw()
Default class constructor.
Definition SevenSegDispHw.cpp:38
bool _isOn
Current display status: On/Off.
Definition SevenSegDispHw.h:82
uint8_t * _dspBlankBuffPtr
Pointer to a display buffer filled with _allLedsOff ("spaces") to use as display buffer while in "Off...
Definition SevenSegDispHw.h:77
bool getCommAnode()
Returns a value indicating if the display module component of the display hardware uses a common anod...
Definition SevenSegDispHw.cpp:101
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:70
uint8_t * _dspBuffPtrBkp
Pointer to the display buffer, copy of the original **_dspBuffPtr** to be used as backup.
Definition SevenSegDispHw.h:79
uint8_t _brghtnssLvl
Current display brightness level.
Definition SevenSegDispHw.h:74
virtual uint8_t getBrghtnssMaxLvl()
Returns the maximum display brightness level setting allowed for the display.
Definition SevenSegDispHw.cpp:91
uint8_t _xcdDspDigitsQty
Number of unused available display ports, its the difference (_dspDigitsQtyMax - _dspDigitsQty),...
Definition SevenSegDispHw.h:84
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:188
uint8_t * _dspBuffPtr
Pointer to the display buffer, will be provided by the SevenSegDisplays object when it's instantiated...
Definition SevenSegDispHw.h:78
uint8_t * getxcdDspBuffPtr()
Returns a pointer to an array holding the contents for the digits/ports available from the display co...
Definition SevenSegDispHw.cpp:121
uint8_t _allLedsOff
Value to set in the display port to set all leds off (a "space"), dependent of _commAnode.
Definition SevenSegDispHw.h:73
virtual uint8_t getBrghtnssMinLvl()
Returns the minimum display brightness level setting for the display.
Definition SevenSegDispHw.cpp:96
virtual bool getIsOn()
Returns the state of the display.
Definition SevenSegDispHw.cpp:116
uint8_t _brghtnssLvlMin
Minimum display brightness level.
Definition SevenSegDispHw.h:76
uint8_t getHwDspDigitsQty()
Returns the quantity of digits of the display module.
Definition SevenSegDispHw.cpp:111
virtual bool setDigitsOrder(uint8_t *newOrderPtr)
Sets a mapping to relate the display buffer positions to the display port assigned to exhibit it's co...
Definition SevenSegDispHw.cpp:136
uint8_t * _xcdDspBuffPtr
A pointer to a buffer the size of the exceeding digits used to control display specific amenities.
Definition SevenSegDispHw.h:83
void setDspBuffPtr(uint8_t *newDspBuffPtr)
Sets the pointer to the Display Buffer memory area.
Definition SevenSegDispHw.cpp:167
uint8_t _brghtnssLvlMax
Maximum display brightness level.
Definition SevenSegDispHw.h:75
SevenSegDynDummy(uint8_t dspDigits=4, bool commAnode=true)
Class constructor, instantiates a SevenSegDynDummy object.
Definition SevenSegDispHw.cpp:344
bool end()
Stops the active display updating.
Definition SevenSegDispHw.cpp:396
virtual ~SevenSegDynDummy()
Class destructor.
Definition SevenSegDispHw.cpp:349
bool begin(uint32_t updtLps=0)
Sets up the required resources for the "dummy hardware display" to work.
Definition SevenSegDispHw.cpp:361
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:463
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:456
SevenSegDynHC595(uint8_t *ioPins, uint8_t dspDigits, bool commAnode)
Class constructor.
Definition SevenSegDispHw.cpp:245
virtual ~SevenSegDynHC595()
Class destructor.
Definition SevenSegDispHw.cpp:253
virtual bool begin(uint32_t updtLps=0)
Sets up the required resources for the hardware display to work.
Definition SevenSegDispHw.cpp:267
bool end()
Stops the active display updating.
Definition SevenSegDispHw.cpp:299
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work.
Definition SevenSegDispHw.cpp:223
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, stopping and deleting the timer...
Definition SevenSegDispHw.cpp:228
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:917
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display module.
Definition SevenSegDispHw.cpp:903
virtual bool getIsOn()
Returns a value indicating if the display controller is in working/On or shutdown/Off mode.
Definition SevenSegDispHw.cpp:861
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:866
bool end()
Ends the active mode of the display by shutting it off.
Definition SevenSegDispHw.cpp:854
bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:825
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to _dspDigitsQty, the local buffer differs from the shared _dspBuff...
Definition SevenSegDispHw.h:867
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:926
SevenSegMax7219()
Default class constructor.
Definition SevenSegDispHw.cpp:804
~SevenSegMax7219()
Class destructor.
Definition SevenSegDispHw.cpp:820
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:498
SevenSegStatHC595()
Class default constructor.
Definition SevenSegDispHw.cpp:485
virtual ~SevenSegStatHC595()
Class destructor.
Definition SevenSegDispHw.cpp:496
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:505
SevenSegTM1636()
Default constructor.
Definition SevenSegDispHw.cpp:756
virtual ~SevenSegTM1636()
Default destructor.
Definition SevenSegDispHw.cpp:763
SevenSegTM1637()
Default constructor.
Definition SevenSegDispHw.cpp:772
~SevenSegTM1637()
Default destructor.
Definition SevenSegDispHw.cpp:779
~SevenSegTM1639()
Default destructor.
Definition SevenSegDispHw.cpp:795
SevenSegTM1639()
Default constructor.
Definition SevenSegDispHw.cpp:788
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:672
bool begin(uint32_t updtLps=0)
Turns On the display to be ready to receive data.
Definition SevenSegDispHw.cpp:547
~SevenSegTM163X()
Class destructor.
Definition SevenSegDispHw.cpp:542
virtual uint8_t getBrghtnssLvl()
Returns the current brightness level setting for the display module.
Definition SevenSegDispHw.cpp:563
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the Brightness level of the display.
Definition SevenSegDispHw.cpp:649
SevenSegTM163X()
Default class constructor.
Definition SevenSegDispHw.cpp:527
bool end()
Turns Off the display.
Definition SevenSegDispHw.cpp:557
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to or less than display module component digits ports,...
Definition SevenSegDispHw.h:601
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:663
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:568