Seven Segments Displays Agnostic Library for ESP32 (Arduino) v3.0.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
sevenSegDisplays.h
1#ifndef sevenSegDisplays_H
2#define sevenSegDisplays_H
3
4#include <Arduino.h>
5#include <SevenSegDispHw.h>
6
7const int MAX_DIGITS_PER_DISPLAY{8};
8const int MAX_DISPLAYS_QTY{10};
9
10class SevenSegDisplays {
11 static uint8_t _displaysCount;
12 static uint16_t _dspSerialNum;
13 static uint8_t _dspPtrArrLngth;
14 static SevenSegDisplays** _instancesLstPtr;
15
16 static TimerHandle_t _blinkTmrHndl;
17 static TimerHandle_t _waitTmrHndl;
18
19 static void tmrCbBlink(TimerHandle_t blinkTmrCbArg);
20 static void tmrCbWait(TimerHandle_t waitTmrCbArg);
21
22private:
23 uint8_t _waitChar {0xBF};
24 uint8_t _waitCount {0};
25 bool _waiting {false};
26 unsigned long _waitRate {250};
27 unsigned long _waitTimer {0};
28protected:
29 const unsigned long _minBlinkRate{100};
30 const unsigned long _maxBlinkRate{2000};
31
32 bool* _blinkMaskPtr{nullptr};
33 uint8_t* _dspAuxBuffPtr{nullptr};
34 bool _dspBuffChng{false};
35 uint8_t* _dspBuffPtr{nullptr};
36 uint8_t _dspDigitsQty{};
37 SevenSegDispHw _dspUndrlHw{};
38 SevenSegDisplays* _dspInstance;
39 uint16_t _dspInstNbr{0};
40 int32_t _dspValMax{};
41 int32_t _dspValMin{};
42
43 bool _blinking{false};
44 bool _blinkShowOn{false};
45 unsigned long _blinkTimer{0};
46 unsigned long _blinkOffRate{500};
47 unsigned long _blinkOnRate{500};
48 unsigned long _blinkRatesGCD{500}; //Holds the value for the minimum timer checking the change ON/OFF of the blinking,
49 //saving unneeded timer interruptions, and without the need of the std::gcd function
50 String _charSet{"0123456789AabCcdEeFGHhIiJLlnOoPqrStUuY-_=~* ."}; // for using indexOf() method
51 uint8_t _charLeds[45] = { //Values valid for a Common Anode display. For a Common Cathode display values must be logically bit negated
52 0xC0, // 0
53 0xF9, // 1
54 0xA4, // 2
55 0xB0, // 3
56 0x99, // 4
57 0x92, // 5
58 0x82, // 6
59 0xF8, // 7
60 0x80, // 8
61 0x90, // 9
62 0x88, // A
63 0xA0, // a
64 0x83, // b
65 0xC6, // C
66 0xA7, // c
67 0xA1, // d
68 0x86, // E
69 0x84, // e
70 0x8E, // F
71 0xC2, // G
72 0x89, // H
73 0x8B, // h
74 0xF9, // I
75 0xFB, // i
76 0xF1, // J
77 0xC7, // L
78 0xCF, // l
79 0xAB, // n
80 0xC0, // O
81 0xA3, // o
82 0x8C, // P
83 0x98, // q
84 0xAF, // r
85 0x92, // S
86 0x87, // t
87 0xC1, // U
88 0xE3, // u
89 0x91, // Y
90 0xBF, // Minus -
91 0xF7, // Underscore _
92 0xB7, // Low =
93 0xB6, //~ for Equivalent symbol
94 0x9C, // °
95 0xFF, // Space
96 0x7F //.
97 };
98
99 uint8_t _space {0xFF};
100 uint8_t _dot {0x7F};
101 String _zeroPadding{""};
102 String _spacePadding{""};
103
104 unsigned long blinkTmrGCD(unsigned long blnkOnTm, unsigned long blnkOffTm);
105 void restoreDspBuff();
106 void saveDspBuff();
107 void setAttrbts();
108 void updBlinkState();
109 void updWaitState();
110public:
111 SevenSegDisplays();
112 SevenSegDisplays(SevenSegDispHw dspUndrlHw);
113 ~SevenSegDisplays();
114 bool blink();
115 bool blink(const unsigned long &onRate, const unsigned long &offRate = 0);
116 void clear();
117 bool doubleGauge(const int &levelLeft, const int &levelRight, char labelLeft = ' ', char labelRight = ' ');
118 bool gauge(const int &level, char label = ' ');
119 bool gauge(const double &level, char label = ' ');
120 uint8_t getDigitsQty();
121 uint32_t getDspValMax();
122 uint32_t getDspValMin();
123 uint16_t getInstanceNbr();
124 unsigned long getMaxBlinkRate();
125 unsigned long getMinBlinkRate();
126 bool isBlank();
127 bool isBlinking();
128 bool isWaiting();
129 bool noBlink();
130 bool noWait();
131 bool print(String text);
132 bool print(const int32_t &value, bool rgtAlgn = false, bool zeroPad = false);
133 bool print(const double &value, const unsigned int &decPlaces, bool rgtAlgn = false, bool zeroPad = false);
134 void resetBlinkMask();
135 void setBlinkMask(const bool* newBlnkMsk);
136 bool setBlinkRate(const unsigned long &newOnRate, const unsigned long &newOffRate = 0);
137 bool setWaitChar (const char &newChar);
138 bool setWaitRate(const unsigned long &newWaitRate);
139 bool wait();
140 bool wait(const unsigned long &newWaitRate);
141 bool write(const uint8_t &segments, const uint8_t &port);
142 bool write(const String &character, const uint8_t &port);
143};
144
145//============================================================> Class declarations separator
146
147class ClickCounter{
148private:
149 SevenSegDisplays _display;
150 int _count{0};
151 int _beginStartVal{0};
152 bool _countRgthAlgn{true};
153 bool _countZeroPad{false};
154public:
155 ClickCounter(uint8_t ccSclk, uint8_t ccRclk, uint8_t ccDio, bool rgthAlgn = true, bool zeroPad = false, bool commAnode = true, const uint8_t dspDigits = 4);
156 ~ClickCounter();
157 bool blink();
158 bool blink(const unsigned long &onRate, const unsigned long &offRate = 0);
159 void clear();
160 bool countBegin(int32_t startVal = 0); //To be analyzed it's current need
161 bool countDown(int32_t qty = 1);
162 bool countReset();
163 bool countRestart(int32_t restartValue = 0);
164 bool countStop(); //To be analyzed it's current need
165 bool countToZero(int32_t qty = 1);
166 bool countUp(int32_t qty = 1);
167 int32_t getCount();
168 int32_t getStartVal();
169 bool noBlink();
170 bool setBlinkRate(const unsigned long &newOnRate, const unsigned long &newOffRate = 0);
171 bool updDisplay(); //To be analyzed it's current need
172};
173
174#endif