//libraries
//LCD display using I2C
#include <LiquidCrystal_I2C.h>
//LCD constants
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
//display constants / definitions
//general display status symbols
#define COMPONENT_OK "*"
#define COMPONENT_ERROR "!"
//LCD
//LCD static lines
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
//to add a new component
//add to ENUM
//update: intNumComponent, booComponentStates, intCurPosCol, intCurPosLine
//list of components
const int intNumComponents = 9;
//line and column numbers - note order defined by COMPONENT enumeration
const int intCurPosCol[intNumComponents] = {15,5,11,4,9,3,8,13,18}; //elements can have value up to 19
const int intCurPosLine[intNumComponents] = {0,1,1,2,2,3,3,3,3}; //elements can have value up to 3
//note the list below is important - defines cursor positions in intCurPos line and column
enum COMPONENT {
DASHCAM,
ESP8266_AP,
GPS,
DHT,
SD_CARD,
CAMERA1,
CAMERA2,
CAMERA3,
CAMERA4
};
COMPONENT comp;
//State variables
//TRUE - device ok
//FALSE - device error
bool booComponentStates[intNumComponents] = {false,true,true,true,true,true,true,true,true};
void setup() {
Serial.begin(9600);
initLCD();
}
void loop() {
printAllStates();
delay(1000);
changeStates();
}
void initLCD(){
// Init
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(0, 0);
lcd.print("DASHCAM STATUS:");
lcd.setCursor(0,1);
lcd.print("WiFi: GPS:");
lcd.setCursor(0,2);
lcd.print("DHT: SD:");
lcd.setCursor(0,3);
lcd.print("C1: C2: C3: C4:");
}
void printAllStates(){
for(int i = 0; i<intNumComponents; i++){
printState(i);
}
}
void printState(COMPONENT comp){
lcd.setCursor(getComponentStateColumn(comp),getComponentStateLine(comp));
lcd.print(getStatus(comp));
}
//return line number for cursor based on component
int getComponentStateLine(COMPONENT comp){
return intCurPosLine[comp];
}
//return column number for cursor based on component
int getComponentStateColumn(COMPONENT comp){
return intCurPosCol[comp];
}
//give string representation of whether component is working or not
String getStatus(COMPONENT comp){
return (getState(comp) ? COMPONENT_OK : COMPONENT_ERROR);
}
//function to return status of a component
//input: component from enumeration
//output: true for working, false when not working
bool getState(COMPONENT comp){
return booComponentStates[comp];
}
//function to set status of a component
//input: component from enumeration, component status
//output: nothing
void setState(COMPONENT comp, bool state){
booComponentStates[comp] = state;
}
//need separate function to obtain status of each component on regular basis
//this will need to call other libraries
void changeStates(){
for(int i = 0; i<intNumComponents; i++){
setState(i,!booComponentStates[i]);
//booComponentStates[i] = !booComponentStates[i];
}
}