diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 961df38..3fe1e96 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -155,6 +155,7 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { #endif } +#ifdef USEFASTCLOCK void CommandDistributor::broadcastClockTime(int16_t time, int8_t rate) { // The JMRI clock command is of the form : PFT65871<;>4 // The CS broadcast is of the form "%d\n"), time*60, rate); #endif } +#endif void CommandDistributor::broadcastLoco(byte slot) { DCC::LOCO * sp=&DCC::speedTable[slot]; diff --git a/CommandDistributor.h b/CommandDistributor.h index c816b94..d51b2b6 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -45,7 +45,9 @@ public : static void broadcastLoco(byte slot); static void broadcastSensor(int16_t id, bool value); static void broadcastTurnout(int16_t id, bool isClosed); +#ifdef USEFASTCLOCK static void broadcastClockTime(int16_t time, int8_t rate); +#ifdef static void broadcastPower(); static void broadcastText(const FSH * msg); template static void broadcastReply(clientType type, Targs... msg); diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 486ef32..3898f95 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -97,7 +97,9 @@ Print *DCCEXParser::stashStream = NULL; RingStream *DCCEXParser::stashRingStream = NULL; byte DCCEXParser::stashTarget=0; +#ifdef USEFASTCLOCK int16_t lastclocktime = 0; +#endif // This is a JMRI command parser. // It doesnt know how the string got here, nor how it gets back. @@ -572,9 +574,15 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) case 'J' : // throttle info access { +#ifdef USEFASTCLOCK if ((params<1) | (params>3)) break; // +#endif +#ifndef USEFASTCLOCK + if ((params<1) | (params>2)) break; // +#endif int16_t id=(params==2)?p[1]:0; switch(p[0]) { +#ifdef USEFASTCLOCK case HASH_KEYWORD_C: // sets time and speed if (params==1) { // returns latest time StringFormatter::send(stream, F("\n"), lastclocktime); @@ -593,6 +601,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) lastclocktime = p[1]; } return; +#endif case HASH_KEYWORD_A: // returns automations/routes StringFormatter::send(stream, F(" diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index f969544..1b5b51e 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -92,7 +92,9 @@ LookList * RMFT2::onRedLookup=NULL; LookList * RMFT2::onAmberLookup=NULL; LookList * RMFT2::onGreenLookup=NULL; LookList * RMFT2::onChangeLookup=NULL; +#ifdef USEFASTCLOCK LookList * RMFT2::onClockLookup=NULL; +#endif #define GET_OPCODE GETHIGHFLASH(RMFT2::RouteCode,progCounter) #define SKIPOP progCounter+=3 @@ -176,7 +178,9 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) { onAmberLookup=LookListLoader(OPCODE_ONAMBER); onGreenLookup=LookListLoader(OPCODE_ONGREEN); onChangeLookup=LookListLoader(OPCODE_ONCHANGE); + #ifdef USEFASTCLOCK onClockLookup=LookListLoader(OPCODE_ONTIME); + #endif // Second pass startup, define any turnouts or servos, set signals red // add sequences onRoutines to the lookups @@ -977,7 +981,9 @@ void RMFT2::loop2() { case OPCODE_ONAMBER: case OPCODE_ONGREEN: case OPCODE_ONCHANGE: + #ifdef USEFASTCLOCK case OPCODE_ONTIME: + #endif break; @@ -1110,12 +1116,14 @@ void RMFT2::changeEvent(int16_t vpin, bool change) { if (change) handleEvent(F("CHANGE"),onChangeLookup,vpin); } +#ifdef USEFASTCLOCK void RMFT2::clockEvent(int16_t clocktime, bool change) { // Hunt for an ONTIME for this time if (Diag::CMD) DIAG(F("Looking for clock event at : %d"), clocktime); - if (change) handleEvent(F("CHANGE"),onClockLookup,clocktime); + if (change) handleEvent(F("CLOCK"),onClockLookup,clocktime); } +#endif void RMFT2::handleEvent(const FSH* reason,LookList* handlers, int16_t id) { int pc= handlers->find(id); diff --git a/EXRAIL2.h b/EXRAIL2.h index 69fd382..7f04458 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -55,8 +55,10 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_SET_TRACK, OPCODE_ONRED,OPCODE_ONAMBER,OPCODE_ONGREEN, OPCODE_ONCHANGE, +#ifdef USEFASTCLOCK OPCODE_ONCLOCKTIME, OPCODE_ONTIME, +#endif // OPcodes below this point are skip-nesting IF operations // placed here so that they may be skipped as a group @@ -118,7 +120,9 @@ class LookList { static void turnoutEvent(int16_t id, bool closed); static void activateEvent(int16_t addr, bool active); static void changeEvent(int16_t id, bool change); + #ifdef USEFASTCLOCK static void clockEvent(int16_t clocktime, bool change); + #endif static const int16_t SERVO_SIGNAL_FLAG=0x4000; static const int16_t ACTIVE_HIGH_SIGNAL_FLAG=0x2000; static const int16_t DCC_SIGNAL_FLAG=0x1000; @@ -176,7 +180,9 @@ private: static LookList * onAmberLookup; static LookList * onGreenLookup; static LookList * onChangeLookup; +#ifdef USEFASTCLOCK static LookList * onClockLookup; +#endif // Local variables - exist for each instance/task RMFT2 *next; // loop chain diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index a5e6d90..409cdcd 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -86,8 +86,10 @@ #undef ONDEACTIVATE #undef ONDEACTIVATEL #undef ONCLOSE +#ifdef USEFASTCLOCK #undef ONTIME #undef ONCLOCKTIME +#endif #undef ONGREEN #undef ONRED #undef ONTHROW @@ -200,8 +202,10 @@ #define ONACTIVATE(addr,subaddr) #define ONACTIVATEL(linear) #define ONAMBER(signal_id) +#ifdef USEFASTCLOCK #define ONTIME(value) #define ONCLOCKTIME(hours,mins) +#endif #define ONDEACTIVATE(addr,subaddr) #define ONDEACTIVATEL(linear) #define ONCLOSE(turnout_id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 7ef3acd..0d807d1 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -55,13 +55,11 @@ // helper macro for turnout description as HIDDEN #define HIDDEN "\x01" +#ifdef USEFASTCLOCK // helper macro to strip leading zeros off time inputs // (10#mins)%100) #define STRIP_ZERO(value) 10##value%100 - -// helper macro to strip leading zeros off time inputs -// (10#mins)%100) -#define STRIP_ZERO(value) 10##value%100 +#endif // Pass 1 Implements aliases #include "EXRAIL2MacroReset.h" @@ -305,8 +303,10 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { #define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3), #define ONAMBER(signal_id) OPCODE_ONAMBER,V(signal_id), #define ONCLOSE(turnout_id) OPCODE_ONCLOSE,V(turnout_id), +#ifdef USEFASTCLOCK #define ONTIME(value) OPCODE_ONTIME,V(value), #define ONCLOCKTIME(hours,mins) OPCODE_ONTIME,V((STRIP_ZERO(hours)*60)+STRIP_ZERO(mins)), +#endif #define ONDEACTIVATE(addr,subaddr) OPCODE_ONDEACTIVATE,V(addr<<2|subaddr), #define ONDEACTIVATEL(linear) OPCODE_ONDEACTIVATE,V(linear+3), #define ONGREEN(signal_id) OPCODE_ONGREEN,V(signal_id), diff --git a/IO_EXFastclock.h b/IO_EXFastclock.h index c9985f2..22bb94e 100644 --- a/IO_EXFastclock.h +++ b/IO_EXFastclock.h @@ -26,8 +26,8 @@ */ #ifndef IO_EXFastclock_h - #define IO_EXFastclock_h -#endif +#define IO_EXFastclock_h + #include "IODevice.h" #include "I2CManager.h" @@ -55,12 +55,12 @@ static void EXFastClock::create(uint8_t _I2CAddress) { DIAG(F("Clock check result - %d"), _checkforclock); if (_checkforclock == 0) { FAST_CLOCK_EXISTS = true; - DIAG(F("I2C Fast Clock found at x%x"), _I2CAddress); + //DIAG(F("I2C Fast Clock found at x%x"), _I2CAddress); new EXFastClock(_I2CAddress); } else { FAST_CLOCK_EXISTS = false; - DIAG(F("No Fast Clock found")); + //DIAG(F("No Fast Clock found")); LCD(6,F("CLOCK NOT FOUND")); } @@ -85,7 +85,7 @@ void _begin() override { #endif } else { _deviceState = DEVSTATE_FAILED; - LCD(6,F("CLOCK NOT FOUND")); + //LCD(6,F("CLOCK NOT FOUND")); DIAG(F("Fast Clock Not Found at address %d"), _I2CAddress); } } @@ -107,8 +107,8 @@ void _loop(unsigned long currentMicros) override{ if (_clocktime != _previousclocktime) { _previousclocktime = _clocktime; - if (Diag::CMD) - DIAG(F("Received Clock Time is: %d at rate: %d"), _clocktime, _clockrate); + //if (Diag::CMD) + // DIAG(F("Received Clock Time is: %d at rate: %d"), _clocktime, _clockrate); LCD(6,F(("Clk Time:%d Sp %d")), _clocktime, _clockrate); RMFT2::clockEvent(_clocktime,1); // Now tell everyone else what the time is. @@ -132,3 +132,5 @@ void _display() { DIAG(F("FastCLock on I2C:x%x - %S"), _I2CAddress, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } }; + +#endif diff --git a/config.example.h b/config.example.h index aae18a9..a2d97c5 100644 --- a/config.example.h +++ b/config.example.h @@ -224,4 +224,8 @@ The configuration file for DCC-EX Command Station // //#define SERIAL_BT_COMMANDS + +// FastClock Enabler +// To build the FastClock code into the CS please uncomment the line below +//#define USEFASTCLOCK /////////////////////////////////////////////////////////////////////////////////////