Seven Segments Displays Agnostic Library for ESP32 (Arduino) v3.1.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
40#ifndef sevenSegDispHw_ESP32_H
41#define sevenSegDispHw_ESP32_H
42
43#include "Arduino.h"
44#include <stdint.h>
45#include <Wire.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
72 uint8_t _allLedsOff{};
73 uint8_t _brghtnssLvl{0};
74 uint8_t _brghtnssLvlMax{0};
75 uint8_t _brghtnssLvlMin{0};
76 uint8_t* _dspBlankBuffPtr{nullptr};
77 uint8_t* _dspBuffPtr{nullptr};
78 uint8_t* _dspBuffPtrBkp{nullptr};
79 SevenSegDispHw* _dspHwInstance{nullptr};
80 uint8_t _dspHwInstNbr{0};
81 bool _isOn{false};
82
83 virtual void _send(uint8_t* digitsBuffer);
84 virtual void _send(const uint8_t &segments, const uint8_t &port);
85
86 virtual void _sendDataUnit(void* dataUnit); //FFDR unify send methods using void*
87 virtual void _sendMssg(void* dataMssg); //FFDR unify send methods using void*
88
89public:
105 SevenSegDispHw(uint8_t* ioPins, uint8_t dspDigits = 4, bool commAnode = true);
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();
210 virtual void ntfyUpdDsply();
221 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
241 bool setDigitsOrder(uint8_t* newOrderPtr);
255 void setDspBuffPtr(uint8_t* newDspBuffPtr);
265 virtual void turnOff();
271 virtual void turnOn();
281 virtual void turnOn(const uint8_t &newBrghtnssLvl);
282};
283
284//============================================================> Class declarations separator
285
292 static void tmrCbRfrshDyn(TimerHandle_t rfrshTmrCbArg);
293
294private:
295 virtual void _unAbstract() = 0; // Makes this an Abstract class.
296
297protected:
298 TimerHandle_t _dynDspRfrshTmrHndl{NULL};
299 uint8_t _firstRefreshed{0};
300 String _rfrshTmrName{""};
301
302 void _refresh();
303 virtual void _send(uint8_t content);
304 virtual void _send(const uint8_t &segments, const uint8_t &port);
305
306public:
308 SevenSegDynamic(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
309 virtual ~SevenSegDynamic();
321 virtual bool begin(uint32_t updtLps=0);
328 virtual bool end();
329};
330
331//============================================================> Class declarations separator
332
342 static void tmrCbRfrshDynHC595(TimerHandle_t rfrshTmrCbArg);
343
344private:
345 const uint8_t _sclkIndx {0};
346 const uint8_t _rclkIndx {1};
347 const uint8_t _dioIndx {2};
348
349 ShiftRegGPIOXpander* _drvrShftRegPtr{nullptr};
350 uint8_t* _drvrShftRegSndPtr{nullptr};
351 uint8_t _sclk {};
352 uint8_t _rclk {};
353 uint8_t _dio {};
354
355 virtual void _unAbstract();
356
357protected:
358 TimerHandle_t _dynHC595DspRfrshTmrHndl{NULL};
359
360 void _refresh();
361 virtual void send(uint8_t content){};
362 virtual void send(const uint8_t &segments, const uint8_t &port){};
363
364public:
372 SevenSegDynHC595(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
377 virtual ~SevenSegDynHC595();
393 virtual bool begin(uint32_t updtLps = 0);
409 bool end();
410};
411
412//============================================================> Class declarations separator
413
427 static void tmrCbRfrshDynDummy(TimerHandle_t rfrshTmrCbArg);
428
429private:
430 virtual void _unAbstract();
431
432protected:
433 // static TimerHandle_t _dynDummyDspRfrshTmrHndl;
434 TimerHandle_t _dynDummyDspRfrshTmrHndl{NULL};
435
436 void _refresh();
437 virtual void send(const uint8_t &segments, const uint8_t &port);
438
439public:
446 SevenSegDynDummy(uint8_t dspDigits = 4, bool commAnode = true);
450 virtual ~SevenSegDynDummy();
465 bool begin(uint32_t updtLps = 0);
471 bool end();
472
473 virtual void turnOff();
474
475 virtual void turnOn();
476
477};
478
479//============================================================> Class declarations separator
480
500private:
501 virtual void _unAbstract() = 0; // Makes this an Abstract class.
502
503protected:
504
505public:
507 SevenSegStatic(uint8_t* ioPins, uint8_t dspDigits = 4, bool commAnode = true);
508 virtual ~SevenSegStatic();
509};
510
511//============================================================> Class declarations separator
512
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();
557 virtual void ntfyUpdDsply();
558};
559
560//============================================================> Class declarations separator
561
586private:
587 const uint8_t _clkIndx {0};
588 const uint8_t _dioIndx {1};
589 const uint8_t _dspDigitsQtyMax{};
590 const uint8_t _hwBrghtnssLvlMax{0x07};
591 const uint8_t _hwBrghtnssLvlMin{0x00};
592 uint32_t _txClkTckTm{2};
593 uint8_t _clk {};
594 uint8_t _dio {};
595
596 virtual void _unAbstract() = 0; // Makes this an Abstract class. For the subclasses to be instantiable they'll have to implement the _unAbstract() method.
597 void _updDsplyCntnt();
598
599protected:
600 uint8_t* _lclDspBuffPtr{nullptr};
601 uint8_t* _xcdDspBuffPtr{nullptr};
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
612 public:
625 SevenSegTM163X(uint8_t* ioPins, uint8_t dspDigits, bool commAnode, uint8_t dspContMaxDigits);
639 bool begin(uint32_t updtLps = 0);
645 bool end();
655 virtual uint8_t getBrghtnssLvl();
659 virtual void ntfyUpdDsply();
668 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
674 virtual void turnOff();
680 virtual void turnOn();
688 virtual void turnOn(const uint8_t &newBrghtnssLvl);
689};
690
691//============================================================> Class declarations separator
692
702private:
703 const uint8_t _dspDigitsQtyMax{4}; // Maximum display size in digits
704 virtual void _unAbstract();
705
706public:
718 SevenSegTM1636(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
722 virtual ~SevenSegTM1636();
723};
724
725//============================================================> Class declarations separator
726
736private:
737 const uint8_t _dspDigitsQtyMax{6}; // Maximum display size in digits
738 virtual void _unAbstract();
739
740public:
752 SevenSegTM1637(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
757};
758
759//============================================================> Class declarations separator
760
770private:
771 const uint8_t _dspDigitsQtyMax{8}; // Maximum display size in digits
772 virtual void _unAbstract();
773
774public:
786 SevenSegTM1639(uint8_t* ioPins, uint8_t dspDigits, bool commAnode);
791};
792
793//============================================================> Class declarations separator
794
832 // Address Map Constants
833 const uint8_t _NoOpAddr{0x00};
834 const uint8_t _DspPortsBaseAddr{0x01};
835 const uint8_t _DecodeModeAddr{0x09};
836 const uint8_t _BrghtnsSettAddr{0x0A};
837 const uint8_t _ScanLimitAddr{0x0B};
838 const uint8_t _ShutDownAddr{0x0C};
839 const uint8_t _DspTestAddr{0x0F};
840
841 // Valid parameters constants
842 const uint8_t _DisplayTestMode{0x01};
843 const uint8_t _NoDecode{0x00};
844 const uint8_t _NormalOp{0x00};
845 const uint8_t _TurnOff{0x00};
846 const uint8_t _TurnOn{0x01};
847
848private:
849 const uint8_t _clkIndx {0};
850 const uint8_t _dinIndx {1};
851 const uint8_t _csIndx {2};
852
853 const uint8_t _dspDigitsQtyMax{8};
854 const uint8_t _hwBrghtnssLvlMax{0x0F};
855 const uint8_t _hwBrghtnssLvlMin{0x00};
856
857 uint8_t _clk {}; // Serial clock max. rate 10 MHz. Data is shifted into the chip on **clk rising edge**
858 uint8_t _din {}; // Data value to get into the chip reg, must be set before the clk rising edge to be accepted.
859 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.
860
861 uint8_t _cnvrtStdDgtTo72xxDgt(const uint8_t &StdDgt);
862 virtual void _unAbstract();
863 void _updLclBffrCntnt();
864
865protected:
866 uint8_t* _lclDspBuffPtr{nullptr};
867
868 virtual void _sendByte(const uint8_t &val, const bool &MSbFrst = true);
869 virtual void send(const uint8_t &address, const uint8_t &data, const bool &MSbFrst = true);
870 virtual void _sendBffr();
871
872public:
885 SevenSegMax7219(uint8_t* ioPins, uint8_t dspDigits);
901 bool begin(uint32_t updtLps = 0);
909 bool end();
916 virtual bool getIsOn();
920 virtual void ntfyUpdDsply();
926 virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl);
934 virtual void turnOff();
940 virtual void turnOn();
948 virtual void turnOn(const uint8_t &newBrghtnssLvl);
949};
950
951//============================================================> Class declarations separator
952
953#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:110
virtual void turnOff()
Turns the display module off.
Definition sevenSegDispHw.cpp:162
virtual uint8_t getBrghtnssLvl()
Returns the current display brightness level setting for the display.
Definition sevenSegDispHw.cpp:75
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, turning the display off and fre...
Definition sevenSegDispHw.cpp:64
virtual ~SevenSegDispHw()
Class destructor.
Definition sevenSegDispHw.cpp:50
uint8_t * getDspBuffPtr()
Returns a pointer to the display buffer.
Definition sevenSegDispHw.cpp:95
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display.
Definition sevenSegDispHw.cpp:135
SevenSegDispHw()
Default class constructor.
Definition sevenSegDispHw.cpp:38
bool _isOn
Current display status: On/Off.
Definition sevenSegDispHw.h:81
uint8_t * _dspBlankBuffPtr
Pointer to a display buffer filled with _allLedsOff ("spaces") to use as display buffer while in "Off...
Definition sevenSegDispHw.h:76
bool getCommAnode()
Returns a value indicating if the display module component of the display hardware uses a common anod...
Definition sevenSegDispHw.cpp:90
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition sevenSegDispHw.cpp:58
uint8_t * _dspBuffPtrBkp
Pointer to the display buffer, copy of the original **_dspBuffPtr** to be used as backup.
Definition sevenSegDispHw.h:78
uint8_t _brghtnssLvl
Current display brightness level.
Definition sevenSegDispHw.h:73
virtual uint8_t getBrghtnssMaxLvl()
Returns the maximum display brightness level setting allowed for the display.
Definition sevenSegDispHw.cpp:80
virtual void turnOn()
Turns the display module on.
Definition sevenSegDispHw.cpp:176
uint8_t * _dspBuffPtr
Pointer to the display buffer, will be provided by the SevenSegDisplays object when it's instantiated...
Definition sevenSegDispHw.h:77
uint8_t _allLedsOff
Value to set in the display port to set all leds off (a "space"), dependent of _commAnode.
Definition sevenSegDispHw.h:72
virtual uint8_t getBrghtnssMinLvl()
Returns the minimum display brightness level setting for the display.
Definition sevenSegDispHw.cpp:85
virtual bool getIsOn()
Returns the state of the display.
Definition sevenSegDispHw.cpp:105
uint8_t _brghtnssLvlMin
Minimum display brightness level.
Definition sevenSegDispHw.h:75
uint8_t getHwDspDigitsQty()
Returns the quantity of digits of the display module.
Definition sevenSegDispHw.cpp:100
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:140
void setDspBuffPtr(uint8_t *newDspBuffPtr)
Sets the pointer to the Display Buffer memory area.
Definition sevenSegDispHw.cpp:155
uint8_t _brghtnssLvlMax
Maximum display brightness level.
Definition sevenSegDispHw.h:74
Models a dynamic display with no screen, for tests or remote display of the data.
Definition sevenSegDispHw.h:426
SevenSegDynDummy(uint8_t dspDigits=4, bool commAnode=true)
Class constructor, instantiates a SevenSegDynDummy object.
Definition sevenSegDispHw.cpp:347
bool end()
Stops the active display updating.
Definition sevenSegDispHw.cpp:399
virtual ~SevenSegDynDummy()
Class destructor
Definition sevenSegDispHw.cpp:352
bool begin(uint32_t updtLps=0)
Sets up the required resources for the "dummy hardware display" to work.
Definition sevenSegDispHw.cpp:364
virtual void turnOn()
Turns the display module on.
Definition sevenSegDispHw.cpp:466
virtual void turnOff()
Turns the display module off.
Definition sevenSegDispHw.cpp:459
Models seven segment displays driven by two 74HC595 shift registers.
Definition sevenSegDispHw.h:341
SevenSegDynHC595(uint8_t *ioPins, uint8_t dspDigits, bool commAnode)
Class constructor.
Definition sevenSegDispHw.cpp:243
virtual ~SevenSegDynHC595()
Class destructor.
Definition sevenSegDispHw.cpp:254
virtual bool begin(uint32_t updtLps=0)
Sets up the required resources for the hardware display to work.
Definition sevenSegDispHw.cpp:268
bool end()
Stops the active display updating.
Definition sevenSegDispHw.cpp:299
Abstract class models a generic dynamically updated Seven Segment display hardware
Definition sevenSegDispHw.h:291
virtual bool begin(uint32_t updtLps=0)
Sets up the hardware display to work.
Definition sevenSegDispHw.cpp:211
virtual bool end()
Reverts the begin(uint32_t) actions, stopping the display activities, stopping and deleting the timer...
Definition sevenSegDispHw.cpp:216
Models a Seven Segment display hardware using a Max7219 display controller component
Definition sevenSegDispHw.h:831
virtual void turnOff()
Turns the display module off.
Definition sevenSegDispHw.cpp:933
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the brightness level for the display module.
Definition sevenSegDispHw.cpp:919
virtual bool getIsOn()
Returns a value indicating if the display controller is in working/On or shutdown/Off mode.
Definition sevenSegDispHw.cpp:874
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition sevenSegDispHw.cpp:879
bool end()
Ends the active mode of the display by shutting it off.
Definition sevenSegDispHw.cpp:867
bool begin(uint32_t updtLps=0)
Sets up the hardware display to work, and starts the display activities.
Definition sevenSegDispHw.cpp:843
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to _dspDigitsQty, the local buffer differs from the shared _dspBuff...
Definition sevenSegDispHw.h:866
virtual void turnOn()
Turns the display module on.
Definition sevenSegDispHw.cpp:942
SevenSegMax7219()
Default class constructor.
Definition sevenSegDispHw.cpp:813
~SevenSegMax7219()
Class destructor.
Definition sevenSegDispHw.cpp:838
Models displays driven by 74HC595 or similar shift registers, one shift register per display port,...
Definition sevenSegDispHw.h:522
SevenSegStatHC595()
Class default constructor.
Definition sevenSegDispHw.cpp:488
virtual ~SevenSegStatHC595()
Class destructor.
Definition sevenSegDispHw.cpp:501
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition sevenSegDispHw.cpp:503
Abstract class that models displays that don't need permanent MCU data updating to keep the data corr...
Definition sevenSegDispHw.h:499
Models a Seven Segment display hardware controlled by a TM1636 display controller component.
Definition sevenSegDispHw.h:701
SevenSegTM1636()
Default constructor.
Definition sevenSegDispHw.cpp:765
virtual ~SevenSegTM1636()
Default destructor.
Definition sevenSegDispHw.cpp:772
Models a Seven Segment display hardware controlled by a TM1637 display controller component.
Definition sevenSegDispHw.h:735
SevenSegTM1637()
Default constructor.
Definition sevenSegDispHw.cpp:781
~SevenSegTM1637()
Default destructor.
Definition sevenSegDispHw.cpp:788
Models a Seven Segment display hardware controlled by a TM1639 display controller component.
Definition sevenSegDispHw.h:769
~SevenSegTM1639()
Default destructor.
Definition sevenSegDispHw.cpp:804
SevenSegTM1639()
Default constructor.
Definition sevenSegDispHw.cpp:797
Abstract class that models Seven Segments LEDs static displays hardware using Titan Micro TM163X seri...
Definition sevenSegDispHw.h:585
virtual void turnOn()
Turns the display module on.
Definition sevenSegDispHw.cpp:681
bool begin(uint32_t updtLps=0)
Turns On the display to be ready to receive data.
Definition sevenSegDispHw.cpp:560
~SevenSegTM163X()
Class destructor.
Definition sevenSegDispHw.cpp:553
virtual uint8_t getBrghtnssLvl()
Returns the current brightness level setting for the display module.
Definition sevenSegDispHw.cpp:572
virtual bool setBrghtnssLvl(const uint8_t &newBrghtnssLvl)
Sets the Brightness level of the display.
Definition sevenSegDispHw.cpp:658
uint8_t * _xcdDspBuffPtr
A pointer to a buffer the size of the exceeding digits used to control display specific amenities.
Definition sevenSegDispHw.h:601
SevenSegTM163X()
Default class constructor.
Definition sevenSegDispHw.cpp:525
bool end()
Turns Off the display.
Definition sevenSegDispHw.cpp:566
uint8_t _xcdDspDigitsQty
Number of unused available display ports, its the difference (_dspDigitsQtyMax - _dspDigitsQty),...
Definition sevenSegDispHw.h:602
uint8_t * _lclDspBuffPtr
Pointer to an array of size equal to or less than display module component digits ports,...
Definition sevenSegDispHw.h:600
virtual void turnOff()
Turns the display module off.
Definition sevenSegDispHw.cpp:672
virtual void ntfyUpdDsply()
See SevenSegDispHw::ntfyUpdDsply() for description.
Definition sevenSegDispHw.cpp:577