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

Compare commits

..

No commits in common. "6f076720f74acbe9d26c8939959a2c21574eb593" and "19efa749b8c5e7b00e63ee9fe6ca7daa32c5f36f" have entirely different histories.

8 changed files with 19 additions and 28 deletions

View File

@ -209,9 +209,7 @@ int16_t CommandDistributor::retClockTime() {
void CommandDistributor::broadcastLoco(byte slot) { void CommandDistributor::broadcastLoco(byte slot) {
DCC::LOCO * sp=&DCC::speedTable[slot]; DCC::LOCO * sp=&DCC::speedTable[slot];
uint32_t func = sp->functions; broadcastReply(COMMAND_TYPE, F("<l %d %d %d %l>\n"), sp->loco,slot,sp->speedCode,sp->functions);
func = func & 0x1fffffff; // mask out bits 0-28
broadcastReply(COMMAND_TYPE, F("<l %d %d %d %l>\n"), sp->loco,slot,sp->speedCode,func);
#ifdef SABERTOOTH #ifdef SABERTOOTH
if (Serial2 && sp->loco == SABERTOOTH) { if (Serial2 && sp->loco == SABERTOOTH) {
static uint8_t rampingmode = 0; static uint8_t rampingmode = 0;

26
DCC.cpp
View File

@ -163,8 +163,8 @@ uint8_t DCC::getThrottleFrequency(int cab) {
if (reg<0) if (reg<0)
return 0; // use default frequency return 0; // use default frequency
uint8_t res = (uint8_t)(speedTable[reg].functions >>30); uint8_t res = (uint8_t)(speedTable[reg].functions >>30);
//DIAG(F("Speed table %d functions %l shifted %d"), reg, speedTable[reg].functions, res); DIAG(F("Speed table %d functions %l shifted %d"), reg, speedTable[reg].functions, res);
return res; // shift out first 30 bits so we have the "frequency bits" left return res; // shift out first 29 bits so we have the "frequency bits" left
#endif #endif
} }
@ -216,34 +216,28 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
} else { } else {
speedTable[reg].functions &= ~funcmask; speedTable[reg].functions &= ~funcmask;
} }
if (speedTable[reg].functions != previous && functionNumber <= 28) { if (speedTable[reg].functions != previous && functionNumber > 28) {
updateGroupflags(speedTable[reg].groupFlags, functionNumber); updateGroupflags(speedTable[reg].groupFlags, functionNumber);
CommandDistributor::broadcastLoco(reg); CommandDistributor::broadcastLoco(reg);
} }
return true; return true;
} }
// Flip function state (used from withrottle protocol) // Flip function state
void DCC::changeFn( int cab, int16_t functionNumber) { void DCC::changeFn( int cab, int16_t functionNumber) {
if (cab<=0 || functionNumber>31) return; if (cab<=0 || functionNumber>28) return;
int reg = lookupSpeedTable(cab); int reg = lookupSpeedTable(cab);
if (reg<0) return; if (reg<0) return;
unsigned long funcmask = (1UL<<functionNumber); unsigned long funcmask = (1UL<<functionNumber);
speedTable[reg].functions ^= funcmask; speedTable[reg].functions ^= funcmask;
if (functionNumber <= 28) { updateGroupflags(speedTable[reg].groupFlags, functionNumber);
updateGroupflags(speedTable[reg].groupFlags, functionNumber); CommandDistributor::broadcastLoco(reg);
CommandDistributor::broadcastLoco(reg);
}
} }
// Report function state (used from withrottle protocol) int DCC::getFn( int cab, int16_t functionNumber) {
// returns 0 false, 1 true or -1 for do not know if (cab<=0 || functionNumber>28) return -1; // unknown
int8_t DCC::getFn( int cab, int16_t functionNumber) {
if (cab<=0 || functionNumber>28)
return -1; // unknown
int reg = lookupSpeedTable(cab); int reg = lookupSpeedTable(cab);
if (reg<0) if (reg<0) return -1;
return -1;
unsigned long funcmask = (1UL<<functionNumber); unsigned long funcmask = (1UL<<functionNumber);
return (speedTable[reg].functions & funcmask)? 1 : 0; return (speedTable[reg].functions & funcmask)? 1 : 0;

2
DCC.h
View File

@ -68,7 +68,7 @@ public:
static void setFunction(int cab, byte fByte, byte eByte); static void setFunction(int cab, byte fByte, byte eByte);
static bool setFn(int cab, int16_t functionNumber, bool on); static bool setFn(int cab, int16_t functionNumber, bool on);
static void changeFn(int cab, int16_t functionNumber); static void changeFn(int cab, int16_t functionNumber);
static int8_t getFn(int cab, int16_t functionNumber); static int getFn(int cab, int16_t functionNumber);
static uint32_t getFunctionMap(int cab); static uint32_t getFunctionMap(int cab);
static void updateGroupflags(byte &flags, int16_t functionNumber); static void updateGroupflags(byte &flags, int16_t functionNumber);
static void setAccessory(int address, byte port, bool gate, byte onoff = 2); static void setAccessory(int address, byte port, bool gate, byte onoff = 2);

View File

@ -157,7 +157,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
TCCR2A = (TCCR2A & B11111100) | abits; // set WGM0 and WGM1 TCCR2A = (TCCR2A & B11111100) | abits; // set WGM0 and WGM1
TCCR2B = (TCCR2B & B11110000) | bbits; // set WGM2 and 3 bits of prescaler TCCR2B = (TCCR2B & B11110000) | bbits; // set WGM2 and 3 bits of prescaler
//DIAG(F("Timer 2 A=%x B=%x"), TCCR2A, TCCR2B); DIAG(F("Timer 2 A=%x B=%x"), TCCR2A, TCCR2B);
} else { // not timer 9 or 10 } else { // not timer 9 or 10
abits = B01; abits = B01;
@ -179,7 +179,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
// Timer4 // Timer4
TCCR4A = (TCCR4A & B11111100) | abits; // set WGM0 and WGM1 TCCR4A = (TCCR4A & B11111100) | abits; // set WGM0 and WGM1
TCCR4B = (TCCR4B & B11100000) | bbits; // set WGM2 and WGM3 and divisor TCCR4B = (TCCR4B & B11100000) | bbits; // set WGM2 and WGM3 and divisor
//DIAG(F("Timer 4 A=%x B=%x"), TCCR4A, TCCR4B); DIAG(F("Timer 4 A=%x B=%x"), TCCR4A, TCCR4B);
break; break;
case 46: case 46:
case 45: case 45:
@ -187,7 +187,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
// Timer5 // Timer5
TCCR5A = (TCCR5A & B11111100) | abits; // set WGM0 and WGM1 TCCR5A = (TCCR5A & B11111100) | abits; // set WGM0 and WGM1
TCCR5B = (TCCR5B & B11100000) | bbits; // set WGM2 and WGM3 and divisor TCCR5B = (TCCR5B & B11100000) | bbits; // set WGM2 and WGM3 and divisor
//DIAG(F("Timer 5 A=%x B=%x"), TCCR5A, TCCR5B); DIAG(F("Timer 5 A=%x B=%x"), TCCR5A, TCCR5B);
break; break;
default: default:
break; break;

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202401012116Z" #define GITHUB_SHA "devel-202312310824Z"

View File

@ -349,7 +349,7 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
} }
} }
#endif #endif
//DIAG(F("Brake pin %d freqency %d"), brakePin, f); DIAG(F("Brake %d freqency %d"), brakePin, f);
DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency to 100Hz XXX May move to setup DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency to 100Hz XXX May move to setup
DCCTimer::DCCEXanalogWrite(brakePin,brake); DCCTimer::DCCEXanalogWrite(brakePin,brake);
#else // all AVR here #else // all AVR here

View File

@ -618,7 +618,7 @@ void WiThrottle::sendFunctions(Print* stream, byte loco) {
#endif #endif
for(int fKey=0; fKey<fkeys; fKey++) { for(int fKey=0; fKey<fkeys; fKey++) {
int8_t fstate=DCC::getFn(locoid,fKey); int fstate=DCC::getFn(locoid,fKey);
if (fstate>=0) StringFormatter::send(stream,F("M%cA%c%d<;>F%d%d\n"),myLocos[loco].throttle,LorS(locoid),locoid,fstate,fKey); if (fstate>=0) StringFormatter::send(stream,F("M%cA%c%d<;>F%d%d\n"),myLocos[loco].throttle,LorS(locoid),locoid,fstate,fKey);
} }
} }

View File

@ -3,8 +3,7 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.2.XX" #define VERSION "5.2.17"
// 5.2.XX - Variable frequency for DC mode
// 5.2.17 - ESP32 simplify network logic // 5.2.17 - ESP32 simplify network logic
// 5.2.16 - Bugfix to allow for devices using the EX-IOExpander protocol to have no analogue or no digital pins // 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 // 5.2.15 - move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions