AGirs
LedLcdManager.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <InfraredTypes.h>
4 #include <IrSender.h>
5 #ifdef LCD
6 #include "LiquidCrystal_I2C_bm.h"
7 #endif
8 
9 typedef uint8_t led_t;
10 
12 public:
13  static constexpr int maxLeds = 8;
14  static constexpr int defaultLcdRows = 2;
15  static constexpr int defaultLcdColumns = 16;
16  static constexpr int invalidLine = -1;
17 
18  static constexpr int defaultBlinkTime = 2000;
19  static constexpr int selftestTimeWithoutLCD = 200;
20  static constexpr int selftestTimeWithLCD = 2000;
21 
22  enum LedState {
23  on,
24  off,
26  invalid
27  };
28 
29  static constexpr led_t invalidLed = 255U;
30 
31 private:
32  static unsigned int row;
33  static unsigned int column;
34 
36  static pin_t physicalLeds[maxLeds];
37 
39  static led_t logicalLeds[maxLeds];
40 
42  static bool shouldTimeOut[maxLeds];
43 
44  static milliseconds_t blinkTime;
45 
47  static unsigned long turnOffTime;
48 
49 #ifdef LCD
50  static LiquidCrystal_I2C *lcd;
51 #endif
52 
53  static unsigned int lcdRows;
54  static unsigned int lcdColumns;
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() = delete;
65 
66  static void disableTurnOffTime();
67 
68  static void groundPin(pin_t pin) {
69  pinMode(pin, OUTPUT);
70  digitalWrite(pin, LOW);
71  }
72 
73  static void prepare(bool clean, int x, int y);
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(const char *str, bool clear = true, int x = invalidLine, int y = invalidLine);
94  void static lcdPrint(String& string, bool clear = true, int x = invalidLine, int y = invalidLine) {
95  lcdPrint(string.c_str(), clear, x, y);
96  }
97 
98  void static lcdPrint(const __FlashStringHelper *pstr, bool clear = true, int x = 0, int y = invalidLine);
99 
100  static void lcdSetCursor(uint8_t x = 0, uint8_t y = 0) {
101 #ifdef LCD
102  lcd->setCursor(x, y);
103 #else
104  (void) x;
105  (void) y;
106 #endif
107  }
108 
109  static void allOff(bool force);
110 
111  static milliseconds_t getBlinkTime() {
112  return blinkTime;
113  };
114 
115  static void setBlinkTime(milliseconds_t value) {
116  blinkTime = value;
117  }
118 
119  static void updateTurnOffTime();
120 
122  static void checkTurnoff();
123 
124  static void selfTest(const char *text);
125 
126  static void selfTest(const __FlashStringHelper *text);
127 
128  static bool setPhysicalLed(led_t physicalLed, LedState state);
129 
130  static bool setLogicLed(led_t logicLed, LedState state);
131 
132  static bool setLogicLed(led_t logicLed, const char *state) {
133  return setLogicLed(logicLed, onOffBlinkParse(state));
134  };
135 
136  static LedState onOffBlinkParse(const char *value);
137 
138  static void setupShouldTimeout(led_t logicLed, bool state);
139 
140  static bool setupLogicLed(led_t loginLed, led_t physicalLed);
141 
142  static bool setupLogicLeds(const led_t array[maxLeds]);
143 
144  static void setupLedGroundPins() {
145 #ifdef SIGNAL_LED_1_GND
146  groundPin(SIGNAL_LED_1_GND);
147 #endif
148 #ifdef SIGNAL_LED_2_GND
149  groundPin(SIGNAL_LED_2_GND);
150 #endif
151 #ifdef SIGNAL_LED_3_GND
152  groundPin(SIGNAL_LED_3_GND);
153 #endif
154 #ifdef SIGNAL_LED_4_GND
155  groundPin(SIGNAL_LED_4_GND);
156 #endif
157 #ifdef SIGNAL_LED_5_GND
158  groundPin(SIGNAL_LED_5_GND);
159 #endif
160 #ifdef SIGNAL_LED_6_GND
161  groundPin(SIGNAL_LED_6_GND);
162 #endif
163 #ifdef SIGNAL_LED_7_GND
164  groundPin(SIGNAL_LED_7_GND);
165 #endif
166 #ifdef SIGNAL_LED_8_GND
167  groundPin(SIGNAL_LED_8_GND);
168 #endif
169 
170  }
171 };
uint8_t led_t
Definition: LedLcdManager.h:9
Functions for deploying I2C LCD displays.
#define str(s)
static constexpr int defaultBlinkTime
Definition: LedLcdManager.h:18
static void setBlinkTime(milliseconds_t value)
static void lcdPrint(const char *str, bool clear=true, int x=invalidLine, int y=invalidLine)
static void lcdPrint(const __FlashStringHelper *pstr, bool clear=true, int x=0, int y=invalidLine)
static constexpr int maxLeds
Definition: LedLcdManager.h:13
static constexpr int defaultLcdColumns
Definition: LedLcdManager.h:15
static void setupShouldTimeout(led_t logicLed, bool state)
static milliseconds_t getBlinkTime()
static constexpr int selftestTimeWithLCD
Definition: LedLcdManager.h:20
static void allOff(bool force)
static void lcdPrint(String &string, bool clear=true, int x=invalidLine, int y=invalidLine)
Definition: LedLcdManager.h:94
static void setupLedGroundPins()
static constexpr led_t invalidLed
Definition: LedLcdManager.h:29
static bool setLogicLed(led_t logicLed, LedState state)
static bool setLogicLed(led_t logicLed, const char *state)
static LedState onOffBlinkParse(const char *value)
static constexpr int selftestTimeWithoutLCD
Definition: LedLcdManager.h:19
static bool setupLogicLed(led_t loginLed, led_t physicalLed)
void setupPhysicalLeds(pin_t led1=invalidPin, pin_t led2=invalidPin, pin_t led3=invalidPin, pin_t led4=invalidPin, pin_t led5=invalidPin, pin_t led6=invalidPin, pin_t led7=invalidPin, pin_t led8=invalidPin)
static void lcdSetCursor(uint8_t x=0, uint8_t y=0)
static void setup(int8_t i2cAddress, 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 bool setupLogicLeds(const led_t array[maxLeds])
static constexpr int invalidLine
Definition: LedLcdManager.h:16
static void selfTest(const char *text)
static bool setPhysicalLed(led_t physicalLed, LedState state)
static void setup(int8_t i2cAddress, uint8_t columns, uint8_t rows, pin_t pled1, pin_t pled2=invalidLed, pin_t pled3=invalidPin, pin_t pled4=invalidPin, pin_t pled5=invalidPin, pin_t pled6=invalidPin, pin_t pled7=invalidPin, pin_t pled8=invalidPin)
static void updateTurnOffTime()
static void checkTurnoff()
Turn off if it is due.
static constexpr int defaultLcdRows
Definition: LedLcdManager.h:14
void setCursor(uint8_t, uint8_t)
#define SIGNAL_LED_7_GND
#define SIGNAL_LED_8_GND
#define SIGNAL_LED_5_GND
#define SIGNAL_LED_6_GND
#define SIGNAL_LED_3_GND
#define SIGNAL_LED_4_GND
#define SIGNAL_LED_2_GND