diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index f9557ef..48ee1fe 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -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() diff --git a/DCC.h b/DCC.h index 4e1053c..0ba7a5f 100644 --- a/DCC.h +++ b/DCC.h @@ -165,5 +165,16 @@ private: #define MOTOR_BOARD_TYPE "FireBox1S" #endif +#ifdef ENABLE_LCD +#include + #if defined(LIB_TYPE_PCF8574) + #include + extern LiquidCrystal_PCF8574 lcdDisplay; + #elif defined(LIB_TYPE_I2C) + #include + extern LiquidCrystal_I2C lcdDisplay; + #endif +extern bool lcdEnabled; +#endif #endif diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 69e3dc1..f7ba4ef 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -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 diff --git a/platformio.ini b/platformio.ini index 58fd2a1..0c91321 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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