mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
DC frequency fix bit shifting (debug code) step #4
This commit is contained in:
parent
bf17f2018b
commit
ba0a41b6f2
17
DCC.cpp
17
DCC.cpp
|
@ -153,12 +153,14 @@ uint8_t DCC::getThrottleSpeedByte(int cab) {
|
||||||
return speedTable[reg].speedCode;
|
return speedTable[reg].speedCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns -1 for fault, 0 to 3 for frequency
|
// returns 0 to 3 for frequency
|
||||||
int8_t DCC::getThrottleFrequency(int cab) {
|
uint8_t DCC::getThrottleFrequency(int cab) {
|
||||||
int reg=lookupSpeedTable(cab);
|
int reg=lookupSpeedTable(cab);
|
||||||
if (reg<0)
|
if (reg<0)
|
||||||
return -1;
|
return 0; // use default frequency
|
||||||
return (int8_t)(speedTable[reg].functions >>29); // shift out first 29 bits so we have the "frequency bits" left
|
uint8_t res = (uint8_t)(speedTable[reg].functions >>30);
|
||||||
|
DIAG(F("Speed table %d functions %l shifted %d"), reg, speedTable[reg].functions, res);
|
||||||
|
return res; // shift out first 29 bits so we have the "frequency bits" left
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns direction on loco
|
// returns direction on loco
|
||||||
|
@ -191,8 +193,11 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||||
b[nB++] = functionNumber >>7 ; // high order bits
|
b[nB++] = functionNumber >>7 ; // high order bits
|
||||||
}
|
}
|
||||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
// We use the reminder table up to 28 for normal functions.
|
||||||
|
// We use 29 to 31 for DC frequency as well.
|
||||||
|
if (functionNumber > 31)
|
||||||
|
return true;
|
||||||
|
|
||||||
int reg = lookupSpeedTable(cab);
|
int reg = lookupSpeedTable(cab);
|
||||||
if (reg<0) return false;
|
if (reg<0) return false;
|
||||||
|
@ -206,7 +211,7 @@ 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) {
|
if (speedTable[reg].functions != previous && functionNumber > 28) {
|
||||||
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||||
CommandDistributor::broadcastLoco(reg);
|
CommandDistributor::broadcastLoco(reg);
|
||||||
}
|
}
|
||||||
|
|
2
DCC.h
2
DCC.h
|
@ -61,7 +61,7 @@ public:
|
||||||
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
|
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||||
static int8_t getThrottleSpeed(int cab);
|
static int8_t getThrottleSpeed(int cab);
|
||||||
static uint8_t getThrottleSpeedByte(int cab);
|
static uint8_t getThrottleSpeedByte(int cab);
|
||||||
static int8_t getThrottleFrequency(int cab);
|
static uint8_t getThrottleFrequency(int cab);
|
||||||
static bool getThrottleDirection(int cab);
|
static bool getThrottleDirection(int cab);
|
||||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
||||||
|
|
|
@ -142,9 +142,9 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
|
||||||
if (pin == 9 || pin == 10) { // timer 2 is different
|
if (pin == 9 || pin == 10) { // timer 2 is different
|
||||||
|
|
||||||
if (fbits >= 3)
|
if (fbits >= 3)
|
||||||
abits = B11;
|
abits = B00000011;
|
||||||
else
|
else
|
||||||
abits = B01;
|
abits = B00000001;
|
||||||
|
|
||||||
if (fbits >= 3)
|
if (fbits >= 3)
|
||||||
bbits = B0001;
|
bbits = B0001;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-202312251647Z"
|
#define GITHUB_SHA "devel-202312310824Z"
|
||||||
|
|
|
@ -349,6 +349,7 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
DIAG(F("Brake %d freqencybits %x"), 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
|
||||||
|
|
|
@ -202,7 +202,7 @@ void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
|
||||||
FOR_EACH_TRACK(t) {
|
FOR_EACH_TRACK(t) {
|
||||||
if (trackDCAddr[t]!=cab && cab != 0) continue;
|
if (trackDCAddr[t]!=cab && cab != 0) continue;
|
||||||
if (track[t]->getMode() & TRACK_MODE_DC)
|
if (track[t]->getMode() & TRACK_MODE_DC)
|
||||||
track[t]->setDCSignal(speedbyte);
|
track[t]->setDCSignal(speedbyte, DCC::getThrottleFrequency(trackDCAddr[t]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,11 +348,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackManager::applyDCSpeed(byte t) {
|
void TrackManager::applyDCSpeed(byte t) {
|
||||||
int8_t frequency = DCC::getThrottleFrequency(trackDCAddr[t]);
|
track[t]->setDCSignal(DCC::getThrottleSpeedByte(trackDCAddr[t]),
|
||||||
if (frequency <0) // loco was not found
|
DCC::getThrottleFrequency(trackDCAddr[t]));
|
||||||
frequency = 0; // default
|
|
||||||
uint8_t speedByte = DCC::getThrottleSpeedByte(trackDCAddr[t]);
|
|
||||||
track[t]->setDCSignal(speedByte, (uint8_t)frequency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
|
bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user