From 1807189183389ed64ed95c32e072974181a04d89 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 8 Nov 2021 02:07:21 +0100 Subject: [PATCH 01/15] make it possible to disable EEPROM code to save flash space --- DCC.cpp | 4 ++++ DCCEXParser.cpp | 11 +++++++++-- EEStore.cpp | 4 ++++ EEStore.h | 2 ++ Outputs.cpp | 8 ++++++-- Outputs.h | 2 ++ Sensors.cpp | 8 +++++--- Sensors.h | 2 ++ Turnouts.cpp | 32 +++++++++++++++++++++++++++++--- Turnouts.h | 3 ++- defines.h | 4 ++-- 11 files changed, 67 insertions(+), 13 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index f42ddf7..61ddbc8 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -20,7 +20,9 @@ #include "DIAG.h" #include "DCC.h" #include "DCCWaveform.h" +#ifndef DISABLE_EEPROM #include "EEStore.h" +#endif #include "GITHUB_SHA.h" #include "version.h" #include "FSH.h" @@ -56,9 +58,11 @@ void DCC::begin(const FSH * motorShieldName, MotorDriver * mainDriver, MotorDriv // Initialise HAL layer before reading EEprom. IODevice::begin(); +#ifndef DISABLE_EEPROM // Load stuff from EEprom (void)EEPROM; // tell compiler not to warn this is unused EEStore::init(); +#endif DCCWaveform::begin(mainDriver,progDriver); } diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index ed1f684..be95871 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -56,7 +56,9 @@ const int16_t HASH_KEYWORD_ON = 2657; const int16_t HASH_KEYWORD_DCC = 6436; const int16_t HASH_KEYWORD_SLOW = -17209; const int16_t HASH_KEYWORD_PROGBOOST = -6353; +#ifndef DISABLE_EEPROM const int16_t HASH_KEYWORD_EEPROM = -7168; +#endif const int16_t HASH_KEYWORD_LIMIT = 27413; const int16_t HASH_KEYWORD_MAX = 16244; const int16_t HASH_KEYWORD_MIN = 15978; @@ -278,7 +280,9 @@ void DCCEXParser::parse(const FSH * cmd) { void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) { +#ifndef DISABLE_EEPROM (void)EEPROM; // tell compiler not to warn this is unused +#endif if (Diag::CMD) DIAG(F("PARSING:%s"), com); int16_t p[MAX_COMMAND_PARAMS]; @@ -540,6 +544,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) // TODO Send stats of speed reminders table return; +#ifndef DISABLE_EEPROM case 'E': // STORE EPROM EEStore::store(); StringFormatter::send(stream, F("\n"), EEStore::eeStore->data.nTurnouts, EEStore::eeStore->data.nSensors, EEStore::eeStore->data.nOutputs); @@ -549,7 +554,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) EEStore::clear(); StringFormatter::send(stream, F("\n")); return; - +#endif case ' ': // < > StringFormatter::send(stream, F("\n")); return; @@ -864,11 +869,13 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[]) delay(50); // wait for the prescaller time to expire break; // and if we didnt restart } - + +#ifndef DISABLE_EEPROM case HASH_KEYWORD_EEPROM: // if (params >= 2) EEStore::dump(p[1]); return true; +#endif case HASH_KEYWORD_SPEED28: DCC::setGlobalSpeedsteps(28); diff --git a/EEStore.cpp b/EEStore.cpp index 3a13be7..15e2b2e 100644 --- a/EEStore.cpp +++ b/EEStore.cpp @@ -18,6 +18,9 @@ * You should have received a copy of the GNU General Public License * along with CommandStation. If not, see . */ + +#include "config.h" +#ifndef DISABLE_EEPROM #include "EEStore.h" #include "DIAG.h" @@ -103,3 +106,4 @@ void EEStore::dump(int num) { EEStore *EEStore::eeStore = NULL; int EEStore::eeAddress = 0; +#endif diff --git a/EEStore.h b/EEStore.h index 8fc98bd..22e12dd 100644 --- a/EEStore.h +++ b/EEStore.h @@ -17,6 +17,7 @@ * You should have received a copy of the GNU General Public License * along with CommandStation. If not, see . */ +#ifndef DISABLE_EEPROM #ifndef EEStore_h #define EEStore_h @@ -52,3 +53,4 @@ struct EEStore{ }; #endif +#endif // DISABLE_EEPROM diff --git a/Outputs.cpp b/Outputs.cpp index 7287446..3cc7a43 100644 --- a/Outputs.cpp +++ b/Outputs.cpp @@ -82,7 +82,9 @@ the state of any outputs being monitored or controlled by a separate interface o **********************************************************************/ #include "Outputs.h" +#ifndef DISABLE_EEPROM #include "EEStore.h" +#endif #include "StringFormatter.h" #include "IODevice.h" @@ -102,10 +104,11 @@ void Output::activate(uint16_t s){ data.active = s; // if s>0, set status to active, else inactive // set state of output pin to HIGH or LOW depending on whether bit zero of iFlag is set to 0 (ACTIVE=HIGH) or 1 (ACTIVE=LOW) IODevice::write(data.pin, s ^ data.invert); - +#ifndef DISABLE_EEPROM // Update EEPROM if output has been stored. if(EEStore::eeStore->data.nOutputs > 0 && num > 0) EEPROM.put(num, data.oStatus); +#endif } /////////////////////////////////////////////////////////////////////////////// @@ -141,7 +144,7 @@ bool Output::remove(uint16_t n){ /////////////////////////////////////////////////////////////////////////////// // Static function to load configuration and state of all Outputs from EEPROM - +#ifndef DISABLE_EEPROM void Output::load(){ struct OutputData data; Output *tt; @@ -176,6 +179,7 @@ void Output::store(){ } } +#endif /////////////////////////////////////////////////////////////////////////////// // Static function to create an Output object diff --git a/Outputs.h b/Outputs.h index 58be7e9..017bf7e 100644 --- a/Outputs.h +++ b/Outputs.h @@ -48,8 +48,10 @@ public: bool isActive(); static Output* get(uint16_t); static bool remove(uint16_t); +#ifndef DISABLE_EEPROM static void load(); static void store(); +#endif static Output *create(uint16_t, VPIN, int, int=0); static Output *firstOutput; struct OutputData data; diff --git a/Sensors.cpp b/Sensors.cpp index d6d3d81..5109722 100644 --- a/Sensors.cpp +++ b/Sensors.cpp @@ -68,7 +68,9 @@ decide to ignore the return and only react to triggers. #include "StringFormatter.h" #include "Sensors.h" +#ifndef DISABLE_EEPROM #include "EEStore.h" +#endif #include "IODevice.h" @@ -275,7 +277,7 @@ bool Sensor::remove(int n){ } /////////////////////////////////////////////////////////////////////////////// - +#ifndef DISABLE_EEPROM void Sensor::load(){ struct SensorData data; Sensor *tt; @@ -303,7 +305,7 @@ void Sensor::store(){ EEStore::eeStore->data.nSensors++; } } - +#endif /////////////////////////////////////////////////////////////////////////////// Sensor *Sensor::firstSensor=NULL; @@ -314,4 +316,4 @@ unsigned long Sensor::lastReadCycle=0; Sensor *Sensor::firstPollSensor = NULL; Sensor *Sensor::lastSensor = NULL; bool Sensor::inputChangeCallbackRegistered = false; -#endif \ No newline at end of file +#endif diff --git a/Sensors.h b/Sensors.h index 7547784..2c280a9 100644 --- a/Sensors.h +++ b/Sensors.h @@ -68,8 +68,10 @@ public: Sensor *nextSensor; void setState(int state); +#ifndef DISABLE_EEPROM static void load(); static void store(); +#endif static Sensor *create(int id, VPIN vpin, int pullUp); static Sensor* get(int id); static bool remove(int id); diff --git a/Turnouts.cpp b/Turnouts.cpp index dcbff73..92aadb9 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -22,7 +22,9 @@ #include "defines.h" // includes config.h +#ifndef DISABLE_EEPROM #include "EEStore.h" +#endif #include "StringFormatter.h" #include "RMFT2.h" #include "Turnouts.h" @@ -141,11 +143,13 @@ if (ok) { turnoutlistHash++; // let withrottle know something changed - + +#ifndef DISABLE_EEPROM // Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress // is always zero for LCN turnouts. if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress > 0) - EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags); + EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags); +#endif #if defined(RMFT_ACTIVE) RMFT2::turnoutEvent(id, closeFlag); @@ -159,6 +163,7 @@ return ok; } +#ifndef DISABLE_EEPROM // Load all turnout objects /* static */ void Turnout::load() { for (uint16_t i=0; idata.nTurnouts; i++) { @@ -212,7 +217,7 @@ #endif return tt; } - +#endif // Display, on the specified stream, the current state of the turnout (1=thrown or 0=closed). /* static */ void Turnout::printState(uint16_t id, Print *stream) { Turnout *tt = get(id); @@ -277,6 +282,7 @@ // Load a Servo turnout definition from EEPROM. The common Turnout data has already been read at this point. Turnout *ServoTurnout::load(struct TurnoutData *turnoutData) { +#ifndef DISABLE_EEPROM ServoTurnoutData servoTurnoutData; // Read class-specific data from EEPROM EEPROM.get(EEStore::pointer(), servoTurnoutData); @@ -286,6 +292,10 @@ Turnout *tt = ServoTurnout::create(turnoutData->id, servoTurnoutData.vpin, servoTurnoutData.thrownPosition, servoTurnoutData.closedPosition, servoTurnoutData.profile, turnoutData->closed); return tt; +#else + (void)turnoutData; + return NULL; +#endif } // For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed @@ -308,6 +318,7 @@ } void ServoTurnout::save() { +#ifndef DISABLE_EEPROM // Write turnout definition and current position to EEPROM // First write common servo data, then // write the servo-specific data @@ -315,6 +326,7 @@ EEStore::advance(sizeof(_turnoutData)); EEPROM.put(EEStore::pointer(), _servoTurnoutData); EEStore::advance(sizeof(_servoTurnoutData)); +#endif } /************************************************************************************* @@ -367,6 +379,7 @@ // Load a DCC turnout definition from EEPROM. The common Turnout data has already been read at this point. /* static */ Turnout *DCCTurnout::load(struct TurnoutData *turnoutData) { +#ifndef DISABLE_EEPROM DCCTurnoutData dccTurnoutData; // Read class-specific data from EEPROM EEPROM.get(EEStore::pointer(), dccTurnoutData); @@ -376,6 +389,10 @@ DCCTurnout *tt = new DCCTurnout(turnoutData->id, dccTurnoutData.address, dccTurnoutData.subAddress); return tt; +#else + (void)turnoutData; + return NULL; +#endif } void DCCTurnout::print(Print *stream) { @@ -396,6 +413,7 @@ } void DCCTurnout::save() { +#ifndef DISABLE_EEPROM // Write turnout definition and current position to EEPROM // First write common servo data, then // write the servo-specific data @@ -403,6 +421,7 @@ EEStore::advance(sizeof(_turnoutData)); EEPROM.put(EEStore::pointer(), _dccTurnoutData); EEStore::advance(sizeof(_dccTurnoutData)); +#endif } @@ -441,6 +460,7 @@ // Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point. /* static */ Turnout *VpinTurnout::load(struct TurnoutData *turnoutData) { +#ifndef DISABLE_EEPROM VpinTurnoutData vpinTurnoutData; // Read class-specific data from EEPROM EEPROM.get(EEStore::pointer(), vpinTurnoutData); @@ -450,6 +470,10 @@ VpinTurnout *tt = new VpinTurnout(turnoutData->id, vpinTurnoutData.vpin, turnoutData->closed); return tt; +#else + (void)turnoutData; + return NULL; +#endif } // Report 1 for thrown, 0 for closed. @@ -465,6 +489,7 @@ } void VpinTurnout::save() { +#ifndef DISABLE_EEPROM // Write turnout definition and current position to EEPROM // First write common servo data, then // write the servo-specific data @@ -472,6 +497,7 @@ EEStore::advance(sizeof(_turnoutData)); EEPROM.put(EEStore::pointer(), _vpinTurnoutData); EEStore::advance(sizeof(_vpinTurnoutData)); +#endif } diff --git a/Turnouts.h b/Turnouts.h index 6a55c15..d597c38 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -155,13 +155,14 @@ public: inline static Turnout *first() { return _firstTurnout; } +#ifndef DISABLE_EEPROM // Load all turnout definitions. static void load(); // Load one turnout definition static Turnout *loadTurnout(); // Save all turnout definitions static void store(); - +#endif static void printAll(Print *stream) { for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) tt->printState(stream); diff --git a/defines.h b/defines.h index 1d76f95..4a67326 100644 --- a/defines.h +++ b/defines.h @@ -65,8 +65,8 @@ // #define WIFI_SERIAL_LINK_SPEED 115200 -#if __has_include ( "myAutomation.h") && defined(BIG_RAM) +#if __has_include ( "myAutomation.h") && (defined(BIG_RAM) || defined(DISABLE_EEPROM)) #define RMFT_ACTIVE #endif -#endif \ No newline at end of file +#endif From a4f746c00cca0e5811033badeef8a4937fc3bd05 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 22 Nov 2021 00:41:47 +0100 Subject: [PATCH 02/15] Warn for broken configs --- GITHUB_SHA.h | 3 ++- defines.h | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 4338846..10207a2 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1,2 @@ -#define GITHUB_SHA "37904b5" +#define GITHUB_SHA "disable-eeprom-20211122-00:00" + diff --git a/defines.h b/defines.h index 4a67326..0580605 100644 --- a/defines.h +++ b/defines.h @@ -39,19 +39,29 @@ #if (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO) || defined(TEENSYDUINO)) #define BIG_RAM #endif -#if ENABLE_WIFI && defined(BIG_RAM) -#define WIFI_ON true -#ifndef WIFI_CHANNEL -#define WIFI_CHANNEL 1 -#endif +#if ENABLE_WIFI + #if defined(BIG_RAM) + #define WIFI_ON true + #ifndef WIFI_CHANNEL + #define WIFI_CHANNEL 1 + #endif + #else + #warning You have defined that you want WIFI but your hardware has not enough memory to do that, so WIFI DISABLED + #define WIFI_ON false + #endif #else -#define WIFI_ON false + #define WIFI_ON false #endif -#if ENABLE_ETHERNET && defined(BIG_RAM) -#define ETHERNET_ON true +#if ENABLE_ETHERNET + #if defined(BIG_RAM) + #define ETHERNET_ON true + #else + #warning You have defined that you want ETHERNET but your hardware has not enough memory to do that, so ETHERNET DISABLED + #define ETHERNET_ON false + #endif #else -#define ETHERNET_ON false + #define ETHERNET_ON false #endif #if WIFI_ON && ETHERNET_ON @@ -65,8 +75,12 @@ // #define WIFI_SERIAL_LINK_SPEED 115200 -#if __has_include ( "myAutomation.h") && (defined(BIG_RAM) || defined(DISABLE_EEPROM)) - #define RMFT_ACTIVE +#if __has_include ( "myAutomation.h") + #if defined(BIG_RAM) || defined(DISABLE_EEPROM) + #define RMFT_ACTIVE + #else + #warning You have myAutomation.h but your hardware has not enough memory to do that, so EX-RAIL DISABLED + #endif #endif #endif From 3bddeeda3ec3dd6ad4eb21520dc57a6f2ae37a11 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 25 Nov 2021 00:10:11 +0100 Subject: [PATCH 03/15] better long/short addr handling under ; configurable long/short border --- DCC.cpp | 14 +++++++------- DCC.h | 10 ++++++++++ DCCEXParser.cpp | 11 ++++++++++- WiThrottle.cpp | 17 ++++++++++++++--- config.example.h | 12 ++++++++++++ 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index f42ddf7..8726534 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -84,7 +84,7 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) { uint8_t nB = 0; // DIAG(F("setSpeedInternal %d %x"),cab,speedCode); - if (cab > 127) + if (cab > HIGHEST_SHORT_ADDR) b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address b[nB++] = lowByte(cab); @@ -124,7 +124,7 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) { byte b[4]; byte nB = 0; - if (cab > 127) + if (cab > HIGHEST_SHORT_ADDR) b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address b[nB++] = lowByte(cab); if (byte1!=0) b[nB++] = byte1; @@ -153,7 +153,7 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) { //non reminding advanced binary bit set byte b[5]; byte nB = 0; - if (cab > 127) + if (cab > HIGHEST_SHORT_ADDR) b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address b[nB++] = lowByte(cab); if (functionNumber <= 127) { @@ -262,7 +262,7 @@ void DCC::setAccessory(int address, byte number, bool activate) { void DCC::writeCVByteMain(int cab, int cv, byte bValue) { byte b[5]; byte nB = 0; - if (cab > 127) + if (cab > HIGHEST_SHORT_ADDR) b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address b[nB++] = lowByte(cab); @@ -283,7 +283,7 @@ void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) { bValue = bValue % 2; bNum = bNum % 8; - if (cab > 127) + if (cab > HIGHEST_SHORT_ADDR) b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address b[nB++] = lowByte(cab); @@ -548,7 +548,7 @@ void DCC::setLocoId(int id,ACK_CALLBACK callback) { callback(-1); return; } - if (id<=127) + if (id<=HIGHEST_SHORT_ADDR) ackManagerSetup(id, SHORT_LOCO_ID_PROG, callback); else ackManagerSetup(id | 0xc000,LONG_LOCO_ID_PROG, callback); @@ -906,7 +906,7 @@ void DCC::ackManagerLoop() { case COMBINELOCOID: // ackManagerStash is cv17, ackManagerByte is CV 18 - callback( ackManagerByte + ((ackManagerStash - 192) << 8)); + callback( LONG_ADDR_MARKER | ( ackManagerByte + ((ackManagerStash - 192) << 8))); return; case ITSKIP: diff --git a/DCC.h b/DCC.h index 8cb5d97..283b406 100644 --- a/DCC.h +++ b/DCC.h @@ -23,6 +23,16 @@ #include "MotorDrivers.h" #include "FSH.h" +#include "config.h" +#ifndef HIGHEST_SHORT_ADDR +#define HIGHEST_SHORT_ADDR 127 +#else +#if HIGHEST_SHORT_ADDR > 127 +#error short addr greater than 127 does not make sense +#endif +#endif +#define LONG_ADDR_MARKER 0x4000 + typedef void (*ACK_CALLBACK)(int16_t result); enum ackOp : byte diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index ed1f684..98cd1be 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -960,8 +960,17 @@ void DCCEXParser::callback_R(int16_t result) void DCCEXParser::callback_Rloco(int16_t result) { + if (result <= 0) + StringFormatter::send(getAsyncReplyStream(), F("\n")); + else if (result & LONG_ADDR_MARKER ) { //long addr + result = result & ~LONG_ADDR_MARKER; + if (result > HIGHEST_SHORT_ADDR) //real long + StringFormatter::send(getAsyncReplyStream(), F("\n"), result); + else + StringFormatter::send(getAsyncReplyStream(), F("\n"), result); + } else // short addr StringFormatter::send(getAsyncReplyStream(), F("\n"), result); - commitAsyncReplyStream(); + commitAsyncReplyStream(); } void DCCEXParser::callback_Wloco(int16_t result) diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 07017ba..62369ce 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -409,7 +409,7 @@ void WiThrottle::checkHeartbeat() { } char WiThrottle::LorS(int cab) { - return (cab<127)?'S':'L'; + return (cab<=HIGHEST_SHORT_ADDR)?'S':'L'; } // Drive Away feature. Callback handling @@ -421,9 +421,20 @@ char WiThrottle::stashThrottleChar; void WiThrottle::getLocoCallback(int16_t locoid) { stashStream->mark(stashClient); - if (locoid<0) StringFormatter::send(stashStream,F("HMNo loco found on prog track\n")); + + char addrchar; + if (locoid & LONG_ADDR_MARKER) { // long addr + locoid = locoid & ~LONG_ADDR_MARKER; + addrchar = 'L'; + } else + addrchar = 'S'; + + if (locoid<=0) + StringFormatter::send(stashStream,F("HMNo loco found on prog track\n")); + else if (addrchar == 'L' && locoid <= HIGHEST_SHORT_ADDR ) + StringFormatter::send(stashStream,F("HMLong addr <= 127 not supported\n")); else { - char addcmd[20]={'M',stashThrottleChar,'+',LorS(locoid) }; + char addcmd[20]={'M',stashThrottleChar,'+', addrchar}; itoa(locoid,addcmd+4,10); stashInstance->multithrottle(stashStream, (byte *)addcmd); DCCWaveform::progTrack.setPowerMode(POWERMODE::ON); diff --git a/config.example.h b/config.example.h index 5f26ca7..2708bae 100644 --- a/config.example.h +++ b/config.example.h @@ -128,6 +128,18 @@ The configuration file for DCC-EX Command Station // Define scroll mode as 0, 1 or 2 #define SCROLLMODE 1 +///////////////////////////////////////////////////////////////////////////////////// +// REDEFINE WHERE SHORT/LONG ADDR break is. According to NMRA the last short address +// is 127 and the first long address is 128. There are manufacturers which have +// another view. Lenz CS for example have considered addresses long from 100. If +// you want to change to that mode, do +//#define HIGHEST_SHORT_ADDR 99 +// If you want to run all your locos addressed long format, you could even do a +//#define HIGHEST_SHORT_ADDR 0 +// We do not support to use the same address, for example 100(long) and 100(short) +// at the same time, there must be a border. + + ///////////////////////////////////////////////////////////////////////////////////// // // DEFINE TURNOUTS/ACCESSORIES FOLLOW NORM RCN-213 From 8a17965cd2195b659c50c2d5c51bd7970be71dcf Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 25 Nov 2021 19:55:48 +0100 Subject: [PATCH 04/15] type and correct include --- DCC.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DCC.h b/DCC.h index 283b406..fea9a1a 100644 --- a/DCC.h +++ b/DCC.h @@ -23,7 +23,7 @@ #include "MotorDrivers.h" #include "FSH.h" -#include "config.h" +#include "defines.h" #ifndef HIGHEST_SHORT_ADDR #define HIGHEST_SHORT_ADDR 127 #else @@ -31,7 +31,7 @@ #error short addr greater than 127 does not make sense #endif #endif -#define LONG_ADDR_MARKER 0x4000 +const uint16_t LONG_ADDR_MARKER = 0x4000; typedef void (*ACK_CALLBACK)(int16_t result); From fd43a9b88b23732ac7003a1fad02a415e73bcfa9 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 25 Nov 2021 23:10:03 +0100 Subject: [PATCH 05/15] defines to reverse accessories and turnouts renamed --- DCCEXParser.cpp | 2 +- IO_DCCAccessory.cpp | 12 ++++++++---- config.example.h | 16 +++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index ed1f684..a412531 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -368,7 +368,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) || ((p[activep] & 0x01) != p[activep]) // invalid activate 0|1 ) break; // Honour the configuration option (config.h) which allows the command to be reversed -#ifdef DCC_ACCESSORY_RCN_213 +#ifdef DCC_ACCESSORY_COMMAND_REVERSE DCC::setAccessory(address, subaddress,p[activep]==0); #else DCC::setAccessory(address, subaddress,p[activep]==1); diff --git a/IO_DCCAccessory.cpp b/IO_DCCAccessory.cpp index e40198b..6e739cd 100644 --- a/IO_DCCAccessory.cpp +++ b/IO_DCCAccessory.cpp @@ -47,11 +47,15 @@ void DCCAccessoryDecoder::_begin() { // Device-specific write function. State 1=closed, 0=thrown. Adjust for RCN-213 compliance void DCCAccessoryDecoder::_write(VPIN id, int state) { int packedAddress = _packedAddress + id - _firstVpin; - #ifdef DIAG_IO - DIAG(F("DCC Write Linear Address:%d State:%d"), packedAddress, state); - #endif -#if !defined(DCC_ACCESSORY_RCN_213) +#if defined(HAL_ACCESSORY_COMMAND_REVERSE) state = !state; +#ifdef DIAG_IO + DIAG(F("DCC Write Linear Address:%d State:%d (inverted)"), packedAddress, state); +#endif +#else +#ifdef DIAG_IO + DIAG(F("DCC Write Linear Address:%d State:%d"), packedAddress, state); +#endif #endif DCC::setAccessory(ADDRESS(packedAddress), SUBADDRESS(packedAddress), state); } diff --git a/config.example.h b/config.example.h index 5f26ca7..c948c53 100644 --- a/config.example.h +++ b/config.example.h @@ -141,10 +141,20 @@ The configuration file for DCC-EX Command Station // don't add it to your config.h. //#define DCC_TURNOUTS_RCN_213 -// The following #define likewise inverts the behaviour of the command -// for triggering DCC Accessory Decoders, so that generates a +// By default, the driver which defines a DCC accessory decoder +// does send out the same state change on the DCC packet as it +// receives. This means a VPIN state=1 sends D=1 (close turnout +// or signal green) in the DCC packet. This can be reversed if +// necessary. +//#define HAL_ACCESSORY_COMMAND_REVERSE + +// If you have issues with that the direction of the accessory commands is +// reversed (for example when converting from another CS to DCC-EX) then +// you can use this to revese the sense of all accessory commmands sent +// over DCC++. This #define likewise inverts the behaviour of the command +// for triggering DCC Accessory Decoders, so that generates a // DCC packet with D=1 (close turnout) and generates D=0 // (throw turnout). -//#define DCC_ACCESSORY_RCN_213 +//#define DCC_ACCESSORY_COMMAND_REVERSE ///////////////////////////////////////////////////////////////////////////////////// From 43538d3b327c6e532f2410008dbab04758c0fa31 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 26 Nov 2021 19:32:45 +0100 Subject: [PATCH 06/15] smaller code --- DCCEXParser.cpp | 24 +++++++++++++----------- WiThrottle.cpp | 32 ++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 98cd1be..e3c9eac 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -958,18 +958,20 @@ void DCCEXParser::callback_R(int16_t result) commitAsyncReplyStream(); } -void DCCEXParser::callback_Rloco(int16_t result) -{ - if (result <= 0) - StringFormatter::send(getAsyncReplyStream(), F("\n")); - else if (result & LONG_ADDR_MARKER ) { //long addr - result = result & ~LONG_ADDR_MARKER; - if (result > HIGHEST_SHORT_ADDR) //real long - StringFormatter::send(getAsyncReplyStream(), F("\n"), result); +void DCCEXParser::callback_Rloco(int16_t result) { + const FSH * detail; + if (result<=0) { + detail=F("\n"); + } else { + bool longAddr=result & LONG_ADDR_MARKER; //long addr + if (longAddr) + result = result^LONG_ADDR_MARKER; + if (longAddr && result <= HIGHEST_SHORT_ADDR) + detail=F("\n"); else - StringFormatter::send(getAsyncReplyStream(), F("\n"), result); - } else // short addr - StringFormatter::send(getAsyncReplyStream(), F("\n"), result); + detail=F("\n"); + } + StringFormatter::send(getAsyncReplyStream(), detail, result); commitAsyncReplyStream(); } diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 62369ce..8aabb82 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -51,6 +51,8 @@ #include "version.h" #include "RMFT2.h" +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) #define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;locomark(stashClient); - char addrchar; - if (locoid & LONG_ADDR_MARKER) { // long addr - locoid = locoid & ~LONG_ADDR_MARKER; - addrchar = 'L'; - } else - addrchar = 'S'; - if (locoid<=0) StringFormatter::send(stashStream,F("HMNo loco found on prog track\n")); - else if (addrchar == 'L' && locoid <= HIGHEST_SHORT_ADDR ) - StringFormatter::send(stashStream,F("HMLong addr <= 127 not supported\n")); else { - char addcmd[20]={'M',stashThrottleChar,'+', addrchar}; - itoa(locoid,addcmd+4,10); - stashInstance->multithrottle(stashStream, (byte *)addcmd); - DCCWaveform::progTrack.setPowerMode(POWERMODE::ON); - DCC::setProgTrackSyncMain(true); // <1 JOIN> so we can drive loco away + // short or long + char addrchar; + if (locoid & LONG_ADDR_MARKER) { // long addr + locoid = locoid ^ LONG_ADDR_MARKER; + addrchar = 'L'; + } else + addrchar = 'S'; + if (addrchar == 'L' && locoid <= HIGHEST_SHORT_ADDR ) + StringFormatter::send(stashStream,F("HMLong addr <= " STR(HIGHEST_SHORT_ADDR) " not supported\n")); + else { + char addcmd[20]={'M',stashThrottleChar,'+', addrchar}; + itoa(locoid,addcmd+4,10); + stashInstance->multithrottle(stashStream, (byte *)addcmd); + DCCWaveform::progTrack.setPowerMode(POWERMODE::ON); + DCC::setProgTrackSyncMain(true); // <1 JOIN> so we can drive loco away + } } stashStream->commit(); } From d4ee215ae6491f55ae51c264de95e27d9d3be725 Mon Sep 17 00:00:00 2001 From: Florian Becker <1367506+make-ing@users.noreply.github.com> Date: Tue, 30 Nov 2021 11:12:29 +0100 Subject: [PATCH 07/15] fix typo (#194) replace "manu" with "many" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94a01c6..9062575 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Both CommandStation-EX and BaseStation-Classic support much of the NMRA Digital * Control of all cab functions F0-F28 and F29-F68 * Main Track: Write configuration variable bytes and set/clear specific configuration variable (CV) bits (aka Programming on Main or POM) * Programming Track: Same as the main track with the addition of reading configuration variable bytes -* And manu more custom features. see [What's new in CommandStation-EX?](#whats-new-in-commandstation-ex) +* And many more custom features. see [What's new in CommandStation-EX?](#whats-new-in-commandstation-ex) # What’s in this Repository? From 419822ef0637d1dcb3305f2ed8bda2b4d2f9aa53 Mon Sep 17 00:00:00 2001 From: Florian Becker <1367506+make-ing@users.noreply.github.com> Date: Tue, 30 Nov 2021 10:12:49 +0000 Subject: [PATCH 08/15] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 7cf2ed1..216cf8a 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "a2f8a8e" +#define GITHUB_SHA "d4ee215" From 67e48d34f48b35b7c67207416d569bc03542abcf Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 30 Nov 2021 19:40:31 +0100 Subject: [PATCH 09/15] do not include config.h direct --- EEStore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EEStore.cpp b/EEStore.cpp index 15e2b2e..1a4cd2c 100644 --- a/EEStore.cpp +++ b/EEStore.cpp @@ -19,7 +19,7 @@ * along with CommandStation. If not, see . */ -#include "config.h" +#include "defines.h" #ifndef DISABLE_EEPROM #include "EEStore.h" From 9018ec9757f94341f246fee792ce9f3848dc8e11 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 30 Nov 2021 19:56:09 +0100 Subject: [PATCH 10/15] DISABLE_EEPROM explanation --- config.example.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config.example.h b/config.example.h index 5f26ca7..e064db8 100644 --- a/config.example.h +++ b/config.example.h @@ -128,6 +128,16 @@ The configuration file for DCC-EX Command Station // Define scroll mode as 0, 1 or 2 #define SCROLLMODE 1 +///////////////////////////////////////////////////////////////////////////////////// +// DISABLE EEPROM +// +// If you do not need the EEPROM at all, you can disable all the code that saves +// data in the EEPROM. You might want to do that if you are in a Arduino UNO +// and want to use the EX-RAIL automation. Otherwise you do not have enough RAM +// to do that. Of course, then none of the EEPROM related commands works. +// +// #define DISABLE_EEPROM + ///////////////////////////////////////////////////////////////////////////////////// // // DEFINE TURNOUTS/ACCESSORIES FOLLOW NORM RCN-213 From 58afea135c2a3d725be8d6e7bc3d75e5325f997c Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 30 Nov 2021 18:57:58 +0000 Subject: [PATCH 11/15] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 24d8907..6f908b6 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "disable-eeprom-20211130-19:44" +#define GITHUB_SHA "9018ec9" From 7d665fe577f013095db73950e4e7915f9e39ad7d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 30 Nov 2021 20:08:58 +0100 Subject: [PATCH 12/15] update version --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index 3089db9..967d6e6 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,7 @@ #include "StringFormatter.h" -#define VERSION "3.2.0 rc5" +#define VERSION "3.2.0 rc6" // 3.2.0 Major functional and non-functional changes. // New HAL added for I/O (digital and analogue inputs and outputs, servos etc). // Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. From 4924cc77797ecd665f5f99c907454cec69803376 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 30 Nov 2021 20:11:45 +0100 Subject: [PATCH 13/15] update version --- version.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/version.h b/version.h index 967d6e6..1d8bd01 100644 --- a/version.h +++ b/version.h @@ -21,6 +21,8 @@ // Configuration options to globally flip polarity of DCC Accessory states when driven // from command and command. // Increased use of display for showing loco decoder programming information. +// Can disable EEPROM code +// Can define border between long and short addresses // ... // 3.1.7 Bugfix: Unknown locos should have speed forward // 3.1.6 Make output ID two bytes and guess format/size of registered outputs found in EEPROM From 0f728c1c156f6884ba5229bfd464ba9be4305e2a Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 2 Dec 2021 08:35:42 +0100 Subject: [PATCH 14/15] 3 diffenent defines to fix RCN-213 compat --- version.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version.h b/version.h index 1d8bd01..31be785 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,7 @@ #include "StringFormatter.h" -#define VERSION "3.2.0 rc6" +#define VERSION "3.2.0 rc7" // 3.2.0 Major functional and non-functional changes. // New HAL added for I/O (digital and analogue inputs and outputs, servos etc). // Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules. @@ -23,6 +23,7 @@ // Increased use of display for showing loco decoder programming information. // Can disable EEPROM code // Can define border between long and short addresses +// Turnout and accessory states (thrown/closed = 0/1 or 1/0) can be set to match RCN-213 // ... // 3.1.7 Bugfix: Unknown locos should have speed forward // 3.1.6 Make output ID two bytes and guess format/size of registered outputs found in EEPROM From 92591c8a2ef12707477ad702fc10e51a24503149 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 2 Dec 2021 07:36:44 +0000 Subject: [PATCH 15/15] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 6f908b6..693983d 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "9018ec9" +#define GITHUB_SHA "0f728c1"