1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 18:16:13 +01:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Kcsmith0708
911421e8d7
Merge 2afb5f3d6c into 1398cf1999 2023-12-20 23:11:03 +01:00
peteGSX
1398cf1999
Merge pull request #373 from DCC-EX:ex-ioexpander-no-analogue-pins-fix
Ex-ioexpander-no-analogue-pins-fix
2023-12-19 18:49:18 +10:00
peteGSX
797028b223 Ready to test 2023-12-19 07:30:15 +10:00
Harald Barth
1881d4c9ad version 5.2.15 2023-12-13 11:41:57 +01:00
Harald Barth
18116a391c move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions 2023-12-13 11:40:15 +01:00
Harald Barth
a1accec79a add repeats to function packets that are not reminded in accordance with accessory packets 2023-12-13 10:55:58 +01:00
10 changed files with 61 additions and 51 deletions

View File

@ -283,7 +283,7 @@ void CommandDistributor::broadcastPower() {
//DIAG(F("m=%d p=%d j=%d"), main, prog, join); //DIAG(F("m=%d p=%d j=%d"), main, prog, join);
const FSH * reason=F(""); const FSH * reason=F("");
if (join) { if (join) {
reason = F("JOIN"); reason = F(" JOIN"); // with space at start so we can append without space
broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason); broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason);
} else { } else {
if (main) { if (main) {
@ -303,7 +303,7 @@ void CommandDistributor::broadcastPower() {
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state); broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state);
#endif #endif
LCD(2,F("Power %S %S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),reason); LCD(2,F("Power %S%S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),reason);
} }
void CommandDistributor::broadcastRaw(clientType type, char * msg) { void CommandDistributor::broadcastRaw(clientType type, char * msg) {

26
DCC.cpp
View File

@ -122,7 +122,7 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) {
DCCWaveform::mainTrack.schedulePacket(b, nB, 0); DCCWaveform::mainTrack.schedulePacket(b, nB, 0);
} }
void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) { void DCC::setFunctionInternal(int cab, byte byte1, byte byte2, byte count) {
// DIAG(F("setFunctionInternal %d %x %x"),cab,byte1,byte2); // DIAG(F("setFunctionInternal %d %x %x"),cab,byte1,byte2);
byte b[4]; byte b[4];
byte nB = 0; byte nB = 0;
@ -133,7 +133,7 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) {
if (byte1!=0) b[nB++] = byte1; if (byte1!=0) b[nB++] = byte1;
b[nB++] = byte2; b[nB++] = byte2;
DCCWaveform::mainTrack.schedulePacket(b, nB, 0); DCCWaveform::mainTrack.schedulePacket(b, nB, count);
} }
// returns speed steps 0 to 127 (1 == emergency stop) // returns speed steps 0 to 127 (1 == emergency stop)
@ -619,33 +619,39 @@ bool DCC::issueReminder(int reg) {
break; break;
case 1: // remind function group 1 (F0-F4) case 1: // remind function group 1 (F0-F4)
if (flags & FN_GROUP_1) if (flags & FN_GROUP_1)
setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4)); // 100D DDDD #ifndef DISABLE_FUNCTION_REMINDERS
#ifdef DISABLE_FUNCTION_REMINDERS setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4),0); // 100D DDDD
#else
setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4),2);
flags&= ~FN_GROUP_1; // dont send them again flags&= ~FN_GROUP_1; // dont send them again
#endif #endif
break; break;
case 2: // remind function group 2 F5-F8 case 2: // remind function group 2 F5-F8
if (flags & FN_GROUP_2) if (flags & FN_GROUP_2)
setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F)); // 1011 DDDD #ifndef DISABLE_FUNCTION_REMINDERS
#ifdef DISABLE_FUNCTION_REMINDERS setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F),0); // 1011 DDDD
#else
setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F),2);
flags&= ~FN_GROUP_2; // dont send them again flags&= ~FN_GROUP_2; // dont send them again
#endif #endif
break; break;
case 3: // remind function group 3 F9-F12 case 3: // remind function group 3 F9-F12
if (flags & FN_GROUP_3) if (flags & FN_GROUP_3)
setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F)); // 1010 DDDD #ifndef DISABLE_FUNCTION_REMINDERS
#ifdef DISABLE_FUNCTION_REMINDERS setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F),0); // 1010 DDDD
#else
setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F),2);
flags&= ~FN_GROUP_3; // dont send them again flags&= ~FN_GROUP_3; // dont send them again
#endif #endif
break; break;
case 4: // remind function group 4 F13-F20 case 4: // remind function group 4 F13-F20
if (flags & FN_GROUP_4) if (flags & FN_GROUP_4)
setFunctionInternal(loco,222, ((functions>>13)& 0xFF)); setFunctionInternal(loco,222, ((functions>>13)& 0xFF),2);
flags&= ~FN_GROUP_4; // dont send them again flags&= ~FN_GROUP_4; // dont send them again
break; break;
case 5: // remind function group 5 F21-F28 case 5: // remind function group 5 F21-F28
if (flags & FN_GROUP_5) if (flags & FN_GROUP_5)
setFunctionInternal(loco,223, ((functions>>21)& 0xFF)); setFunctionInternal(loco,223, ((functions>>21)& 0xFF),2);
flags&= ~FN_GROUP_5; // dont send them again flags&= ~FN_GROUP_5; // dont send them again
break; break;
} }

2
DCC.h
View File

@ -109,7 +109,7 @@ private:
static byte loopStatus; static byte loopStatus;
static void setThrottle2(uint16_t cab, uint8_t speedCode); static void setThrottle2(uint16_t cab, uint8_t speedCode);
static void updateLocoReminder(int loco, byte speedCode); static void updateLocoReminder(int loco, byte speedCode);
static void setFunctionInternal(int cab, byte fByte, byte eByte); static void setFunctionInternal(int cab, byte fByte, byte eByte, byte count);
static bool issueReminder(int reg); static bool issueReminder(int reg);
static int lastLocoReminder; static int lastLocoReminder;
static int highestUsedReg; static int highestUsedReg;

View File

@ -587,7 +587,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
} }
else break; // will reply <X> else break; // will reply <X>
} }
CommandDistributor::broadcastPower();
//TrackManager::streamTrackState(NULL,t); //TrackManager::streamTrackState(NULL,t);
return; return;
@ -619,7 +618,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
} }
else break; // will reply <X> else break; // will reply <X>
} }
CommandDistributor::broadcastPower();
return; return;
} }

View File

@ -414,7 +414,6 @@ void RMFT2::driveLoco(byte speed) {
power on appropriate track if DC or main if dcc power on appropriate track if DC or main if dcc
if (TrackManager::getMainPowerMode()==POWERMODE::OFF) { if (TrackManager::getMainPowerMode()==POWERMODE::OFF) {
TrackManager::setMainPower(POWERMODE::ON); TrackManager::setMainPower(POWERMODE::ON);
CommandDistributor::broadcastPower();
} }
**********/ **********/
@ -642,7 +641,6 @@ void RMFT2::loop2() {
case OPCODE_POWEROFF: case OPCODE_POWEROFF:
TrackManager::setPower(POWERMODE::OFF); TrackManager::setPower(POWERMODE::OFF);
TrackManager::setJoin(false); TrackManager::setJoin(false);
CommandDistributor::broadcastPower();
break; break;
case OPCODE_SET_POWER: case OPCODE_SET_POWER:
@ -837,12 +835,10 @@ void RMFT2::loop2() {
case OPCODE_JOIN: case OPCODE_JOIN:
TrackManager::setPower(POWERMODE::ON); TrackManager::setPower(POWERMODE::ON);
TrackManager::setJoin(true); TrackManager::setJoin(true);
CommandDistributor::broadcastPower();
break; break;
case OPCODE_UNJOIN: case OPCODE_UNJOIN:
TrackManager::setJoin(false); TrackManager::setJoin(false);
CommandDistributor::broadcastPower();
break; break;
case OPCODE_READ_LOCO1: // READ_LOCO is implemented as 2 separate opcodes case OPCODE_READ_LOCO1: // READ_LOCO is implemented as 2 separate opcodes
@ -870,7 +866,6 @@ void RMFT2::loop2() {
case OPCODE_POWERON: case OPCODE_POWERON:
TrackManager::setMainPower(POWERMODE::ON); TrackManager::setMainPower(POWERMODE::ON);
TrackManager::setJoin(false); TrackManager::setJoin(false);
CommandDistributor::broadcastPower();
break; break;
case OPCODE_START: case OPCODE_START:

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202311270714Z" #define GITHUB_SHA "devel-202312131041Z"

View File

@ -22,13 +22,10 @@
* This device driver will configure the device on startup, along with * This device driver will configure the device on startup, along with
* interacting with the device for all input/output duties. * interacting with the device for all input/output duties.
* *
* To create EX-IOExpander devices, these are defined in myHal.cpp: * To create EX-IOExpander devices, these are defined in myAutomation.h:
* (Note the device driver is included by default) * (Note the device driver is included by default)
* *
* void halSetup() { * HAL(EXIOExpander,800,18,0x65)
* // EXIOExpander::create(vpin, num_vpins, i2c_address);
* EXIOExpander::create(800, 18, 0x65);
* }
* *
* All pins on an EX-IOExpander device are allocated according to the pin map for the specific * All pins on an EX-IOExpander device are allocated according to the pin map for the specific
* device in use. There is no way for the device driver to sanity check pins are used for the * device in use. There is no way for the device driver to sanity check pins are used for the
@ -98,25 +95,30 @@ private:
_numAnaloguePins = receiveBuffer[2]; _numAnaloguePins = receiveBuffer[2];
// See if we already have suitable buffers assigned // See if we already have suitable buffers assigned
size_t digitalBytesNeeded = (_numDigitalPins + 7) / 8; if (_numDigitalPins>0) {
if (_digitalPinBytes < digitalBytesNeeded) { size_t digitalBytesNeeded = (_numDigitalPins + 7) / 8;
// Not enough space, free any existing buffer and allocate a new one if (_digitalPinBytes < digitalBytesNeeded) {
if (_digitalPinBytes > 0) free(_digitalInputStates); // Not enough space, free any existing buffer and allocate a new one
_digitalInputStates = (byte*) calloc(_digitalPinBytes, 1); if (_digitalPinBytes > 0) free(_digitalInputStates);
_digitalPinBytes = digitalBytesNeeded; _digitalInputStates = (byte*) calloc(_digitalPinBytes, 1);
} _digitalPinBytes = digitalBytesNeeded;
size_t analogueBytesNeeded = _numAnaloguePins * 2; }
if (_analoguePinBytes < analogueBytesNeeded) { }
// Free any existing buffers and allocate new ones.
if (_analoguePinBytes > 0) { if (_numAnaloguePins>0) {
free(_analogueInputBuffer); size_t analogueBytesNeeded = _numAnaloguePins * 2;
free(_analogueInputStates); if (_analoguePinBytes < analogueBytesNeeded) {
free(_analoguePinMap); // Free any existing buffers and allocate new ones.
if (_analoguePinBytes > 0) {
free(_analogueInputBuffer);
free(_analogueInputStates);
free(_analoguePinMap);
}
_analogueInputStates = (uint8_t*) calloc(analogueBytesNeeded, 1);
_analogueInputBuffer = (uint8_t*) calloc(analogueBytesNeeded, 1);
_analoguePinMap = (uint8_t*) calloc(_numAnaloguePins, 1);
_analoguePinBytes = analogueBytesNeeded;
} }
_analogueInputStates = (uint8_t*) calloc(analogueBytesNeeded, 1);
_analogueInputBuffer = (uint8_t*) calloc(analogueBytesNeeded, 1);
_analoguePinMap = (uint8_t*) calloc(_numAnaloguePins, 1);
_analoguePinBytes = analogueBytesNeeded;
} }
} else { } else {
DIAG(F("EX-IOExpander I2C:%s ERROR configuring device"), _I2CAddress.toString()); DIAG(F("EX-IOExpander I2C:%s ERROR configuring device"), _I2CAddress.toString());
@ -124,8 +126,8 @@ private:
return; return;
} }
} }
// We now need to retrieve the analogue pin map // We now need to retrieve the analogue pin map if there are analogue pins
if (status == I2C_STATUS_OK) { if (status == I2C_STATUS_OK && _numAnaloguePins>0) {
commandBuffer[0] = EXIOINITA; commandBuffer[0] = EXIOINITA;
status = I2CManager.read(_I2CAddress, _analoguePinMap, _numAnaloguePins, commandBuffer, 1); status = I2CManager.read(_I2CAddress, _analoguePinMap, _numAnaloguePins, commandBuffer, 1);
} }
@ -239,7 +241,7 @@ private:
// If we're not doing anything now, check to see if a new input transfer is due. // If we're not doing anything now, check to see if a new input transfer is due.
if (_readState == RDS_IDLE) { if (_readState == RDS_IDLE) {
if (currentMicros - _lastDigitalRead > _digitalRefresh) { // Delay for digital read refresh if (currentMicros - _lastDigitalRead > _digitalRefresh && _numDigitalPins>0) { // Delay for digital read refresh
// Issue new read request for digital states. As the request is non-blocking, the buffer has to // Issue new read request for digital states. As the request is non-blocking, the buffer has to
// be allocated from heap (object state). // be allocated from heap (object state).
_readCommandBuffer[0] = EXIORDD; _readCommandBuffer[0] = EXIORDD;
@ -247,7 +249,7 @@ private:
// non-blocking read // non-blocking read
_lastDigitalRead = currentMicros; _lastDigitalRead = currentMicros;
_readState = RDS_DIGITAL; _readState = RDS_DIGITAL;
} else if (currentMicros - _lastAnalogueRead > _analogueRefresh) { // Delay for analogue read refresh } else if (currentMicros - _lastAnalogueRead > _analogueRefresh && _numAnaloguePins>0) { // Delay for analogue read refresh
// Issue new read for analogue input states // Issue new read for analogue input states
_readCommandBuffer[0] = EXIORDAN; _readCommandBuffer[0] = EXIORDAN;
I2CManager.read(_I2CAddress, _analogueInputBuffer, I2CManager.read(_I2CAddress, _analogueInputBuffer,

View File

@ -489,10 +489,13 @@ std::vector<MotorDriver *>TrackManager::getMainDrivers() {
// Set track power for all tracks with this mode // Set track power for all tracks with this mode
void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermode) { void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermode) {
bool didChange=false;
FOR_EACH_TRACK(t) { FOR_EACH_TRACK(t) {
MotorDriver *driver=track[t]; MotorDriver *driver=track[t];
TRACK_MODE trackmodeOfTrack = driver->getMode(); TRACK_MODE trackmodeOfTrack = driver->getMode();
if (trackmodeToMatch & trackmodeOfTrack) { if (trackmodeToMatch & trackmodeOfTrack) {
if (powermode != driver->getPower())
didChange=true;
if (powermode == POWERMODE::ON) { if (powermode == POWERMODE::ON) {
if (trackmodeOfTrack & TRACK_MODE_DC) { if (trackmodeOfTrack & TRACK_MODE_DC) {
driver->setBrake(true); // DC starts with brake on driver->setBrake(true); // DC starts with brake on
@ -507,12 +510,15 @@ void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermod
driver->setPower(powermode); driver->setPower(powermode);
} }
} }
if (didChange)
CommandDistributor::broadcastPower();
} }
// Set track power for this track, inependent of mode // Set track power for this track, inependent of mode
void TrackManager::setTrackPower(POWERMODE powermode, byte t) { void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
MotorDriver *driver=track[t]; MotorDriver *driver=track[t];
TRACK_MODE trackmode = driver->getMode(); TRACK_MODE trackmode = driver->getMode();
POWERMODE oldpower = driver->getPower();
if (trackmode & TRACK_MODE_NONE) { if (trackmode & TRACK_MODE_NONE) {
driver->setBrake(true); // Track is unused. Brake is good to have. driver->setBrake(true); // Track is unused. Brake is good to have.
powermode = POWERMODE::OFF; // Track is unused. Force it to OFF powermode = POWERMODE::OFF; // Track is unused. Force it to OFF
@ -530,6 +536,8 @@ void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
} }
} }
driver->setPower(powermode); driver->setPower(powermode);
if (oldpower != driver->getPower())
CommandDistributor::broadcastPower();
} }
// returns state of the one and only prog track // returns state of the one and only prog track

View File

@ -150,7 +150,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
*/ */
CommandDistributor::broadcastPower();
} }
#if defined(EXRAIL_ACTIVE) #if defined(EXRAIL_ACTIVE)
else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate
@ -496,7 +495,6 @@ void WiThrottle::getLocoCallback(int16_t locoid) {
TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away
DIAG(F("LocoCallback commit success")); DIAG(F("LocoCallback commit success"));
stashStream->commit(); stashStream->commit();
CommandDistributor::broadcastPower();
} }
void WiThrottle::sendIntro(Print* stream) { void WiThrottle::sendIntro(Print* stream) {

View File

@ -3,7 +3,10 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.2.14" #define VERSION "5.2.16"
// 5.2.16 - Bugfix to allow for devices using the EX-IOExpander protocol to have no analogue or no digital pins
// 5.2.15 - move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions
// - add repeats to function packets that are not reminded in accordance with accessory packets
// 5.2.14 - Reminder window DCC packet optimization // 5.2.14 - Reminder window DCC packet optimization
// - Optional #define DISABLE_FUNCTION_REMINDERS // - Optional #define DISABLE_FUNCTION_REMINDERS
// 5.2.13 - EXRAIL STEALTH // 5.2.13 - EXRAIL STEALTH