diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 67bcc54..e7087ad 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -209,9 +209,7 @@ int16_t CommandDistributor::retClockTime() { void CommandDistributor::broadcastLoco(byte slot) { DCC::LOCO * sp=&DCC::speedTable[slot]; - uint32_t func = sp->functions; - func = func & 0x1fffffff; // mask out bits 0-28 - broadcastReply(COMMAND_TYPE, F("\n"), sp->loco,slot,sp->speedCode,func); + broadcastReply(COMMAND_TYPE, F("\n"), sp->loco,slot,sp->speedCode,sp->functions); #ifdef SABERTOOTH if (Serial2 && sp->loco == SABERTOOTH) { static uint8_t rampingmode = 0; diff --git a/DCC.cpp b/DCC.cpp index 5ab7eff..a8bc953 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -219,8 +219,9 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) { } else { speedTable[reg].functions &= ~funcmask; } - if (speedTable[reg].functions != previous && functionNumber <= 28) { - updateGroupflags(speedTable[reg].groupFlags, functionNumber); + if (speedTable[reg].functions != previous) { + if (functionNumber <= 28) + updateGroupflags(speedTable[reg].groupFlags, functionNumber); CommandDistributor::broadcastLoco(reg); } return true; @@ -235,14 +236,14 @@ void DCC::changeFn( int cab, int16_t functionNumber) { speedTable[reg].functions ^= funcmask; if (functionNumber <= 28) { updateGroupflags(speedTable[reg].groupFlags, functionNumber); - CommandDistributor::broadcastLoco(reg); } + CommandDistributor::broadcastLoco(reg); } // Report function state (used from withrottle protocol) // returns 0 false, 1 true or -1 for do not know int8_t DCC::getFn( int cab, int16_t functionNumber) { - if (cab<=0 || functionNumber>28) + if (cab<=0 || functionNumber>31) return -1; // unknown int reg = lookupSpeedTable(cab); if (reg<0) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2eeedc9..fa4c9f8 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -68,7 +68,7 @@ Once a new OPCODE is decided upon, update this list. K, Reserved for future use - Potentially Railcom l, Loco speedbyte/function map broadcast L, Reserved for LCC interface (implemented in EXRAIL) - m, + m, message to throttles broadcast M, Write DCC packet n, N, @@ -283,25 +283,22 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) return; // filterCallback asked us to ignore case 't': // THROTTLE { - if (params==1) { // display state - - int16_t slot=DCC::lookupSpeedTable(p[0],false); - if (slot>=0) { - DCC::LOCO * sp=&DCC::speedTable[slot]; - StringFormatter::send(stream,F("\n"), - sp->loco,slot,sp->speedCode,sp->functions); - } - else // send dummy state speed 0 fwd no functions. - StringFormatter::send(stream,F("\n"),p[0]); - return; - } - int16_t cab; int16_t tspeed; int16_t direction; - + + if (params==1) { // display state + int16_t slot=DCC::lookupSpeedTable(p[0],false); + if (slot>=0) + CommandDistributor::broadcastLoco(slot); + else // send dummy state speed 0 fwd no functions. + StringFormatter::send(stream,F("\n"),p[0]); + return; + } + if (params == 4) { // + // ignore register p[0] cab = p[1]; tspeed = p[2]; direction = p[3]; diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 0ee465a..8e16f0c 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-stm32ECa-202403082308Z" +#define GITHUB_SHA "devel-stm32ECa-202403240600Z" \ No newline at end of file diff --git a/IO_RotaryEncoder.h b/IO_RotaryEncoder.h index 9d40b34..2e6cfe7 100644 --- a/IO_RotaryEncoder.h +++ b/IO_RotaryEncoder.h @@ -42,9 +42,9 @@ * Defining in myAutomation.h requires the device driver to be included in addition to the HAL() statement. Examples: * * #include "IO_RotaryEncoder.h" -* HAL(RotaryEncoder, 700, 1, 0x70) // Define single Vpin, no feedback or position sent to rotary encoder software -* HAL(RotaryEncoder, 700, 2, 0x70) // Define two Vpins, feedback only sent to rotary encoder software -* HAL(RotaryEncoder, 700, 3, 0x70) // Define three Vpins, can send feedback and position update to rotary encoder software +* HAL(RotaryEncoder, 700, 1, 0x67) // Define single Vpin, no feedback or position sent to rotary encoder software +* HAL(RotaryEncoder, 700, 2, 0x67) // Define two Vpins, feedback only sent to rotary encoder software +* HAL(RotaryEncoder, 700, 3, 0x67) // Define three Vpins, can send feedback and position update to rotary encoder software * * Refer to the documentation for further information including the valid activities and examples. */ diff --git a/MotorDrivers.h b/MotorDrivers.h index 907c11b..9e5f85b 100644 --- a/MotorDrivers.h +++ b/MotorDrivers.h @@ -1,7 +1,7 @@ /* * © 2022-2023 Paul M. Antoine * © 2021 Fred Decker - * © 2020-2023 Harald Barth + * © 2020-2024 Harald Barth * (c) 2020 Chris Harlow. All rights reserved. * (c) 2021 Fred Decker. All rights reserved. * (c) 2020 Harald Barth. All rights reserved. @@ -57,6 +57,10 @@ // of the brake pin on the motor bridge is inverted // (HIGH == release brake) +// You can have a CS wihout any possibility to do any track signal. +// That's strange but possible. +#define NO_SHIELD F("No shield at all") + // Arduino STANDARD Motor Shield, used on different architectures: #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) diff --git a/TrackManager.cpp b/TrackManager.cpp index e357e7f..338b11c 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -1,6 +1,6 @@ /* * © 2022 Chris Harlow - * © 2022,2023 Harald Barth + * © 2022-2024 Harald Barth * © 2023 Colin Murdoch * All rights reserved. * @@ -41,7 +41,7 @@ MotorDriver * TrackManager::track[MAX_TRACKS]; int16_t TrackManager::trackDCAddr[MAX_TRACKS]; -byte TrackManager::lastTrack=0; +int8_t TrackManager::lastTrack=-1; bool TrackManager::progTrackSyncMain=false; bool TrackManager::progTrackBoosted=false; int16_t TrackManager::joinRelay=UNUSED_PIN; @@ -498,7 +498,11 @@ void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermod // Set track power for this track, inependent of mode void TrackManager::setTrackPower(POWERMODE powermode, byte t) { - MotorDriver *driver=track[t]; + MotorDriver *driver=track[t]; + if (driver == NULL) { // track is not defined at all + DIAG(F("Error: Track %c does not exist"), t+'A'); + return; + } TRACK_MODE trackmode = driver->getMode(); POWERMODE oldpower = driver->getPower(); if (trackmode & TRACK_MODE_NONE) { diff --git a/TrackManager.h b/TrackManager.h index c1f314a..7dce0ee 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -1,6 +1,6 @@ /* * © 2022 Chris Harlow - * © 2022 Harald Barth + * © 2022-2024 Harald Barth * © 2023 Colin Murdoch * * All rights reserved. @@ -46,7 +46,7 @@ const byte TRACK_POWER_1=1, TRACK_POWER_ON=1; class TrackManager { public: static void Setup(const FSH * shieldName, - MotorDriver * track0, + MotorDriver * track0=NULL, MotorDriver * track1=NULL, MotorDriver * track2=NULL, MotorDriver * track3=NULL, @@ -108,7 +108,7 @@ class TrackManager { private: static void addTrack(byte t, MotorDriver* driver); - static byte lastTrack; + static int8_t lastTrack; static byte nextCycleTrack; static void applyDCSpeed(byte t); diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 56efeeb..e8a1254 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -571,7 +571,7 @@ void WiThrottle::sendRoutes(Print* stream) { void WiThrottle::sendFunctions(Print* stream, byte loco) { int16_t locoid=myLocos[loco].cab; - int fkeys=29; + int fkeys=32; // upper limit (send functions 0 to 31) myLocos[loco].functionToggles=1<<2; // F2 (HORN) is a non-toggle #ifdef EXRAIL_ACTIVE diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index 70eb96a..0934723 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -351,12 +351,13 @@ void halSetup() { //======================================================================= // The parameters are: // firstVpin = First available Vpin to allocate - // numPins= Number of Vpins to allocate, can be either 1 or 2 - // i2cAddress = Available I2C address (default 0x70) + // numPins= Number of Vpins to allocate, can be either 1 to 3 + // i2cAddress = Available I2C address (default 0x67) //RotaryEncoder::create(firstVpin, numPins, i2cAddress); - //RotaryEncoder::create(700, 1, 0x70); - //RotaryEncoder::create(701, 2, 0x71); + //RotaryEncoder::create(700, 1, 0x67); + //RotaryEncoder::create(700, 2, 0x67); + //RotaryEncoder::create(700, 3, 0x67); //======================================================================= // The following directive defines an EX-FastClock instance. diff --git a/version.h b/version.h index 4c737f8..7dac629 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,10 @@ #include "StringFormatter.h" -#define VERSION "5.3.6" +#define VERSION "5.3.7" +// 5.2.41 - Update rotary encoder default address to 0x67 +// 5.2.40 - Allow no shield +// 5.2.39 - Functions for DC frequency: Use func up to F31 // 5.2.38 - Exrail MESSAGE("text") to send a user message to all // connected throttles (uses and withrottle Hmtext. // 5.2.37 - Bugfix ESP32: Use BOOSTER_INPUT define