8 #if defined(ARDUINO) & ! defined(ARDUINO_AVR_MICRO) & ! defined(ARDUINO_AVR_NANO) 17 LiquidCrystal_I2C *LedLcdManager::lcd;
19 milliseconds_t LedLcdManager::blinkTime = defaultBlinkTime;
20 unsigned long LedLcdManager::turnOffTime;
21 unsigned int LedLcdManager::lcdRows = 0;
22 unsigned int LedLcdManager::lcdColumns = 0;
24 pin_t LedLcdManager::physicalLeds[maxLeds];
25 led_t LedLcdManager::logicalLeds[maxLeds];
26 bool LedLcdManager::shouldTimeOut[maxLeds];
29 const pin_t physicalLeds_[],
const led_t logicalLeds_[],
const bool shouldTimeOut_[]) {
30 setupLcdI2c(i2cAddress, columns, rows);
31 setupPhysicalLeds(physicalLeds_);
33 setupShouldTimeOut(shouldTimeOut_);
38 pin_t pin = physicalLeds[physicalLed-1];
39 if (pin == invalidPin)
43 digitalWrite(pin, state ==
off ? LOW : HIGH);
45 std::cout <<
"setPhysicalLed: pin = " << (int) pin <<
", " << (state ==
off ?
"off" :
"on") << std::endl;
54 : strcmp(value,
"on") == 0 ?
on 55 : strcmp(value,
"off") == 0 ?
off 56 : strcmp(value,
"blink") == 0 ?
blink 67 led_t physicalLed = logicalLeds[logicLed - 1];
78 logicalLeds[logicLed-1] = physicalLed;
83 for (
int i = 0; i <
maxLeds; i++)
84 logicalLeds[i] = logicalLeds_ == NULL ? i+1 : logicalLeds_[i];
88 void LedLcdManager::setupPhysicalLeds(
const pin_t physicalLeds_[maxLeds]) {
89 for (
int i = 0; i <
maxLeds; i++) {
90 physicalLeds[i] = physicalLeds_ == NULL ? invalidPin : physicalLeds_[i];
91 if (physicalLeds[i] != invalidPin)
92 pinMode(physicalLeds[i], OUTPUT);
96 void LedLcdManager::setupShouldTimeOut(
const bool shouldTimeOut_[maxLeds]) {
97 for (
int i = 0; i <
maxLeds; i++)
98 shouldTimeOut[i] = shouldTimeOut_ == NULL ?
true : shouldTimeOut_[i];
103 shouldTimeOut[logicLed-1] = state;
106 void LedLcdManager::setupLcdI2c(int8_t i2cAddress, uint8_t columns, uint8_t rows) {
108 lcd = i2cAddress >= 0 ?
new LiquidCrystal_I2C((uint8_t)i2cAddress, columns, rows) : NULL;
111 lcdColumns = columns;
122 turnOffTime = millis() + blinkTime;
152 if (millis() > turnOffTime)
164 if (force || shouldTimeOut[i - 1])
167 disableTurnOffTime();
170 void LedLcdManager::disableTurnOffTime() {
171 turnOffTime = (
unsigned long) -1;
179 int row = (y < 0 && clear) ? 0 : y;
180 int column = x < 0 ? 0 : x;
181 if (row > (
int) lcdRows - 1 || column > (int) lcdColumns - 1)
187 bool didPrint =
false;
190 String line = tokenizer.
getLine();
191 if (line.length() == 0)
193 if (line.length() > lcdColumns)
194 line = line.substring(0, lcdColumns);
195 if (clear || y >= 0) {
196 lcd->setCursor(column, row);
200 lcd->print(line.c_str());
static LedState onOffBlinkParse(const char *value)
static const int selftestTimeWithoutLCD
static bool setPhysicalLed(led_t physicalLed, LedState state)
static const int selftestTimeWithLCD
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 bool setLogicLed(led_t logicLed, LedState state)
static bool setupLogicLeds(const led_t array[maxLeds])
static const led_t invalidLed
static void setupShouldTimeout(led_t logicLed, bool state)
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)
static void checkTurnoff()
Turn off if it is due.