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
61 class SevenSegDispHw{
62 static uint8_t _dspHwSerialNum;
63 private:
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
66 protected:
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
86 public:
90 SevenSegDispHw();
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
296 class SevenSegDynamic: public SevenSegDispHw{
297 static void tmrCbRfrshDyn(TimerHandle_t rfrshTmrCbArg);
298
299 private:
300 virtual void _unAbstract() = 0; // Makes this an Abstract class.
301
302 protected:
303 TimerHandle_t _dynDspRfrshTmrHndl{NULL};
304 uint8_t _firstRefreshed{0};
305 String _rfrshTmrName{""};
306
307 void _refresh();
308
309 public:
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
344 class SevenSegDynHC595: public SevenSegDynamic{
345 static void tmrCbRfrshDynHC595(TimerHandle_t rfrshTmrCbArg);
346
347 private:
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
360 protected:
361 const uint8_t _dspDigitsQtyMax{8};
362 TimerHandle_t _dynHC595DspRfrshTmrHndl{NULL};
363
364 void _refresh();
365
366 public:
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
428 class SevenSegDynDummy: public SevenSegDynamic{
429 static void tmrCbRfrshDynDummy(TimerHandle_t rfrshTmrCbArg);
430
431 private:
432 virtual void _unAbstract();
433
434 protected:
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
441 public:
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
501 class SevenSegStatic: public SevenSegDispHw{
502 private:
503 virtual void _unAbstract() = 0; // Makes this an Abstract class.
504
505 public:
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
522 class SevenSegStatHC595: public SevenSegStatic{
523 private:
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:
541 SevenSegStatHC595();
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
587 class SevenSegTM163X: public SevenSegStatic{
588 private:
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
600 protected:
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:
615 SevenSegTM163X();
624 SevenSegTM163X(uint8_t* ioPins, uint8_t dspDigits, bool commAnode, uint8_t dspDigitsQtyMax = 0);
628 ~SevenSegTM163X();
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
700 class SevenSegTM1636: public SevenSegTM163X{
701 private:
702 virtual void _unAbstract();
703
704 protected:
705 const uint8_t _dspDigitsQtyMax{4}; // Maximum display controller managing digits capabilities
706
707 public:
711 SevenSegTM1636();
719 SevenSegTM1636(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
723 virtual ~SevenSegTM1636();
724};
725
726//============================================================> Class declarations separator
727
736 class SevenSegTM1637: public SevenSegTM163X{
737 private:
738 const uint8_t _dspDigitsQtyMax{6}; // Maximum display size in digits
739 virtual void _unAbstract();
740
741 public:
745 SevenSegTM1637();
753 SevenSegTM1637(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
757 ~SevenSegTM1637();
758};
759
760//============================================================> Class declarations separator
761
770 class SevenSegTM1639: public SevenSegTM163X{
771 private:
772 const uint8_t _dspDigitsQtyMax{8}; // Maximum display size in digits
773 virtual void _unAbstract();
774
775 public:
779 SevenSegTM1639();
787 SevenSegTM1639(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
791 ~SevenSegTM1639();
792};
793
794//============================================================> Class declarations separator
795
832 class 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
849 private:
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
866 protected:
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
873 public:
877 SevenSegMax7219();
886 SevenSegMax7219(uint8_t* ioPins, uint8_t dspDigits);
890 ~SevenSegMax7219();
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
SevenSegDispHw
Base abstract class models a generic Seven Segment display hardware.
Definition SevenSegDispHw.h:61
SevenSegDispHw::ntfyUpdDsply
virtual void ntfyUpdDsply()
Notifies the SevenSegDispHw component object of a change of content available in the display buffer,...
Definition SevenSegDispHw.cpp:126
SevenSegDispHw::turnOff
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:174
SevenSegDispHw::getBrghtnssLvl
virtual uint8_t getBrghtnssLvl()
Returns the current display brightness level setting for the display.
Definition SevenSegDispHw.cpp:86
SevenSegDispHw::end
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, turning the display off and fre...
Definition SevenSegDispHw.cpp:76
SevenSegDispHw::~SevenSegDispHw
virtual ~SevenSegDispHw()
Class destructor.
Definition SevenSegDispHw.cpp:60
SevenSegDispHw::getDspBuffPtr
uint8_t * getDspBuffPtr()
Returns a pointer to the display buffer.
Definition SevenSegDispHw.cpp:106
SevenSegDispHw::setBrghtnssLvl
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display.
Definition SevenSegDispHw.cpp:131
SevenSegDispHw::SevenSegDispHw
SevenSegDispHw()
Default class constructor.
Definition SevenSegDispHw.cpp:38
SevenSegDispHw::_isOn
bool _isOn
Current display status: On/Off.
Definition SevenSegDispHw.h:82
SevenSegDispHw::_dspBlankBuffPtr
uint8_t * _dspBlankBuffPtr
Pointer to a display buffer filled with _allLedsOff ("spaces") to use as display buffer while in "Off...
Definition SevenSegDispHw.h:77
SevenSegDispHw::getCommAnode
bool getCommAnode()
Returns a value indicating if the display module component of the display hardware uses a common anod...
Definition SevenSegDispHw.cpp:101
SevenSegDispHw::begin
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:70
SevenSegDispHw::_dspBuffPtrBkp
uint8_t * _dspBuffPtrBkp
Pointer to the display buffer, copy of the original **_dspBuffPtr** to be used as backup.
Definition SevenSegDispHw.h:79
SevenSegDispHw::_brghtnssLvl
uint8_t _brghtnssLvl
Current display brightness level.
Definition SevenSegDispHw.h:74
SevenSegDispHw::getBrghtnssMaxLvl
virtual uint8_t getBrghtnssMaxLvl()
Returns the maximum display brightness level setting allowed for the display.
Definition SevenSegDispHw.cpp:91
SevenSegDispHw::_xcdDspDigitsQty
uint8_t _xcdDspDigitsQty
Number of unused available display ports, its the difference (_dspDigitsQtyMax - _dspDigitsQty),...
Definition SevenSegDispHw.h:84
SevenSegDispHw::turnOn
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:188
SevenSegDispHw::_dspBuffPtr
uint8_t * _dspBuffPtr
Pointer to the display buffer, will be provided by the SevenSegDisplays object when it's instantiated...
Definition SevenSegDispHw.h:78
SevenSegDispHw::getxcdDspBuffPtr
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
SevenSegDispHw::_allLedsOff
uint8_t _allLedsOff
Value to set in the display port to set all leds off (a "space"), dependent of _commAnode.
Definition SevenSegDispHw.h:73
SevenSegDispHw::getBrghtnssMinLvl
virtual uint8_t getBrghtnssMinLvl()
Returns the minimum display brightness level setting for the display.
Definition SevenSegDispHw.cpp:96
SevenSegDispHw::getIsOn
virtual bool getIsOn()
Returns the state of the display.
Definition SevenSegDispHw.cpp:116
SevenSegDispHw::_brghtnssLvlMin
uint8_t _brghtnssLvlMin
Minimum display brightness level.
Definition SevenSegDispHw.h:76
SevenSegDispHw::getHwDspDigitsQty
uint8_t getHwDspDigitsQty()
Returns the quantity of digits of the display module.
Definition SevenSegDispHw.cpp:111
SevenSegDispHw::setDigitsOrder
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
SevenSegDispHw::_xcdDspBuffPtr
uint8_t * _xcdDspBuffPtr
A pointer to a buffer the size of the exceeding digits used to control display specific amenities.
Definition SevenSegDispHw.h:83
SevenSegDispHw::setDspBuffPtr
void setDspBuffPtr(uint8_t *newDspBuffPtr)
Sets the pointer to the Display Buffer memory area.
Definition SevenSegDispHw.cpp:167
SevenSegDispHw::_brghtnssLvlMax
uint8_t _brghtnssLvlMax
Maximum display brightness level.
Definition SevenSegDispHw.h:75
SevenSegDynDummy::SevenSegDynDummy
SevenSegDynDummy(uint8_t dspDigits=4, bool commAnode=true)
Class constructor, instantiates a SevenSegDynDummy object.
Definition SevenSegDispHw.cpp:344
SevenSegDynDummy::end
bool end()
Stops the active display updating.
Definition SevenSegDispHw.cpp:396
SevenSegDynDummy::~SevenSegDynDummy
virtual ~SevenSegDynDummy()
Class destructor.
Definition SevenSegDispHw.cpp:349
SevenSegDynDummy::begin
bool begin(uint32_t updtLps=0)
Sets up the required resources for the "dummy hardware display" to work.
Definition SevenSegDispHw.cpp:361
SevenSegDynDummy::turnOn
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:463
SevenSegDynDummy::turnOff
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:456
SevenSegDynHC595::SevenSegDynHC595
SevenSegDynHC595(uint8_t *ioPins, uint8_t dspDigits, bool commAnode)
Class constructor.
Definition SevenSegDispHw.cpp:245
SevenSegDynHC595::~SevenSegDynHC595
virtual ~SevenSegDynHC595()
Class destructor.
Definition SevenSegDispHw.cpp:253
SevenSegDynHC595::begin
virtual bool begin(uint32_t updtLps=0)
Sets up the required resources for the hardware display to work.
Definition SevenSegDispHw.cpp:267
SevenSegDynHC595::end
bool end()
Stops the active display updating.
Definition SevenSegDispHw.cpp:299
SevenSegDynamic::begin
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work.
Definition SevenSegDispHw.cpp:223
SevenSegDynamic::end
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, stopping and deleting the timer...
Definition SevenSegDispHw.cpp:228
SevenSegMax7219::turnOff
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:917
SevenSegMax7219::setBrghtnssLvl
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display module.
Definition SevenSegDispHw.cpp:903
SevenSegMax7219::getIsOn
virtual bool getIsOn()
Returns a value indicating if the display controller is in working/On or shutdown/Off mode.
Definition SevenSegDispHw.cpp:861
SevenSegMax7219::ntfyUpdDsply
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:866
SevenSegMax7219::end
bool end()
Ends the active mode of the display by shutting it off.
Definition SevenSegDispHw.cpp:854
SevenSegMax7219::begin
bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:825
SevenSegMax7219::_lclDspBuffPtr
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to _dspDigitsQty, the local buffer differs from the shared _dspBuff...
Definition SevenSegDispHw.h:867
SevenSegMax7219::turnOn
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:926
SevenSegMax7219::SevenSegMax7219
SevenSegMax7219()
Default class constructor.
Definition SevenSegDispHw.cpp:804
SevenSegMax7219::~SevenSegMax7219
~SevenSegMax7219()
Class destructor.
Definition SevenSegDispHw.cpp:820
SevenSegStatHC595::begin
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition SevenSegDispHw.cpp:498
SevenSegStatHC595::SevenSegStatHC595
SevenSegStatHC595()
Class default constructor.
Definition SevenSegDispHw.cpp:485
SevenSegStatHC595::~SevenSegStatHC595
virtual ~SevenSegStatHC595()
Class destructor.
Definition SevenSegDispHw.cpp:496
SevenSegStatHC595::ntfyUpdDsply
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:505
SevenSegTM1636::SevenSegTM1636
SevenSegTM1636()
Default constructor.
Definition SevenSegDispHw.cpp:756
SevenSegTM1636::~SevenSegTM1636
virtual ~SevenSegTM1636()
Default destructor.
Definition SevenSegDispHw.cpp:763
SevenSegTM1637::SevenSegTM1637
SevenSegTM1637()
Default constructor.
Definition SevenSegDispHw.cpp:772
SevenSegTM1637::~SevenSegTM1637
~SevenSegTM1637()
Default destructor.
Definition SevenSegDispHw.cpp:779
SevenSegTM1639::~SevenSegTM1639
~SevenSegTM1639()
Default destructor.
Definition SevenSegDispHw.cpp:795
SevenSegTM1639::SevenSegTM1639
SevenSegTM1639()
Default constructor.
Definition SevenSegDispHw.cpp:788
SevenSegTM163X::turnOn
virtual void turnOn()
Turns the display module on.
Definition SevenSegDispHw.cpp:672
SevenSegTM163X::begin
bool begin(uint32_t updtLps=0)
Turns On the display to be ready to receive data.
Definition SevenSegDispHw.cpp:547
SevenSegTM163X::~SevenSegTM163X
~SevenSegTM163X()
Class destructor.
Definition SevenSegDispHw.cpp:542
SevenSegTM163X::getBrghtnssLvl
virtual uint8_t getBrghtnssLvl()
Returns the current brightness level setting for the display module.
Definition SevenSegDispHw.cpp:563
SevenSegTM163X::setBrghtnssLvl
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the Brightness level of the display.
Definition SevenSegDispHw.cpp:649
SevenSegTM163X::SevenSegTM163X
SevenSegTM163X()
Default class constructor.
Definition SevenSegDispHw.cpp:527
SevenSegTM163X::end
bool end()
Turns Off the display.
Definition SevenSegDispHw.cpp:557
SevenSegTM163X::_lclDspBuffPtr
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to or less than display module component digits ports,...
Definition SevenSegDispHw.h:601
SevenSegTM163X::turnOff
virtual void turnOff()
Turns the display module off.
Definition SevenSegDispHw.cpp:663
SevenSegTM163X::ntfyUpdDsply
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition SevenSegDispHw.cpp:568