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

Merge branch 'master' into wifi-reliability2

This commit is contained in:
Asbelos 2020-10-20 12:31:52 +01:00
commit 742f10bf0a
5 changed files with 39 additions and 23 deletions

View File

@ -465,15 +465,15 @@ 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)); setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4)); // 100D DDDD
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)); setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F)); // 1011 DDDD
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)); setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F)); // 1010 DDDD
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)

View File

@ -47,6 +47,7 @@ const int HASH_KEYWORD_DCC = 6436;
const int HASH_KEYWORD_SLOW = -17209; const int HASH_KEYWORD_SLOW = -17209;
const int HASH_KEYWORD_PROGBOOST = -6353; const int HASH_KEYWORD_PROGBOOST = -6353;
const int HASH_KEYWORD_EEPROM = -7168; const int HASH_KEYWORD_EEPROM = -7168;
const int HASH_KEYWORD_LIMIT = 27413;
int DCCEXParser::stashP[MAX_PARAMS]; int DCCEXParser::stashP[MAX_PARAMS];
bool DCCEXParser::stashBusy; bool DCCEXParser::stashBusy;
@ -465,19 +466,19 @@ bool DCCEXParser::parsef(Print *stream, int params, int p[])
// convenient for other processing // convenient for other processing
if (params == 2) if (params == 2)
{ {
byte groupcode = p[1] & 0xE0; byte instructionField = p[1] & 0xE0; // 1110 0000
if (groupcode == 0x80) if (instructionField == 0x80) // 1000 0000 Function group 1
{ {
// Shuffle bits from order F0 F4 F3 F2 F1 to F4 F3 F2 F1 F0
byte normalized = (p[1] << 1 & 0x1e) | (p[1] >> 4 & 0x01); byte normalized = (p[1] << 1 & 0x1e) | (p[1] >> 4 & 0x01);
funcmap(p[0], normalized, 0, 4); funcmap(p[0], normalized, 0, 4);
} }
else if (groupcode == 0xC0) else if (instructionField == 0xA0) // 1010 0000 Function group 2
{ {
funcmap(p[0], p[1], 5, 8); if (p[1] & 0x10) // 0001 0000 Bit selects F5toF8 / F9toF12
} funcmap(p[0], p[1], 5, 8);
else if (groupcode == 0xA0) else
{ funcmap(p[0], p[1], 9, 12);
funcmap(p[0], p[1], 9, 12);
} }
} }
if (params == 3) if (params == 3)
@ -586,7 +587,11 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[])
break; break;
case HASH_KEYWORD_ACK: // <D ACK ON/OFF> case HASH_KEYWORD_ACK: // <D ACK ON/OFF>
Diag::ACK = onOff; if (params >= 2 && p[1] == HASH_KEYWORD_LIMIT) {
DCCWaveform::progTrack.setAckLimit(p[2]);
StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]);
} else
Diag::ACK = onOff;
return true; return true;
case HASH_KEYWORD_CMD: // <D CMD ON/OFF> case HASH_KEYWORD_CMD: // <D CMD ON/OFF>

View File

@ -128,7 +128,7 @@ void DCCWaveform::checkPowerOverload() {
if (millis() - lastSampleTaken < sampleDelay) return; if (millis() - lastSampleTaken < sampleDelay) return;
lastSampleTaken = millis(); lastSampleTaken = millis();
int tripValue= motorDriver->rawCurrentTripValue; int tripValue= motorDriver->getRawCurrentTripValue();
if (!isMainTrack && !ackPending && !progTrackSyncMain && !progTrackBoosted) if (!isMainTrack && !ackPending && !progTrackSyncMain && !progTrackBoosted)
tripValue=progTripValue; tripValue=progTripValue;
@ -293,8 +293,11 @@ int DCCWaveform::getLastCurrent() {
void DCCWaveform::setAckBaseline() { void DCCWaveform::setAckBaseline() {
if (isMainTrack) return; if (isMainTrack) return;
ackThreshold=motorDriver->getCurrentRaw() + (int)(65 / motorDriver->senseFactor); int baseline = motorDriver->getCurrentRaw();
if (Diag::ACK) DIAG(F("\nACK-BASELINE %d/%dmA"),ackThreshold,motorDriver->raw2mA(ackThreshold)); ackThreshold= baseline + motorDriver->mA2raw(ackLimitmA);
if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA threshold=%d/%dmA"),
baseline,motorDriver->raw2mA(baseline),
ackThreshold,motorDriver->raw2mA(ackThreshold));
} }
void DCCWaveform::setAckPending() { void DCCWaveform::setAckPending() {

View File

@ -76,6 +76,9 @@ class DCCWaveform {
autoPowerOff=false; autoPowerOff=false;
} }
}; };
inline void setAckLimit(int mA) {
ackLimitmA = mA;
}
private: private:
static VirtualTimer * interruptTimer; static VirtualTimer * interruptTimer;
@ -115,9 +118,10 @@ class DCCWaveform {
unsigned int power_good_counter = 0; unsigned int power_good_counter = 0;
// ACK management (Prog track only) // ACK management (Prog track only)
bool ackPending; volatile bool ackPending;
bool ackDetected; volatile bool ackDetected;
int ackThreshold; int ackThreshold;
int ackLimitmA = 60;
int ackMaxCurrent; int ackMaxCurrent;
unsigned long ackCheckStart; // millis unsigned long ackCheckStart; // millis
unsigned int ackCheckDuration; // millis unsigned int ackCheckDuration; // millis

View File

@ -29,12 +29,16 @@ class MotorDriver {
virtual int getCurrentRaw(); virtual int getCurrentRaw();
virtual unsigned int raw2mA( int raw); virtual unsigned int raw2mA( int raw);
virtual int mA2raw( unsigned int mA); virtual int mA2raw( unsigned int mA);
inline int getRawCurrentTripValue() {
return rawCurrentTripValue;
}
private:
byte powerPin, signalPin, signalPin2, brakePin,currentPin,faultPin; byte powerPin, signalPin, signalPin2, brakePin,currentPin,faultPin;
float senseFactor; float senseFactor;
unsigned int tripMilliamps; unsigned int tripMilliamps;
int rawCurrentTripValue; int rawCurrentTripValue;
const byte UNUSED_PIN = 255; const byte UNUSED_PIN = 255;
}; };
#endif #endif