1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

Add support for 2 or 4 line LCD Display

This commit is contained in:
FrightRisk 2020-09-23 21:54:01 -04:00
parent 3df0ae16df
commit 3d94d8347a
4 changed files with 57 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#include "DCC.h"
#include "DIAG.h"
#include "DCCEXParser.h"
#include "version.h"
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#include "WifiInterface.h"
#endif
@ -24,6 +25,18 @@
int ramLowWatermark = 32767; // This figure gets overwritten dynamically in loop()
#endif
////////////////////////////////////////////////////////////////
//
// Enables an I2C 2x24 or 4x24 LCD Screen
#ifdef ENABLE_LCD
bool lcdEnabled = false;
#if defined(LIB_TYPE_PCF8574)
LiquidCrystal_PCF8574 lcdDisplay(LCD_ADDRESS);
#elif defined(LIB_TYPE_I2C)
LiquidCrystal_I2C lcdDisplay = LiquidCrystal_I2C(LCD_ADDRESS, LCD_COLUMNS, LCD_LINES);
#endif
#endif
// this code is here to demonstrate use of the DCC API and other techniques
// myFilter is an example of an OPTIONAL command filter used to intercept < > commands from
@ -92,6 +105,35 @@ DCCEXParser serialParser;
void setup()
{
////////////////////////////////////////////
//
// More display stuff. Need to put this in a .h file and make
// it a class
#ifdef ENABLE_LCD
Wire.begin();
// Check that we can find the LCD by its address before attempting to use it.
Wire.beginTransmission(LCD_ADDRESS);
if(Wire.endTransmission() == 0) {
lcdEnabled = true;
lcdDisplay.begin(LCD_COLUMNS, LCD_LINES);
lcdDisplay.setBacklight(255);
lcdDisplay.clear();
lcdDisplay.setCursor(0, 0);
lcdDisplay.print("DCC++ EX v");
lcdDisplay.print(VERSION);
lcdDisplay.setCursor(0, 1);
#if COMM_INTERFACE >= 1
lcdDisplay.print("IP: PENDING");
#else
lcdDisplay.print("SERIAL: READY");
#endif
#if LCD_LINES > 2
lcdDisplay.setCursor(0, 3);
lcdDisplay.print("TRACK POWER: OFF");
#endif
}
#endif
// The main sketch has responsibilities during setup()
// Responsibility 1: Start the usb connection for diagnostics
@ -146,7 +188,7 @@ void setup()
// Optionally a Timer number (1..4) may be passed to DCC::begin to override the default Timer1 used for the
// waveform generation. e.g. DCC::begin(STANDARD_MOTOR_SHIELD,2); to use timer 2
DCC::begin(MOTOR_SHIELD_TYPE);
DCC::begin(MOTOR_BOARD);
}
void loop()

11
DCC.h
View File

@ -165,5 +165,16 @@ private:
#define MOTOR_BOARD_TYPE "FireBox1S"
#endif
#ifdef ENABLE_LCD
#include <Wire.h>
#if defined(LIB_TYPE_PCF8574)
#include <LiquidCrystal_PCF8574.h>
extern LiquidCrystal_PCF8574 lcdDisplay;
#elif defined(LIB_TYPE_I2C)
#include <LiquidCrystal_I2C.h>
extern LiquidCrystal_I2C lcdDisplay;
#endif
extern bool lcdEnabled;
#endif
#endif

View File

@ -26,11 +26,11 @@
#include "Sensors.h"
#include "freeMemory.h"
#include "GITHUB_SHA.h"
#include "version.h"
#include "EEStore.h"
#include "DIAG.h"
const char VERSION[] PROGMEM ="0.2.0";
// These keywords are used in the <1> command. The number is what you get if you use the keyword as a parameter.
// To discover new keyword numbers , use the <$ YOURKEYWORD> command

View File

@ -32,6 +32,7 @@ framework = arduino
lib_deps =
${env.lib_deps}
DIO2
mathertel/LiquidCrystal_PCF8574 @ ^1.2.0
[env:mega328]
platform = atmelavr
@ -56,3 +57,4 @@ framework = arduino
lib_deps =
${env.lib_deps}
DIO2
mathertel/LiquidCrystal_PCF8574 @ ^1.2.0