AGirs
LedLcdManager.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Tokenizer.h"
4 #include <InfraredTypes.h>
5 #include <IrSender.h>
6 #ifdef LCD
7 #include <LiquidCrystal_I2C.h> // https://github.com/marcoschwartz/LiquidCrystal_I2C
8 #endif
9 
10 typedef uint8_t led_t;
11 
13 public:
14  static const int maxLeds = 8;
15  static const int defaultLcdRows = 2;
16  static const int defaultLcdColumns = 16;
17 
18  static const int defaultBlinkTime = 2000;
19  static const int selftestTimeWithoutLCD = 200;
20  static const int selftestTimeWithLCD = 2000;
21 
22  enum LedState {
23  on,
24  off,
27  };
28 
29 
30  static const led_t invalidLed = 255;
31 
32 private:
34  static pin_t physicalLeds[maxLeds];
35 
37  static led_t logicalLeds[maxLeds];
38 
40  static bool shouldTimeOut[maxLeds];
41 
42  static milliseconds_t blinkTime;
43 
45  static unsigned long turnOffTime;
46 
47 #ifdef LCD
48  static LiquidCrystal_I2C *lcd;
49 #endif
50 
51  static unsigned int lcdRows;
52  static unsigned int lcdColumns;
53 
54  //static LedLcdManager instance;
55 
56  static void setupPhysicalLeds(const pin_t physicalLeds[maxLeds]);
57  static void setupShouldTimeOut(const bool shouldTimeOut[maxLeds]);
58  /*pin_t pled1, pin_t pled2 = invalidPin,
59  pin_t pled3 = invalidPin, pin_t pled4 = invalidPin,
60  pin_t pled5 = invalidPin, pin_t pled6 = invalidPin,
61  pin_t pled7 = invalidPin, pin_t pled8 = invalidPin);*/
62 
63  static void setupLcdI2c(int8_t i2cAddress, uint8_t columns, uint8_t rows);
64  LedLcdManager();
65 
66  //void initArray(char *array, uint8_t value);
67 
68  static void disableTurnOffTime();
69 
70  static void groundPin(pin_t pin) {
71  pinMode(pin, OUTPUT);
72  digitalWrite(pin, LOW);
73  }
74 
75 public:
77  static void setup(int8_t i2cAddress = -1, uint8_t columns = defaultLcdColumns, uint8_t rows = defaultLcdRows,
78  const pin_t physicalLeds[maxLeds] = NULL,
79  const led_t logicalLeds[maxLeds] = NULL,
80  const bool shouldTimeOut[maxLeds] = NULL);
81 
82  static void setup(int8_t i2cAddress, uint8_t columns, uint8_t rows,
83  pin_t pled1, pin_t pled2 = invalidLed,
84  pin_t pled3 = invalidPin, pin_t pled4 = invalidPin,
85  pin_t pled5 = invalidPin, pin_t pled6 = invalidPin,
86  pin_t pled7 = invalidPin, pin_t pled8 = invalidPin);
87 
88  void setupPhysicalLeds(pin_t led1 = invalidPin, pin_t led2 = invalidPin,
89  pin_t led3 = invalidPin, pin_t led4 = invalidPin,
90  pin_t led5 = invalidPin, pin_t led6 = invalidPin,
91  pin_t led7 = invalidPin, pin_t led8 = invalidPin);
92 
93  void static lcdPrint(String& string, bool clear = true, int x = 0, int y = -1);
94  void static lcdPrint(const char *str, bool clear = true, int x = 0, int y = -1) {
95  String string(str);
96  lcdPrint(string, clear, x, y);
97  };
98 #ifdef ARDUINO
99  void static lcdPrint(const __FlashStringHelper *pstr, bool clear = true, int x = 0, int y = -1) {
100  String string(pstr);
101  lcdPrint(string, clear, x, y);
102  }
103 #endif
104 
105  //void static lcdPrint(const String& str);
106 
107  //LedLcdManager& getInstance() {
108  // return instance;
109  //};
110 
111  //static LiquidCrystal_I2C& getLcd() {
112  // return *lcd;
113  //}
114 
115  static void lcdSetCursor(uint8_t x = 0, uint8_t y = 0) {
116 #ifdef LCD
117  lcd->setCursor(x, y);
118 #else
119  (void) x;
120  (void) y;
121 #endif
122  }
123 
124  static void allOff(bool force);
125 
126  static milliseconds_t getBlinkTime() {
127  return blinkTime;
128  };
129 
130  static void setBlinkTime(milliseconds_t value) {
131  blinkTime = value;
132  }
133 
134  static void updateTurnOffTime();
135 
137  static void checkTurnoff();
138 
139  static void selfTest(const char *text);
140 
141 #ifdef ARDUINO
142  static void selfTest(const __FlashStringHelper *text);
143 #endif
144 
145  static bool setPhysicalLed(led_t physicalLed, LedState state);
146 
147  static bool setLogicLed(led_t logicLed, LedState state);
148 
149  static bool setLogicLed(led_t logicLed, const char *state) {
150  return setLogicLed(logicLed, onOffBlinkParse(state));
151  };
152 
153  static LedState onOffBlinkParse(const char *value);
154 
155  static void setupShouldTimeout(led_t logicLed, bool state);
156 
157  static bool setupLogicLed(led_t loginLed, led_t physicalLed);
158 
159  static bool setupLogicLeds(const led_t array[maxLeds]);
160 
161  static void setupLedGroundPins() {
162 #ifdef SIGNAL_LED_1_GND
163  groundPin(SIGNAL_LED_1_GND);
164 #endif
165 #ifdef SIGNAL_LED_2_GND
166  groundPin(SIGNAL_LED_2_GND);
167 #endif
168 #ifdef SIGNAL_LED_3_GND
169  groundPin(SIGNAL_LED_3_GND);
170 #endif
171 #ifdef SIGNAL_LED_4_GND
172  groundPin(SIGNAL_LED_4_GND);
173 #endif
174 #ifdef SIGNAL_LED_5_GND
175  groundPin(SIGNAL_LED_5_GND);
176 #endif
177 #ifdef SIGNAL_LED_6_GND
178  groundPin(SIGNAL_LED_6_GND);
179 #endif
180 #ifdef SIGNAL_LED_7_GND
181  groundPin(SIGNAL_LED_7_GND);
182 #endif
183 #ifdef SIGNAL_LED_8_GND
184  groundPin(SIGNAL_LED_8_GND);
185 #endif
186 
187  }
188 };
#define SIGNAL_LED_8_GND
#define SIGNAL_LED_7_GND
#define SIGNAL_LED_3_GND
static LedState onOffBlinkParse(const char *value)
static const int maxLeds
Definition: LedLcdManager.h:14
#define SIGNAL_LED_5_GND
static const int selftestTimeWithoutLCD
Definition: LedLcdManager.h:19
static bool setPhysicalLed(led_t physicalLed, LedState state)
static const int selftestTimeWithLCD
Definition: LedLcdManager.h:20
static void setBlinkTime(milliseconds_t value)
#define SIGNAL_LED_6_GND
static bool setLogicLed(led_t logicLed, const char *state)
static void lcdSetCursor(uint8_t x=0, uint8_t y=0)
static void setup(int8_t i2cAddress=-1, uint8_t columns=defaultLcdColumns, uint8_t rows=defaultLcdRows, const pin_t physicalLeds[maxLeds]=NULL, const led_t logicalLeds[maxLeds]=NULL, const bool shouldTimeOut[maxLeds]=NULL)
Sets up the instance, to be called before using the instance.
static void lcdPrint(const __FlashStringHelper *pstr, bool clear=true, int x=0, int y=-1)
Definition: LedLcdManager.h:99
static bool setLogicLed(led_t logicLed, LedState state)
static void setupLedGroundPins()
static bool setupLogicLeds(const led_t array[maxLeds])
#define SIGNAL_LED_2_GND
uint8_t led_t
Definition: LedLcdManager.h:10
static const led_t invalidLed
Definition: LedLcdManager.h:30
static void lcdPrint(const char *str, bool clear=true, int x=0, int y=-1)
Definition: LedLcdManager.h:94
static void setupShouldTimeout(led_t logicLed, bool state)
static const int defaultLcdRows
Definition: LedLcdManager.h:15
static const int defaultLcdColumns
Definition: LedLcdManager.h:16
static void lcdPrint(String &string, bool clear=true, int x=0, int y=-1)
static void updateTurnOffTime()
static void allOff(bool force)
static void selfTest(const char *text)
static bool setupLogicLed(led_t loginLed, led_t physicalLed)
#define SIGNAL_LED_4_GND
static milliseconds_t getBlinkTime()
static void checkTurnoff()
Turn off if it is due.
static const int defaultBlinkTime
Definition: LedLcdManager.h:18