mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-17 06:29:15 +01:00
tidying, join and cmd
This commit is contained in:
parent
7e58165db9
commit
4391b049d8
@ -32,7 +32,7 @@
|
|||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
// These keywords are used in the <1> command. The number is what you get if you use the keyword as a parameter.
|
// These keywords are used in various commands. The number is what you get if you use the keyword as a parameter.
|
||||||
// To discover new keyword numbers , use the <$ YOURKEYWORD> command
|
// To discover new keyword numbers , use the <$ YOURKEYWORD> command
|
||||||
const int16_t HASH_KEYWORD_PROG = -29718;
|
const int16_t HASH_KEYWORD_PROG = -29718;
|
||||||
const int16_t HASH_KEYWORD_MAIN = 11339;
|
const int16_t HASH_KEYWORD_MAIN = 11339;
|
||||||
@ -56,6 +56,7 @@ const int16_t HASH_KEYWORD_LCN = 15137;
|
|||||||
const int16_t HASH_KEYWORD_RESET = 26133;
|
const int16_t HASH_KEYWORD_RESET = 26133;
|
||||||
const int16_t HASH_KEYWORD_SPEED28 = -17064;
|
const int16_t HASH_KEYWORD_SPEED28 = -17064;
|
||||||
const int16_t HASH_KEYWORD_SPEED128 = 25816;
|
const int16_t HASH_KEYWORD_SPEED128 = 25816;
|
||||||
|
const int16_t HASH_KEYWORD_RAILCOM = 29097;
|
||||||
|
|
||||||
int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS];
|
int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS];
|
||||||
bool DCCEXParser::stashBusy;
|
bool DCCEXParser::stashBusy;
|
||||||
@ -776,6 +777,9 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
|
|||||||
Diag::LCN = onOff;
|
Diag::LCN = onOff;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case HASH_KEYWORD_RAILCOM: // <D RAILCOM ON/OFF>
|
||||||
|
return DCCWaveform::setUseRailcom(onOff);
|
||||||
|
|
||||||
case HASH_KEYWORD_PROGBOOST:
|
case HASH_KEYWORD_PROGBOOST:
|
||||||
DCC::setProgTrackBoost(true);
|
DCC::setProgTrackBoost(true);
|
||||||
return true;
|
return true;
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||||
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
||||||
|
|
||||||
|
bool DCCWaveform::useRailcom=false;
|
||||||
|
bool DCCWaveform::supportsRailcom=false;
|
||||||
bool DCCWaveform::progTrackSyncMain=false;
|
bool DCCWaveform::progTrackSyncMain=false;
|
||||||
bool DCCWaveform::progTrackBoosted=false;
|
bool DCCWaveform::progTrackBoosted=false;
|
||||||
int DCCWaveform::progTripValue=0;
|
int DCCWaveform::progTripValue=0;
|
||||||
@ -46,11 +48,15 @@ void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver) {
|
|||||||
&& (mainDriver->getFaultPin() != UNUSED_PIN));
|
&& (mainDriver->getFaultPin() != UNUSED_PIN));
|
||||||
// Only use PWM if both pins are PWM capable. Otherwise JOIN does not work
|
// Only use PWM if both pins are PWM capable. Otherwise JOIN does not work
|
||||||
MotorDriver::usePWM= mainDriver->isPWMCapable() && progDriver->isPWMCapable();
|
MotorDriver::usePWM= mainDriver->isPWMCapable() && progDriver->isPWMCapable();
|
||||||
MotorDriver::useRailcom= MotorDriver::usePWM && mainDriver->isRailcomCapable() && progDriver->isRailcomCapable();
|
supportsRailcom= MotorDriver::usePWM && mainDriver->isRailcomCapable() && progDriver->isRailcomCapable();
|
||||||
|
|
||||||
|
// supportsRailcom depends on hardware caopability
|
||||||
|
// useRailcom is user switchable at run time.
|
||||||
|
useRailcom=supportsRailcom;
|
||||||
|
|
||||||
if (MotorDriver::usePWM){
|
if (MotorDriver::usePWM){
|
||||||
DIAG(F("Signal pin config: high accuracy waveform"));
|
DIAG(F("Signal pin config: high accuracy waveform"));
|
||||||
if (MotorDriver::useRailcom) DIAG(F("Railcom Enabled"));
|
if (supportsRailcom) DIAG(F("Railcom cutout enabled"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DIAG(F("Signal pin config: normal accuracy waveform"));
|
DIAG(F("Signal pin config: normal accuracy waveform"));
|
||||||
@ -120,6 +126,16 @@ void DCCWaveform::setPowerMode(POWERMODE mode) {
|
|||||||
motorDriver->setPower( ison);
|
motorDriver->setPower( ison);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DCCWaveform::setUseRailcom(bool on) {
|
||||||
|
if (!supportsRailcom) return false;
|
||||||
|
useRailcom=on;
|
||||||
|
if (!on) {
|
||||||
|
// turn off any existing cutout
|
||||||
|
mainTrack.motorDriver->setRailcomCutout(false);
|
||||||
|
progTrack.motorDriver->setRailcomCutout(false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DCCWaveform::checkPowerOverload(bool ackManagerActive) {
|
void DCCWaveform::checkPowerOverload(bool ackManagerActive) {
|
||||||
if (millis() - lastSampleTaken < sampleDelay) return;
|
if (millis() - lastSampleTaken < sampleDelay) return;
|
||||||
@ -209,13 +225,20 @@ void DCCWaveform::interrupt2() {
|
|||||||
if (remainingPreambles > 0 ) {
|
if (remainingPreambles > 0 ) {
|
||||||
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
||||||
remainingPreambles--;
|
remainingPreambles--;
|
||||||
// Railcom cutout
|
|
||||||
if (remainingPreambles==(requiredPreambles-2)) motorDriver->setRailcomCutout(true);
|
// Railcom cutout processing but not on prog if synced with main
|
||||||
else if (remainingPreambles==(requiredPreambles-4)) motorDriver->setRailcomCutout(false);
|
if (useRailcom && (isMainTrack || !progTrackSyncMain)) do {
|
||||||
|
bool cutout;
|
||||||
|
if (remainingPreambles==(requiredPreambles-2)) cutout=true;
|
||||||
|
else if (remainingPreambles==(requiredPreambles-6)) cutout=false;
|
||||||
|
else break;
|
||||||
|
motorDriver->setRailcomCutout(cutout);
|
||||||
|
if (progTrackSyncMain) progTrack.motorDriver->setRailcomCutout(cutout);
|
||||||
|
} while(false); // this is to allow break out of do {...} above
|
||||||
|
|
||||||
// Update free memory diagnostic as we don't have anything else to do this time.
|
// Update free memory diagnostic as we don't have anything else to do this time.
|
||||||
// Allow for checkAck and its called functions using 22 bytes more.
|
// Allow for checkAck and its called functions using 22 bytes more.
|
||||||
else updateMinimumFreeMemory(22);
|
updateMinimumFreeMemory(22);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +53,14 @@ class DCCWaveform {
|
|||||||
static void loop(bool ackManagerActive);
|
static void loop(bool ackManagerActive);
|
||||||
static DCCWaveform mainTrack;
|
static DCCWaveform mainTrack;
|
||||||
static DCCWaveform progTrack;
|
static DCCWaveform progTrack;
|
||||||
|
static bool supportsRailcom;
|
||||||
|
static bool useRailcom;
|
||||||
|
|
||||||
void beginTrack();
|
void beginTrack();
|
||||||
void setPowerMode(POWERMODE);
|
void setPowerMode(POWERMODE);
|
||||||
POWERMODE getPowerMode();
|
POWERMODE getPowerMode();
|
||||||
|
static bool setUseRailcom(bool on);
|
||||||
|
|
||||||
void checkPowerOverload(bool ackManagerActive);
|
void checkPowerOverload(bool ackManagerActive);
|
||||||
inline int get1024Current() {
|
inline int get1024Current() {
|
||||||
if (powerMode == POWERMODE::ON)
|
if (powerMode == POWERMODE::ON)
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
#define isLOW(fastpin) (!isHIGH(fastpin))
|
#define isLOW(fastpin) (!isHIGH(fastpin))
|
||||||
|
|
||||||
bool MotorDriver::usePWM=false;
|
bool MotorDriver::usePWM=false;
|
||||||
bool MotorDriver::useRailcom=false;
|
|
||||||
|
|
||||||
bool MotorDriver::commonFaultPin=false;
|
bool MotorDriver::commonFaultPin=false;
|
||||||
|
|
||||||
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
||||||
@ -117,7 +115,7 @@ void MotorDriver::setBrake(bool on) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setRailcomCutout(bool on) {
|
void MotorDriver::setRailcomCutout(bool on) {
|
||||||
if (useRailcom) DCCTimer::setPWM(brakePin,on);
|
DCCTimer::setPWM(brakePin,on);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setSignal( bool high) {
|
void MotorDriver::setSignal( bool high) {
|
||||||
|
@ -58,7 +58,6 @@ class MotorDriver {
|
|||||||
bool canMeasureCurrent();
|
bool canMeasureCurrent();
|
||||||
void setRailcomCutout(bool on);
|
void setRailcomCutout(bool on);
|
||||||
static bool usePWM;
|
static bool usePWM;
|
||||||
static bool useRailcom;
|
|
||||||
static bool commonFaultPin; // This is a stupid motor shield which has only a common fault pin for both outputs
|
static bool commonFaultPin; // This is a stupid motor shield which has only a common fault pin for both outputs
|
||||||
inline byte getFaultPin() {
|
inline byte getFaultPin() {
|
||||||
return faultPin;
|
return faultPin;
|
||||||
|
Loading…
Reference in New Issue
Block a user