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

update devel-cam76 with changes from devel note default_env

update devel-cam76 with changes from devel.  uno, nano, unowifir2 removed due to memory size.
there are other warnings which should be addressed
This commit is contained in:
Ash-4 2024-09-10 11:14:05 -05:00 committed by GitHub
commit 7421851c53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 825 additions and 407 deletions

View File

@ -37,7 +37,7 @@ int16_t lastclocktime;
int8_t lastclockrate; int8_t lastclockrate;
#if WIFI_ON || ETHERNET_ON || defined(SERIAL1_COMMANDS) || defined(SERIAL2_COMMANDS) || defined(SERIAL3_COMMANDS) #if WIFI_ON || ETHERNET_ON || defined(SERIAL1_COMMANDS) || defined(SERIAL2_COMMANDS) || defined(SERIAL3_COMMANDS) || defined(SERIAL4_COMMANDS) || defined(SERIAL5_COMMANDS) || defined(SERIAL6_COMMANDS)
// use a buffer to allow broadcast // use a buffer to allow broadcast
StringBuffer * CommandDistributor::broadcastBufferWriter=new StringBuffer(); StringBuffer * CommandDistributor::broadcastBufferWriter=new StringBuffer();
template<typename... Targs> void CommandDistributor::broadcastReply(clientType type, Targs... msg){ template<typename... Targs> void CommandDistributor::broadcastReply(clientType type, Targs... msg){
@ -248,6 +248,10 @@ void CommandDistributor::broadcastLoco(byte slot) {
#endif #endif
} }
void CommandDistributor::broadcastForgetLoco(int16_t loco) {
broadcastReply(COMMAND_TYPE, F("<l %d 0 1 0>\n<- %d>\n"), loco,loco);
}
void CommandDistributor::broadcastPower() { void CommandDistributor::broadcastPower() {
char pstr[] = "? x"; char pstr[] = "? x";
for(byte t=0; t<TrackManager::MAX_TRACKS; t++) for(byte t=0; t<TrackManager::MAX_TRACKS; t++)

View File

@ -47,6 +47,7 @@ private:
public : public :
static void parse(byte clientId,byte* buffer, RingStream * ring); static void parse(byte clientId,byte* buffer, RingStream * ring);
static void broadcastLoco(byte slot); static void broadcastLoco(byte slot);
static void broadcastForgetLoco(int16_t loco);
static void broadcastSensor(int16_t id, bool value); static void broadcastSensor(int16_t id, bool value);
static void broadcastTurnout(int16_t id, bool isClosed); static void broadcastTurnout(int16_t id, bool isClosed);
static void broadcastTurntable(int16_t id, uint8_t position, bool moving); static void broadcastTurntable(int16_t id, uint8_t position, bool moving);

20
DCC.cpp
View File

@ -271,6 +271,20 @@ uint32_t DCC::getFunctionMap(int cab) {
return (reg<0)?0:speedTable[reg].functions; return (reg<0)?0:speedTable[reg].functions;
} }
// saves DC frequency (0..3) in spare functions 29,30,31
void DCC::setDCFreq(int cab,byte freq) {
if (cab==0 || freq>3) return;
auto reg=lookupSpeedTable(cab,true);
// drop and replace F29,30,31 (top 3 bits)
auto newFunctions=speedTable[reg].functions & 0x1FFFFFFFUL;
if (freq==1) newFunctions |= (1UL<<29); // F29
else if (freq==2) newFunctions |= (1UL<<30); // F30
else if (freq==3) newFunctions |= (1UL<<31); // F31
if (newFunctions==speedTable[reg].functions) return; // no change
speedTable[reg].functions=newFunctions;
CommandDistributor::broadcastLoco(reg);
}
void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) { void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) {
// onoff is tristate: // onoff is tristate:
// 0 => send off packet // 0 => send off packet
@ -728,11 +742,15 @@ void DCC::forgetLoco(int cab) { // removes any speed reminders for this loco
if (reg>=0) { if (reg>=0) {
speedTable[reg].loco=0; speedTable[reg].loco=0;
setThrottle2(cab,1); // ESTOP if this loco still on track setThrottle2(cab,1); // ESTOP if this loco still on track
CommandDistributor::broadcastForgetLoco(cab);
} }
} }
void DCC::forgetAllLocos() { // removes all speed reminders void DCC::forgetAllLocos() { // removes all speed reminders
setThrottle2(0,1); // ESTOP all locos still on track setThrottle2(0,1); // ESTOP all locos still on track
for (int i=0;i<MAX_LOCOS;i++) speedTable[i].loco=0; for (int i=0;i<MAX_LOCOS;i++) {
if (speedTable[i].loco) CommandDistributor::broadcastForgetLoco(speedTable[i].loco);
speedTable[i].loco=0;
}
} }
byte DCC::loopStatus=0; byte DCC::loopStatus=0;

1
DCC.h
View File

@ -70,6 +70,7 @@ public:
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 int8_t getFn(int cab, int16_t functionNumber);
static uint32_t getFunctionMap(int cab); static uint32_t getFunctionMap(int cab);
static void setDCFreq(int cab,byte freq);
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);
static bool setExtendedAccessory(int16_t address, int16_t value, byte repeats=3); static bool setExtendedAccessory(int16_t address, int16_t value, byte repeats=3);

View File

@ -27,8 +27,8 @@
#include "DCCWaveform.h" #include "DCCWaveform.h"
#include "TrackManager.h" #include "TrackManager.h"
unsigned int DCCACK::minAckPulseDuration = 2000; // micros unsigned long DCCACK::minAckPulseDuration = 2000; // micros
unsigned int DCCACK::maxAckPulseDuration = 20000; // micros unsigned long DCCACK::maxAckPulseDuration = 20000; // micros
MotorDriver * DCCACK::progDriver=NULL; MotorDriver * DCCACK::progDriver=NULL;
ackOp const * DCCACK::ackManagerProg; ackOp const * DCCACK::ackManagerProg;
@ -50,8 +50,8 @@ volatile uint8_t DCCACK::numAckSamples=0;
uint8_t DCCACK::trailingEdgeCounter=0; uint8_t DCCACK::trailingEdgeCounter=0;
unsigned int DCCACK::ackPulseDuration; // micros unsigned long DCCACK::ackPulseDuration; // micros
unsigned long DCCACK::ackPulseStart; // micros unsigned long DCCACK::ackPulseStart; // micros
volatile bool DCCACK::ackDetected; volatile bool DCCACK::ackDetected;
unsigned long DCCACK::ackCheckStart; // millis unsigned long DCCACK::ackCheckStart; // millis
volatile bool DCCACK::ackPending; volatile bool DCCACK::ackPending;
@ -127,7 +127,7 @@ bool DCCACK::checkResets(uint8_t numResets) {
void DCCACK::setAckBaseline() { void DCCACK::setAckBaseline() {
int baseline=progDriver->getCurrentRaw(); int baseline=progDriver->getCurrentRaw();
ackThreshold= baseline + progDriver->mA2raw(ackLimitmA); ackThreshold= baseline + progDriver->mA2raw(ackLimitmA);
if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"), if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %lus and %lus"),
baseline,progDriver->raw2mA(baseline), baseline,progDriver->raw2mA(baseline),
ackThreshold,progDriver->raw2mA(ackThreshold), ackThreshold,progDriver->raw2mA(ackThreshold),
minAckPulseDuration, maxAckPulseDuration); minAckPulseDuration, maxAckPulseDuration);
@ -146,7 +146,7 @@ void DCCACK::setAckPending() {
byte DCCACK::getAck() { byte DCCACK::getAck() {
if (ackPending) return (2); // still waiting if (ackPending) return (2); // still waiting
if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%uuS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration, if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%luS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration,
ackMaxCurrent,progDriver->raw2mA(ackMaxCurrent), ackPulseDuration, numAckSamples, numAckGaps); ackMaxCurrent,progDriver->raw2mA(ackMaxCurrent), ackPulseDuration, numAckSamples, numAckGaps);
if (ackDetected) return (1); // Yes we had an ack if (ackDetected) return (1); // Yes we had an ack
return(0); // pending set off but not detected means no ACK. return(0); // pending set off but not detected means no ACK.

View File

@ -79,10 +79,10 @@ class DCCACK {
static inline void setAckLimit(int mA) { static inline void setAckLimit(int mA) {
ackLimitmA = mA; ackLimitmA = mA;
} }
static inline void setMinAckPulseDuration(unsigned int i) { static inline void setMinAckPulseDuration(unsigned long i) {
minAckPulseDuration = i; minAckPulseDuration = i;
} }
static inline void setMaxAckPulseDuration(unsigned int i) { static inline void setMaxAckPulseDuration(unsigned long i) {
maxAckPulseDuration = i; maxAckPulseDuration = i;
} }
@ -126,11 +126,11 @@ class DCCACK {
static unsigned long ackCheckStart; // millis static unsigned long ackCheckStart; // millis
static unsigned int ackCheckDuration; // millis static unsigned int ackCheckDuration; // millis
static unsigned int ackPulseDuration; // micros static unsigned long ackPulseDuration; // micros
static unsigned long ackPulseStart; // micros static unsigned long ackPulseStart; // micros
static unsigned int minAckPulseDuration ; // micros static unsigned long minAckPulseDuration ; // micros
static unsigned int maxAckPulseDuration ; // micros static unsigned long maxAckPulseDuration ; // micros
static MotorDriver* progDriver; static MotorDriver* progDriver;
static volatile uint8_t numAckGaps; static volatile uint8_t numAckGaps;
static volatile uint8_t numAckSamples; static volatile uint8_t numAckSamples;

View File

@ -2,7 +2,7 @@
* © 2022 Paul M Antoine * © 2022 Paul M Antoine
* © 2021 Neil McKechnie * © 2021 Neil McKechnie
* © 2021 Mike S * © 2021 Mike S
* © 2021 Herb Morton * © 2021-2024 Herb Morton
* © 2020-2023 Harald Barth * © 2020-2023 Harald Barth
* © 2020-2021 M Steve Todd * © 2020-2021 M Steve Todd
* © 2020-2021 Fred Decker * © 2020-2021 Fred Decker
@ -564,6 +564,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
} }
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
else if (p[0]=="PROG"_hk) { // <0 PROG> else if (p[0]=="PROG"_hk) { // <0 PROG>
TrackManager::setJoin(false);
TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off
TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::OFF); TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::OFF);
} }
@ -642,6 +643,13 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
case 'F': // New command to call the new Loco Function API <F cab func 1|0> case 'F': // New command to call the new Loco Function API <F cab func 1|0>
if(params!=3) break; if(params!=3) break;
if (p[1]=="DCFREQ"_hk) { // <F cab DCFREQ 0..3>
if (p[2]<0 || p[2]>3) break;
DCC::setDCFreq(p[0],p[2]);
return;
}
if (Diag::CMD) if (Diag::CMD)
DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF")); DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF"));
if (DCC::setFn(p[0], p[1], p[2] == 1)) return; if (DCC::setFn(p[0], p[1], p[2] == 1)) return;
@ -1078,15 +1086,24 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
case "ACK"_hk: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX|RETRY] Value> case "ACK"_hk: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX|RETRY] Value>
if (params >= 3) { if (params >= 3) {
long duration;
if (p[1] == "LIMIT"_hk) { if (p[1] == "LIMIT"_hk) {
DCCACK::setAckLimit(p[2]); DCCACK::setAckLimit(p[2]);
LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42> LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42>
} else if (p[1] == "MIN"_hk) { } else if (p[1] == "MIN"_hk) {
DCCACK::setMinAckPulseDuration(p[2]); if (params == 4 && p[3] == "MS"_hk)
LCD(0, F("Ack Min=%uus"), p[2]); // <D ACK MIN 1500> duration = p[2] * 1000L;
else
duration = p[2];
DCCACK::setMinAckPulseDuration(duration);
LCD(0, F("Ack Min=%lus"), duration); // <D ACK MIN 1500>
} else if (p[1] == "MAX"_hk) { } else if (p[1] == "MAX"_hk) {
DCCACK::setMaxAckPulseDuration(p[2]); if (params == 4 && p[3] == "MS"_hk) // <D ACK MAX 80 MS>
LCD(0, F("Ack Max=%uus"), p[2]); // <D ACK MAX 9000> duration = p[2] * 1000L;
else
duration = p[2];
DCCACK::setMaxAckPulseDuration(duration);
LCD(0, F("Ack Max=%lus"), duration); // <D ACK MAX 9000>
} else if (p[1] == "RETRY"_hk) { } else if (p[1] == "RETRY"_hk) {
if (p[2] >255) p[2]=3; if (p[2] >255) p[2]=3;
LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCCACK::setAckRetry(p[2])); // <D ACK RETRY 2> LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCCACK::setAckRetry(p[2])); // <D ACK RETRY 2>

View File

@ -76,8 +76,13 @@ int DCCTimer::freeMemory() {
#endif #endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include "esp_idf_version.h"
#if ESP_IDF_VERSION_MAJOR > 4
#error "DCC-EX does not support compiling with IDF version 5.0 or later. Downgrade your ESP32 library to a version that contains IDE version 4. Arduino ESP32 library 3.0.0 is too new. Downgrade to one of 2.0.9 to 2.0.17"
#endif
#include "DIAG.h" #include "DIAG.h"
#include <driver/adc.h> #include <driver/adc.h>
#include <soc/sens_reg.h> #include <soc/sens_reg.h>
@ -292,7 +297,12 @@ void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty, bool inverted) {
int ADCee::init(uint8_t pin) { int ADCee::init(uint8_t pin) {
pinMode(pin, ANALOG); pinMode(pin, ANALOG);
adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_width(ADC_WIDTH_BIT_12);
// Espressif deprecated ADC_ATTEN_DB_11 somewhere between 2.0.9 and 2.0.17
#ifdef ADC_ATTEN_11db
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_11db);
#else
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11); adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
#endif
return adc1_get_raw(pinToADC1Channel(pin)); return adc1_get_raw(pinToADC1Channel(pin));
} }
int16_t ADCee::ADCmax() { int16_t ADCee::ADCmax() {

View File

@ -228,7 +228,6 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
case OPCODE_AT: case OPCODE_AT:
case OPCODE_ATTIMEOUT2: case OPCODE_ATTIMEOUT2:
case OPCODE_AFTER: case OPCODE_AFTER:
case OPCODE_AFTEROVERLOAD:
case OPCODE_IF: case OPCODE_IF:
case OPCODE_IFNOT: { case OPCODE_IFNOT: {
int16_t pin = (int16_t)operand; int16_t pin = (int16_t)operand;
@ -479,10 +478,15 @@ bool RMFT2::skipIfBlock() {
/* static */ void RMFT2::readLocoCallback(int16_t cv) { /* static */ void RMFT2::readLocoCallback(int16_t cv) {
if (cv <= 0) {
DIAG(F("CV read error"));
progtrackLocoId = -1;
return;
}
if (cv & LONG_ADDR_MARKER) { // maker bit indicates long addr if (cv & LONG_ADDR_MARKER) { // maker bit indicates long addr
progtrackLocoId = cv ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr progtrackLocoId = cv ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr
if (progtrackLocoId <= HIGHEST_SHORT_ADDR ) { // out of range for long addr if (progtrackLocoId <= HIGHEST_SHORT_ADDR ) { // out of range for long addr
DIAG(F("Long addr %d <= %d unsupported\n"), progtrackLocoId, HIGHEST_SHORT_ADDR); DIAG(F("Long addr %d <= %d unsupported"), progtrackLocoId, HIGHEST_SHORT_ADDR);
progtrackLocoId = -1; progtrackLocoId = -1;
} }
} else { } else {
@ -629,14 +633,16 @@ void RMFT2::loop2() {
skipIf=blinkState!=at_timeout; skipIf=blinkState!=at_timeout;
break; break;
case OPCODE_AFTER: // waits for sensor to hit and then remain off for 0.5 seconds. (must come after an AT operation) case OPCODE_AFTER: // waits for sensor to hit and then remain off for x mS.
// Note, this must come after an AT operation, which is
// automatically inserted by the AFTER macro.
if (readSensor(operand)) { if (readSensor(operand)) {
// reset timer to half a second and keep waiting // reset timer and keep waiting
waitAfter=millis(); waitAfter=millis();
delayMe(50); delayMe(50);
return; return;
} }
if (millis()-waitAfter < 500 ) return; if (millis()-waitAfter < getOperand(1) ) return;
break; break;
case OPCODE_AFTEROVERLOAD: // waits for the power to be turned back on - either by power routine or button case OPCODE_AFTEROVERLOAD: // waits for the power to be turned back on - either by power routine or button
@ -717,41 +723,7 @@ void RMFT2::loop2() {
case OPCODE_SETFREQ: case OPCODE_SETFREQ:
// Frequency is default 0, or 1, 2,3 // Frequency is default 0, or 1, 2,3
//if (loco) DCC::setFn(loco,operand,true); DCC::setDCFreq(loco,operand);
switch (operand) {
case 0: // default - all F-s off
if (loco) {
DCC::setFn(loco,29,false);
DCC::setFn(loco,30,false);
DCC::setFn(loco,31,false);
}
break;
case 1:
if (loco) {
DCC::setFn(loco,29,true);
DCC::setFn(loco,30,false);
DCC::setFn(loco,31,false);
}
break;
case 2:
if (loco) {
DCC::setFn(loco,29,false);
DCC::setFn(loco,30,true);
DCC::setFn(loco,31,false);
}
break;
case 3:
if (loco) {
DCC::setFn(loco,29,false);
DCC::setFn(loco,30,false);
DCC::setFn(loco,31,true);
}
break;
default:
; // do nothing
break;
}
break; break;
case OPCODE_RESUME: case OPCODE_RESUME:
@ -954,11 +926,10 @@ void RMFT2::loop2() {
delayMe(100); delayMe(100);
return; // still waiting for callback return; // still waiting for callback
} }
if (progtrackLocoId<0) {
kill(F("No Loco Found"),progtrackLocoId);
return; // still waiting for callback
}
// At failed read will result in loco == -1
// which is intended so it can be checked
// from within EXRAIL
loco=progtrackLocoId; loco=progtrackLocoId;
speedo=0; speedo=0;
forward=true; forward=true;
@ -1001,6 +972,14 @@ void RMFT2::loop2() {
if ((compileFeatures & FEATURE_LCC) && LCCSerial) if ((compileFeatures & FEATURE_LCC) && LCCSerial)
StringFormatter::send(LCCSerial,F("<L x%h>"),(uint16_t)operand); StringFormatter::send(LCCSerial,F("<L x%h>"),(uint16_t)operand);
break; break;
case OPCODE_ACON: // MERG adapter
case OPCODE_ACOF:
if ((compileFeatures & FEATURE_LCC) && LCCSerial)
StringFormatter::send(LCCSerial,F("<L x%c%h%h>"),
opcode==OPCODE_ACON?'0':'1',
(uint16_t)operand,getOperand(progCounter,1));
break;
case OPCODE_LCCX: // long form LCC case OPCODE_LCCX: // long form LCC
if ((compileFeatures & FEATURE_LCC) && LCCSerial) if ((compileFeatures & FEATURE_LCC) && LCCSerial)
@ -1089,6 +1068,8 @@ void RMFT2::loop2() {
case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime
case OPCODE_ONCLOSE: // Turnout event catchers ignored here case OPCODE_ONCLOSE: // Turnout event catchers ignored here
case OPCODE_ONLCC: // LCC event catchers ignored here case OPCODE_ONLCC: // LCC event catchers ignored here
case OPCODE_ONACON: // MERG event catchers ignored here
case OPCODE_ONACOF: // MERG event catchers ignored here
case OPCODE_ONTHROW: case OPCODE_ONTHROW:
case OPCODE_ONACTIVATE: // Activate event catchers ignored here case OPCODE_ONACTIVATE: // Activate event catchers ignored here
case OPCODE_ONDEACTIVATE: case OPCODE_ONDEACTIVATE:

View File

@ -69,6 +69,8 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
OPCODE_TTADDPOSITION,OPCODE_DCCTURNTABLE,OPCODE_EXTTTURNTABLE, OPCODE_TTADDPOSITION,OPCODE_DCCTURNTABLE,OPCODE_EXTTTURNTABLE,
OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT, OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT,
OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC, OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC,
OPCODE_ACON, OPCODE_ACOF,
OPCODE_ONACON, OPCODE_ONACOF,
OPCODE_ONOVERLOAD, OPCODE_ONOVERLOAD,
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN, OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
OPCODE_ROUTE_DISABLED, OPCODE_ROUTE_DISABLED,

View File

@ -99,6 +99,10 @@
#undef LCCX #undef LCCX
#undef LCN #undef LCN
#undef MOVETT #undef MOVETT
#undef ACON
#undef ACOF
#undef ONACON
#undef ONACOF
#undef MESSAGE #undef MESSAGE
#undef ONACTIVATE #undef ONACTIVATE
#undef ONACTIVATEL #undef ONACTIVATEL
@ -191,7 +195,7 @@
#ifndef RMFT2_UNDEF_ONLY #ifndef RMFT2_UNDEF_ONLY
#define ACTIVATE(addr,subaddr) #define ACTIVATE(addr,subaddr)
#define ACTIVATEL(addr) #define ACTIVATEL(addr)
#define AFTER(sensor_id) #define AFTER(sensor_id,timer...)
#define AFTEROVERLOAD(track_id) #define AFTEROVERLOAD(track_id)
#define ALIAS(name,value...) #define ALIAS(name,value...)
#define AMBER(signal_id) #define AMBER(signal_id)
@ -265,6 +269,10 @@
#define LCN(msg) #define LCN(msg)
#define MESSAGE(msg) #define MESSAGE(msg)
#define MOVETT(id,steps,activity) #define MOVETT(id,steps,activity)
#define ACON(eventid)
#define ACOF(eventid)
#define ONACON(eventid)
#define ONACOF(eventid)
#define ONACTIVATE(addr,subaddr) #define ONACTIVATE(addr,subaddr)
#define ONACTIVATEL(linear) #define ONACTIVATEL(linear)
#define ONAMBER(signal_id) #define ONAMBER(signal_id)
@ -326,7 +334,7 @@
#define SET_TRACK(track,mode) #define SET_TRACK(track,mode)
#define SET_POWER(track,onoff) #define SET_POWER(track,onoff)
#define SETLOCO(loco) #define SETLOCO(loco)
#define SETFREQ(loco,freq) #define SETFREQ(freq)
#define SIGNAL(redpin,amberpin,greenpin) #define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin) #define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed) #define SPEED(speed)

View File

@ -61,47 +61,85 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16
case 'L': case 'L':
// This entire code block is compiled out if LLC macros not used // This entire code block is compiled out if LLC macros not used
if (!(compileFeatures & FEATURE_LCC)) return; if (!(compileFeatures & FEATURE_LCC)) return;
static int lccProgCounter=0;
static int lccEventIndex=0;
if (paramCount==0) { //<L> LCC adapter introducing self if (paramCount==0) { //<L> LCC adapter introducing self
LCCSerial=stream; // now we know where to send events we raise LCCSerial=stream; // now we know where to send events we raise
opcode=0; // flag command as intercepted
// loop through all possible sent events // loop through all possible sent/waited events
for (int progCounter=0;; SKIPOP) { for (int progCounter=lccProgCounter;; SKIPOP) {
byte opcode=GET_OPCODE; byte exrailOpcode=GET_OPCODE;
if (opcode==OPCODE_ENDEXRAIL) break; switch (exrailOpcode) {
if (opcode==OPCODE_LCC) StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0)); case OPCODE_ENDEXRAIL:
if (opcode==OPCODE_LCCX) { // long form LCC stream->print(F("<LR>\n")); // ready to roll
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"), lccProgCounter=0; // allow a second pass
lccEventIndex=0;
return;
case OPCODE_LCC:
StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0));
SKIPOP;
lccProgCounter=progCounter;
return;
case OPCODE_LCCX: // long form LCC
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"),
getOperand(progCounter,1), getOperand(progCounter,1),
getOperand(progCounter,2), getOperand(progCounter,2),
getOperand(progCounter,3), getOperand(progCounter,3),
getOperand(progCounter,0) getOperand(progCounter,0)
); );
}} SKIPOP;SKIPOP;SKIPOP;SKIPOP;
lccProgCounter=progCounter;
return;
case OPCODE_ACON: // CBUS ACON
case OPCODE_ACOF: // CBUS ACOF
StringFormatter::send(stream,F("<LS x%c%h%h>\n"),
exrailOpcode==OPCODE_ACOF?'1':'0',
getOperand(progCounter,0),getOperand(progCounter,1));
SKIPOP;SKIPOP;
lccProgCounter=progCounter;
return;
// we stream the hex events we wish to listen to // we stream the hex events we wish to listen to
// and at the same time build the event index looku. // and at the same time build the event index looku.
case OPCODE_ONLCC:
int eventIndex=0;
for (int progCounter=0;; SKIPOP) {
byte opcode=GET_OPCODE;
if (opcode==OPCODE_ENDEXRAIL) break;
if (opcode==OPCODE_ONLCC) {
onLCCLookup[eventIndex]=progCounter; // TODO skip...
StringFormatter::send(stream,F("<LL %d x%h%h%h:%h>\n"), StringFormatter::send(stream,F("<LL %d x%h%h%h:%h>\n"),
eventIndex, lccEventIndex,
getOperand(progCounter,1), getOperand(progCounter,1),
getOperand(progCounter,2), getOperand(progCounter,2),
getOperand(progCounter,3), getOperand(progCounter,3),
getOperand(progCounter,0) getOperand(progCounter,0)
); );
eventIndex++; SKIPOP;SKIPOP;SKIPOP;SKIPOP;
} // start on handler at next
onLCCLookup[lccEventIndex]=progCounter;
lccEventIndex++;
lccProgCounter=progCounter;
return;
case OPCODE_ONACON:
case OPCODE_ONACOF:
StringFormatter::send(stream,F("<LL %d x%c%h%h>\n"),
lccEventIndex,
exrailOpcode==OPCODE_ONACOF?'1':'0',
getOperand(progCounter,0),getOperand(progCounter,1)
);
SKIPOP;SKIPOP;
// start on handler at next
onLCCLookup[lccEventIndex]=progCounter;
lccEventIndex++;
lccProgCounter=progCounter;
return;
default:
break;
}
} }
StringFormatter::send(stream,F("<LR>\n")); // Ready to rumble
opcode=0;
break;
} }
if (paramCount==1) { // <L eventid> LCC event arrived from adapter if (paramCount==1) { // <L eventid> LCC event arrived from adapter
int16_t eventid=p[0]; int16_t eventid=p[0];

View File

@ -189,6 +189,14 @@ bool exrailHalSetup() {
#define LCCX(senderid,eventid) | FEATURE_LCC #define LCCX(senderid,eventid) | FEATURE_LCC
#undef ONLCC #undef ONLCC
#define ONLCC(senderid,eventid) | FEATURE_LCC #define ONLCC(senderid,eventid) | FEATURE_LCC
#undef ACON
#define ACON(eventid) | FEATURE_LCC
#undef ACOF
#define ACOF(eventid) | FEATURE_LCC
#undef ONACON
#define ONACON(eventid) | FEATURE_LCC
#undef ONACOF
#define ONACOF(eventid) | FEATURE_LCC
#undef ROUTE_ACTIVE #undef ROUTE_ACTIVE
#define ROUTE_ACTIVE(id) | FEATURE_ROUTESTATE #define ROUTE_ACTIVE(id) | FEATURE_ROUTESTATE
#undef ROUTE_INACTIVE #undef ROUTE_INACTIVE
@ -429,10 +437,14 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
#include "myAutomation.h" #include "myAutomation.h"
0,0,0,0 }; 0,0,0,0 };
// Pass 9 ONLCC counter and lookup array // Pass 9 ONLCC/ ONMERG counter and lookup array
#include "EXRAIL2MacroReset.h" #include "EXRAIL2MacroReset.h"
#undef ONLCC #undef ONLCC
#define ONLCC(sender,event) +1 #define ONLCC(sender,event) +1
#undef ONACON
#define ONACON(event) +1
#undef ONACOF
#define ONACOF(event) +1
const int RMFT2::countLCCLookup=0 const int RMFT2::countLCCLookup=0
#include "myAutomation.h" #include "myAutomation.h"
@ -451,7 +463,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define ACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1 | 1), #define ACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1 | 1),
#define ACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<1 | 1), #define ACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<1 | 1),
#define AFTER(sensor_id) OPCODE_AT,V(sensor_id),OPCODE_AFTER,V(sensor_id), #define AFTER(sensor_id,timer...) OPCODE_AT,V(sensor_id),OPCODE_AFTER,V(sensor_id),OPCODE_PAD,V(#timer[0]?timer+0:500),
#define AFTEROVERLOAD(track_id) OPCODE_AFTEROVERLOAD,V(TRACK_NUMBER_##track_id), #define AFTEROVERLOAD(track_id) OPCODE_AFTEROVERLOAD,V(TRACK_NUMBER_##track_id),
#define ALIAS(name,value...) #define ALIAS(name,value...)
#define AMBER(signal_id) OPCODE_AMBER,V(signal_id), #define AMBER(signal_id) OPCODE_AMBER,V(signal_id),
@ -529,6 +541,10 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\ OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\
OPCODE_PAD,V((((uint64_t)sender)>>16)&0xFFFF),\ OPCODE_PAD,V((((uint64_t)sender)>>16)&0xFFFF),\
OPCODE_PAD,V((((uint64_t)sender)>>0)&0xFFFF), OPCODE_PAD,V((((uint64_t)sender)>>0)&0xFFFF),
#define ACON(eventid) OPCODE_ACON,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF),
#define ACOF(eventid) OPCODE_ACOF,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF),
#define ONACON(eventid) OPCODE_ONACON,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF),
#define ONACOF(eventid) OPCODE_ONACOF,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF),
#define LCD(id,msg) PRINT(msg) #define LCD(id,msg) PRINT(msg)
#define SCREEN(display,id,msg) PRINT(msg) #define SCREEN(display,id,msg) PRINT(msg)
#define STEALTH(code...) PRINT(dummy) #define STEALTH(code...) PRINT(dummy)
@ -604,7 +620,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define SET_TRACK(track,mode) OPCODE_SET_TRACK,V(TRACK_MODE_##mode <<8 | TRACK_NUMBER_##track), #define SET_TRACK(track,mode) OPCODE_SET_TRACK,V(TRACK_MODE_##mode <<8 | TRACK_NUMBER_##track),
#define SET_POWER(track,onoff) OPCODE_SET_POWER,V(TRACK_POWER_##onoff),OPCODE_PAD, V(TRACK_NUMBER_##track), #define SET_POWER(track,onoff) OPCODE_SET_POWER,V(TRACK_POWER_##onoff),OPCODE_PAD, V(TRACK_NUMBER_##track),
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco), #define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
#define SETFREQ(loco,freq) OPCODE_SETLOCO,V(loco), OPCODE_SETFREQ,V(freq), #define SETFREQ(freq) OPCODE_SETFREQ,V(freq),
#define SIGNAL(redpin,amberpin,greenpin) #define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin) #define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed) OPCODE_SPEED,V(speed), #define SPEED(speed) OPCODE_SPEED,V(speed),

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202404091507Z" #define GITHUB_SHA "devel-202409040713Z"

View File

@ -547,7 +547,7 @@ protected:
#include "IO_duinoNodes.h" #include "IO_duinoNodes.h"
#include "IO_EXIOExpander.h" #include "IO_EXIOExpander.h"
#include "IO_trainbrains.h" #include "IO_trainbrains.h"
#include "IO_EncoderThrottle.h"
#include "IO_EXSensorCAM.h" #include "IO_EXSensorCAM.h"
#endif // iodevice_h #endif // iodevice_h

144
IO_EncoderThrottle.cpp Normal file
View File

@ -0,0 +1,144 @@
/*
* © 2024, Chris Harlow. All rights reserved.
*
* This file is part of EX-CommandStation
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins
* to drive a loco.
* Loco id is selected by writeAnalog.
*/
#include "IODevice.h"
#include "DIAG.h"
#include "DCC.h"
const byte _DIR_CW = 0x10; // Clockwise step
const byte _DIR_CCW = 0x20; // Counter-clockwise step
const byte transition_table[5][4]= {
{0,1,3,0}, // 0: 00
{1,1,1,2 | _DIR_CW}, // 1: 00->01
{2,2,0,2}, // 2: 00->01->11
{3,3,3,4 | _DIR_CCW}, // 3: 00->10
{4,0,4,4} // 4: 00->10->11
};
const byte _STATE_MASK = 0x07;
const byte _DIR_MASK = 0x30;
void EncoderThrottle::create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch) {
if (checkNoOverlap(firstVpin)) new EncoderThrottle(firstVpin, dtPin,clkPin,clickPin,notch);
}
// Constructor
EncoderThrottle::EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch){
_firstVpin = firstVpin;
_nPins = 1;
_I2CAddress = 0;
_dtPin=dtPin;
_clkPin=clkPin;
_clickPin=clickPin;
_notch=notch;
_locoid=0;
_stopState=xrSTOP;
_rocoState=0;
_prevpinstate=4; // not 01..11
IODevice::configureInput(dtPin,true);
IODevice::configureInput(clkPin,true);
IODevice::configureInput(clickPin,true);
addDevice(this);
_display();
}
void EncoderThrottle::_loop(unsigned long currentMicros) {
if (_locoid==0) return; // not in use
// Clicking down on the roco, stops the loco and sets the direction as unknown.
if (IODevice::read(_clickPin)) {
if (_stopState==xrSTOP) return; // debounced multiple stops
DCC::setThrottle(_locoid,1,DCC::getThrottleDirection(_locoid));
_stopState=xrSTOP;
DIAG(F("DRIVE %d STOP"),_locoid);
return;
}
// read roco pins and detect state change
byte pinstate = (IODevice::read(_dtPin) << 1) | IODevice::read(_clkPin);
if (pinstate==_prevpinstate) return;
_prevpinstate=pinstate;
_rocoState = transition_table[_rocoState & _STATE_MASK][pinstate];
if ((_rocoState & _DIR_MASK) == 0) return; // no value change
int change=(_rocoState & _DIR_CW)?+1:-1;
// handle roco change -1 or +1 (clockwise)
if (_stopState==xrSTOP) {
// first move after button press sets the direction. (clockwise=fwd)
_stopState=change>0?xrFWD:xrREV;
}
// when going fwd, clockwise increases speed.
// but when reversing, anticlockwise increases speed.
// This is similar to a center-zero pot control but with
// the added safety that you cant panic-spin into the other
// direction.
if (_stopState==xrREV) change=-change;
// manage limits
int oldspeed=DCC::getThrottleSpeed(_locoid);
if (oldspeed==1)oldspeed=0; // break out of estop
int newspeed=change>0 ? (min((oldspeed+_notch),126)) : (max(0,(oldspeed-_notch)));
if (newspeed==1) newspeed=0; // normal decelereated stop.
if (oldspeed!=newspeed) {
DIAG(F("DRIVE %d notch %S %d %S"),_locoid,
change>0?F("UP"):F("DOWN"),_notch,
_stopState==xrFWD?F("FWD"):F("REV"));
DCC::setThrottle(_locoid,newspeed,_stopState==xrFWD);
}
}
// Selocoid as analog value to start drive
// use <z vpin locoid [notch]>
void EncoderThrottle::_writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) {
(void) param2;
_locoid=value;
if (param1>0) _notch=param1;
_rocoState=0;
// If loco is moving, we inherit direction from it.
_stopState=xrSTOP;
if (_locoid>0) {
auto speedbyte=DCC::getThrottleSpeedByte(_locoid);
if ((speedbyte & 0x7f) >1) {
// loco is moving
_stopState= (speedbyte & 0x80)?xrFWD:xrREV;
}
}
_display();
}
void EncoderThrottle::_display() {
DIAG(F("DRIVE vpin %d loco %d notch %d"),_firstVpin,_locoid,_notch);
}

53
IO_EncoderThrottle.h Normal file
View File

@ -0,0 +1,53 @@
/*
* © 2024, Chris Harlow. All rights reserved.
*
* This file is part of EX-CommandStation
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins
* to drive a loco.
* Loco id is selected by writeAnalog.
*/
#ifndef IO_EncoderThrottle_H
#define IO_EncoderThrottle_H
#include "IODevice.h"
class EncoderThrottle : public IODevice {
public:
static void create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch=10);
private:
int _dtPin,_clkPin,_clickPin, _locoid, _notch,_prevpinstate;
enum {xrSTOP,xrFWD,xrREV} _stopState;
byte _rocoState;
// Constructor
EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch);
void _loop(unsigned long currentMicros) override ;
// Selocoid as analog value to start drive
// use <z vpin locoid [notch]>
void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override;
void _display() override ;
};
#endif

View File

@ -26,7 +26,7 @@
Thus "MAIN"_hk generates exactly the same run time vakue Thus "MAIN"_hk generates exactly the same run time vakue
as const int16_t HASH_KEYWORD_MAIN=11339 as const int16_t HASH_KEYWORD_MAIN=11339
*/ */
#ifndef KeywordHAsher_h #ifndef KeywordHasher_h
#define KeywordHasher_h #define KeywordHasher_h
#include <Arduino.h> #include <Arduino.h>

View File

@ -1,5 +1,6 @@
/* /*
* © 2022-2024 Paul M Antoine * © 2022-2024 Paul M Antoine
* © 2024 Herb Morton
* © 2021 Mike S * © 2021 Mike S
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2020-2023 Harald Barth * © 2020-2023 Harald Barth
@ -98,7 +99,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
if (HAVE_PORTH(fastSignalPin.inout == &PORTH)) { if (HAVE_PORTH(fastSignalPin.inout == &PORTH)) {
DIAG(F("Found PORTH pin %d"),signalPin); DIAG(F("Found PORTH pin %d"),signalPin);
fastSignalPin.shadowinout = fastSignalPin.inout; fastSignalPin.shadowinout = fastSignalPin.inout;
fastSignalPin.inout = &shadowPORTF; fastSignalPin.inout = &shadowPORTH;
} }
signalPin2=signal_pin2; signalPin2=signal_pin2;
@ -638,6 +639,10 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
} }
throttleInrush(false); throttleInrush(false);
setPower(POWERMODE::ON); setPower(POWERMODE::ON);
break;
}
if (goodtime > POWER_SAMPLE_ALERT_GOOD/2) {
throttleInrush(false);
} }
break; break;
} }

View File

@ -97,6 +97,18 @@
new MotorDriver(25/* 3*/, 19/*12*/, UNUSED_PIN, 13/*9*/, 35/*A2*/, 1.27, 5000, 36 /*A4*/), \ new MotorDriver(25/* 3*/, 19/*12*/, UNUSED_PIN, 13/*9*/, 35/*A2*/, 1.27, 5000, 36 /*A4*/), \
new MotorDriver(23/*11*/, 18/*13*/, UNUSED_PIN, 12/*8*/, 34/*A3*/, 1.27, 5000, 39 /*A5*/) new MotorDriver(23/*11*/, 18/*13*/, UNUSED_PIN, 12/*8*/, 34/*A3*/, 1.27, 5000, 39 /*A5*/)
// EX-CSB1 with integrated motor driver definition
#define EXCSB1 F("EXCSB1"),\
new MotorDriver(25, 0, UNUSED_PIN, -14, 34, 2.23, 5000, 19), \
new MotorDriver(27, 15, UNUSED_PIN, -2, 35, 2.23, 5000, 23)
// EX-CSB1 with EX-8874 stacked on top for 4 outputs
#define EXCSB1_WITH_EX8874 F("EXCSB1_WITH_EX8874"),\
new MotorDriver(25, 0, UNUSED_PIN, -14, 34, 2.23, 5000, 19), \
new MotorDriver(27, 15, UNUSED_PIN, -2, 35, 2.23, 5000, 23), \
new MotorDriver(26, 5, UNUSED_PIN, 13, 36, 1.52, 5000, 18), \
new MotorDriver(16, 4, UNUSED_PIN, 12, 39, 1.52, 5000, 17)
#else #else
// STANDARD shield on any Arduino Uno or Mega compatible with the original specification. // STANDARD shield on any Arduino Uno or Mega compatible with the original specification.
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \ #define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \

View File

@ -68,7 +68,11 @@ void SerialManager::init() {
new SerialManager(&Serial3); new SerialManager(&Serial3);
#endif #endif
#ifdef SERIAL2_COMMANDS #ifdef SERIAL2_COMMANDS
#ifdef ARDUINO_ARCH_ESP32
Serial2.begin(115200, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32
#else // not ESP32
Serial2.begin(115200); Serial2.begin(115200);
#endif // ESP32
new SerialManager(&Serial2); new SerialManager(&Serial2);
#endif #endif
#ifdef SERIAL1_COMMANDS #ifdef SERIAL1_COMMANDS
@ -88,7 +92,11 @@ void SerialManager::init() {
} }
#endif #endif
#ifdef SABERTOOTH #ifdef SABERTOOTH
#ifdef ARDUINO_ARCH_ESP32
Serial2.begin(9600, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32 Serial2.begin(9600, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32
#else
Serial2.begin(9600);
#endif
#endif #endif
} }

View File

@ -139,6 +139,7 @@ void StringFormatter::send2(Print * stream,const FSH* format, va_list args) {
case 'd': printPadded(stream,va_arg(args, int), formatWidth, formatLeft); break; case 'd': printPadded(stream,va_arg(args, int), formatWidth, formatLeft); break;
case 'u': printPadded(stream,va_arg(args, unsigned int), formatWidth, formatLeft); break; case 'u': printPadded(stream,va_arg(args, unsigned int), formatWidth, formatLeft); break;
case 'l': printPadded(stream,va_arg(args, long), formatWidth, formatLeft); break; case 'l': printPadded(stream,va_arg(args, long), formatWidth, formatLeft); break;
case 'L': stream->print(va_arg(args, unsigned long), DEC); break;
case 'b': stream->print(va_arg(args, int), BIN); break; case 'b': stream->print(va_arg(args, int), BIN); break;
case 'o': stream->print(va_arg(args, int), OCT); break; case 'o': stream->print(va_arg(args, int), OCT); break;
case 'x': stream->print((unsigned int)va_arg(args, unsigned int), HEX); break; case 'x': stream->print((unsigned int)va_arg(args, unsigned int), HEX); break;

View File

@ -1,6 +1,8 @@
/* /*
* © 2022 Chris Harlow * © 2022 Chris Harlow
* © 2022-2024 Harald Barth * © 2022-2024 Harald Barth
* © 2023-2024 Paul M. Antoine
* © 2024 Herb Morton
* © 2023 Colin Murdoch * © 2023 Colin Murdoch
* All rights reserved. * All rights reserved.
* *
@ -149,6 +151,8 @@ void TrackManager::setDCCSignal( bool on) {
HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTD(shadowPORTD=PORTD);
HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTE(shadowPORTE=PORTE);
HAVE_PORTF(shadowPORTF=PORTF); HAVE_PORTF(shadowPORTF=PORTF);
HAVE_PORTG(shadowPORTF=PORTG);
HAVE_PORTH(shadowPORTF=PORTH);
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on)); APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTA(PORTA=shadowPORTA);
HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTB(PORTB=shadowPORTB);
@ -156,6 +160,8 @@ void TrackManager::setDCCSignal( bool on) {
HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTD(PORTD=shadowPORTD);
HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTE(PORTE=shadowPORTE);
HAVE_PORTF(PORTF=shadowPORTF); HAVE_PORTF(PORTF=shadowPORTF);
HAVE_PORTG(shadowPORTF=PORTG);
HAVE_PORTH(shadowPORTF=PORTH);
} }
// setPROGSignal(), called from interrupt context // setPROGSignal(), called from interrupt context
@ -167,6 +173,8 @@ void TrackManager::setPROGSignal( bool on) {
HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTD(shadowPORTD=PORTD);
HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTE(shadowPORTE=PORTE);
HAVE_PORTF(shadowPORTF=PORTF); HAVE_PORTF(shadowPORTF=PORTF);
HAVE_PORTG(shadowPORTF=PORTG);
HAVE_PORTH(shadowPORTF=PORTH);
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on)); APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTA(PORTA=shadowPORTA);
HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTB(PORTB=shadowPORTB);
@ -174,6 +182,8 @@ void TrackManager::setPROGSignal( bool on) {
HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTD(PORTD=shadowPORTD);
HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTE(PORTE=shadowPORTE);
HAVE_PORTF(PORTF=shadowPORTF); HAVE_PORTF(PORTF=shadowPORTF);
HAVE_PORTG(shadowPORTF=PORTG);
HAVE_PORTH(shadowPORTF=PORTH);
} }
// setDCSignal(), called from normal context // setDCSignal(), called from normal context
@ -631,23 +641,25 @@ void TrackManager::setJoinRelayPin(byte joinRelayPin) {
void TrackManager::setJoin(bool joined) { void TrackManager::setJoin(bool joined) {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
if (joined) { if (joined) { // if we go into joined mode (PROG acts as MAIN)
FOR_EACH_TRACK(t) { FOR_EACH_TRACK(t) {
if (track[t]->getMode() & TRACK_MODE_PROG) { if (track[t]->getMode() & TRACK_MODE_PROG) { // find PROG track
tempProgTrack = t; tempProgTrack = t; // remember PROG track
setTrackMode(t, TRACK_MODE_MAIN); setTrackMode(t, TRACK_MODE_MAIN);
break; track[t]->setPower(POWERMODE::ON); // if joined, always on
break; // there is only one prog track, done
} }
} }
} else { } else {
if (tempProgTrack != MAX_TRACKS+1) { if (tempProgTrack != MAX_TRACKS+1) {
// as setTrackMode with TRACK_MODE_PROG defaults to // setTrackMode defaults to power off, so we
// power off, we will take the current power state // need to preserve that state.
// of our track and then preserve that state. POWERMODE tPTmode = track[tempProgTrack]->getPower(); // get current power status of this track
POWERMODE tPTmode = track[tempProgTrack]->getPower(); //get current power status of this track setTrackMode(tempProgTrack, TRACK_MODE_PROG); // set track mode back to prog
setTrackMode(tempProgTrack, TRACK_MODE_PROG); track[tempProgTrack]->setPower(tPTmode); // set power status as it was before
track[tempProgTrack]->setPower(tPTmode); //set track status as it was before
tempProgTrack = MAX_TRACKS+1; tempProgTrack = MAX_TRACKS+1;
} else {
DIAG(F("Unjoin but no remembered prog track"));
} }
} }
#endif #endif

View File

@ -147,6 +147,12 @@ bool WifiESP::setup(const char *SSid,
// enableCoreWDT(1); // enableCoreWDT(1);
// disableCoreWDT(0); // disableCoreWDT(0);
#ifdef WIFI_LED
// Turn off Wifi LED
pinMode(WIFI_LED, OUTPUT);
digitalWrite(WIFI_LED, 0);
#endif
// clean start // clean start
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.disconnect(true); WiFi.disconnect(true);
@ -247,12 +253,19 @@ bool WifiESP::setup(const char *SSid,
// no idea to go on // no idea to go on
return false; return false;
} }
#ifdef WIFI_LED
else{
// Turn on Wifi connected LED
digitalWrite(WIFI_LED, 1);
}
#endif
// Now Wifi is up, register the mDNS service // Now Wifi is up, register the mDNS service
if(!MDNS.begin(hostname)) { if(!MDNS.begin(hostname)) {
DIAG(F("Wifi setup failed to start mDNS")); DIAG(F("Wifi setup failed to start mDNS"));
} }
if(!MDNS.addService("withrottle", "tcp", 2560)) { if(!MDNS.addService("withrottle", "tcp", port)) {
DIAG(F("Wifi setup failed to add withrottle service to mDNS")); DIAG(F("Wifi setup failed to add withrottle service to mDNS"));
} }

View File

@ -1,295 +1,338 @@
/* /*
* © 2022 Paul M. Antoine * © 2022 Paul M. Antoine
* © 2021 Neil McKechnie * © 2021 Neil McKechnie
* © 2020-2023 Harald Barth * © 2020-2023 Harald Barth
* © 2020-2021 Fred Decker * © 2020-2021 Fred Decker
* © 2020-2021 Chris Harlow * © 2020-2021 Chris Harlow
* © 2023 Nathan Kellenicki * © 2023 Nathan Kellenicki
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
* *
* This is free software: you can redistribute it and/or modify * This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* It is distributed in the hope that it will be useful, * It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>. * along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/ */
/********************************************************************** /**********************************************************************
The configuration file for DCC-EX Command Station The configuration file for DCC-EX Command Station
**********************************************************************/ **********************************************************************/
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// If you want to add your own motor driver definition(s), add them here // If you want to add your own motor driver definition(s), add them here
// For example MY_SHIELD with display name "MINE": // For example MY_SHIELD with display name "MINE":
// (remove comment start and end marker if you want to edit and use that) // (remove comment start and end marker if you want to edit and use that)
/* /*
#define MY_SHIELD F("MINE"), \ #define MY_SHIELD F("MINE"), \
new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 5.08, 3000, A4), \ new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 5.08, 3000, A4), \
new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 5.08, 1500, A5) new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 5.08, 1500, A5)
*/ */
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// NOTE: Before connecting these boards and selecting one in this software // NOTE: Before connecting these boards and selecting one in this software
// check the quick install guides!!! Some of these boards require a voltage // check the quick install guides!!! Some of these boards require a voltage
// generating resistor on the current sense pin of the device. Failure to select // generating resistor on the current sense pin of the device. Failure to select
// the correct resistor could damage the sense pin on your Arduino or destroy // the correct resistor could damage the sense pin on your Arduino or destroy
// the device. // the device.
// //
// DEFINE MOTOR_SHIELD_TYPE BELOW. THESE ARE EXAMPLES. FULL LIST IN MotorDrivers.h // DEFINE MOTOR_SHIELD_TYPE BELOW. THESE ARE EXAMPLES. FULL LIST IN MotorDrivers.h
// //
// STANDARD_MOTOR_SHIELD : Arduino Motor shield Rev3 based on the L298 with 18V 2A per channel // STANDARD_MOTOR_SHIELD : Arduino Motor shield Rev3 based on the L298 with 18V 2A per channel
// POLOLU_MOTOR_SHIELD : Pololu MC33926 Motor Driver (not recommended for prog track) // POLOLU_MOTOR_SHIELD : Pololu MC33926 Motor Driver (not recommended for prog track)
// FUNDUMOTO_SHIELD : Fundumoto Shield, no current sensing (not recommended, no short protection) // FUNDUMOTO_SHIELD : Fundumoto Shield, no current sensing (not recommended, no short protection)
// FIREBOX_MK1 : The Firebox MK1 // FIREBOX_MK1 : The Firebox MK1
// FIREBOX_MK1S : The Firebox MK1S // FIREBOX_MK1S : The Firebox MK1S
// IBT_2_WITH_ARDUINO : Arduino Motor Shield for PROG and IBT-2 for MAIN // IBT_2_WITH_ARDUINO : Arduino Motor Shield for PROG and IBT-2 for MAIN
// EX8874_SHIELD : DCC-EX TI DRV8874 based motor shield // EX8874_SHIELD : DCC-EX TI DRV8874 based motor shield
// | // |
// +-----------------------v // +-----------------------v
// //
#define MOTOR_SHIELD_TYPE STANDARD_MOTOR_SHIELD #define MOTOR_SHIELD_TYPE STANDARD_MOTOR_SHIELD
// //
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// If you want to restrict the maximum current LOWER than what your // If you want to restrict the maximum current LOWER than what your
// motor shield can provide, you can do that here. For example if you // motor shield can provide, you can do that here. For example if you
// have a motor shield that can provide 5A and your power supply can // have a motor shield that can provide 5A and your power supply can
// only provide 2.5A then you should restict the maximum current to // only provide 2.5A then you should restict the maximum current to
// 2.25A (90% of 2.5A) so that DCC-EX does shut off the track before // 2.25A (90% of 2.5A) so that DCC-EX does shut off the track before
// your PS does shut DCC-EX. MAX_CURRENT is in mA so for this example // your PS does shut DCC-EX. MAX_CURRENT is in mA so for this example
// it would be 2250, adjust the number according to your PS. If your // it would be 2250, adjust the number according to your PS. If your
// PS has a higher rating than your motor shield you do not need this. // PS has a higher rating than your motor shield you do not need this.
// You can use this as well if you are cautious and your trains do not // You can use this as well if you are cautious and your trains do not
// need full current. // need full current.
// #define MAX_CURRENT 2250 // #define MAX_CURRENT 2250
// //
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// The IP port to talk to a WIFI or Ethernet shield. // The IP port to talk to a WIFI or Ethernet shield.
// //
#define IP_PORT 2560 #define IP_PORT 2560
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// NOTE: Only supported on Arduino Mega // NOTE: Only supported on Arduino Mega
// Set to false if you not even want it on the Arduino Mega // Set to false if you not even want it on the Arduino Mega
// //
#define ENABLE_WIFI false //true #define ENABLE_WIFI true
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// DEFINE WiFi Parameters (only in effect if WIFI is on) // DEFINE WiFi Parameters (only in effect if WIFI is on)
// //
// If DONT_TOUCH_WIFI_CONF is set, all WIFI config will be done with // If DONT_TOUCH_WIFI_CONF is set, all WIFI config will be done with
// the <+> commands and this sketch will not change anything over // the <+> commands and this sketch will not change anything over
// AT commands and the other WIFI_* defines below do not have any effect. // AT commands and the other WIFI_* defines below do not have any effect.
//#define DONT_TOUCH_WIFI_CONF //#define DONT_TOUCH_WIFI_CONF
// //
// WIFI_SSID is the network name IF you want to use your existing home network. // WIFI_SSID is the network name IF you want to use your existing home network.
// Do NOT change this if you want to use the WiFi in Access Point (AP) mode. // Do NOT change this if you want to use the WiFi in Access Point (AP) mode.
// //
// If you do NOT set the WIFI_SSID and do NOT set the WIFI_PASSWORD, // If you do NOT set the WIFI_SSID and do NOT set the WIFI_PASSWORD,
// then the WiFi chip will first try to connect to the previously // then the WiFi chip will first try to connect to the previously
// configured network and if that fails fall back to Access Point mode. // configured network and if that fails fall back to Access Point mode.
// The SSID of the AP will be automatically set to DCCEX_*. // The SSID of the AP will be automatically set to DCCEX_*.
// If you DO set the WIFI_SSID then the WiFi chip will try to connect // If you DO set the WIFI_SSID then the WiFi chip will try to connect
// to that (home) network in station (client) mode. If a WIFI_PASSWORD // to that (home) network in station (client) mode. If a WIFI_PASSWORD
// is set (recommended), that password will be used for AP mode. // is set (recommended), that password will be used for AP mode.
// The AP mode password must be at least 8 characters long. // The AP mode password must be at least 8 characters long.
// //
// Your SSID may not contain ``"'' (double quote, ASCII 0x22). // Your SSID may not contain ``"'' (double quote, ASCII 0x22).
#define WIFI_SSID "Your network name" #define WIFI_SSID "Your network name"
// //
// WIFI_PASSWORD is the network password for your home network or if // WIFI_PASSWORD is the network password for your home network or if
// you want to change the password from default AP mode password // you want to change the password from default AP mode password
// to the AP password you want. // to the AP password you want.
// Your password may not contain ``"'' (double quote, ASCII 0x22). // Your password may not contain ``"'' (double quote, ASCII 0x22).
#define WIFI_PASSWORD "Your network passwd" #define WIFI_PASSWORD "Your network passwd"
// //
// WIFI_HOSTNAME: You probably don't need to change this // WIFI_HOSTNAME: You probably don't need to change this
#define WIFI_HOSTNAME "dccex" #define WIFI_HOSTNAME "dccex"
// //
// WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented, // WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented,
// WiFi will be enabled (Mega only). The default channel is set to "1" whether // WiFi will be enabled (Mega only). The default channel is set to "1" whether
// this line exists or not. If you need to use an alternate channel (we recommend // this line exists or not. If you need to use an alternate channel (we recommend
// using only 1,6, or 11) you may change it here. // using only 1,6, or 11) you may change it here.
#define WIFI_CHANNEL 1 #define WIFI_CHANNEL 1
// //
// WIFI_FORCE_AP: If you'd like to specify your own WIFI_SSID in AP mode, set this // WIFI_FORCE_AP: If you'd like to specify your own WIFI_SSID in AP mode, set this
// true. Otherwise it is assumed that you'd like to connect to an existing network // true. Otherwise it is assumed that you'd like to connect to an existing network
// with that SSID. // with that SSID.
#define WIFI_FORCE_AP false #define WIFI_FORCE_AP false
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// ENABLE_ETHERNET: Set to true if you have an Arduino Ethernet card (wired). This // ENABLE_ETHERNET: Set to true if you have an Arduino Ethernet card (wired). This
// is not for Wifi. You will then need the Arduino Ethernet library as well // is not for Wifi. You will then need the Arduino Ethernet library as well
// //
//#define ENABLE_ETHERNET true //#define ENABLE_ETHERNET true
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// DEFINE STATIC IP ADDRESS *OR* COMMENT OUT TO USE DHCP // DEFINE STATIC IP ADDRESS *OR* COMMENT OUT TO USE DHCP
// //
//#define IP_ADDRESS { 192, 168, 1, 200 } //#define IP_ADDRESS { 192, 168, 1, 200 }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //
// DEFINE LCD SCREEN USAGE BY THE BASE STATION // DEFINE LCD SCREEN USAGE BY THE BASE STATION
// //
// Note: This feature requires an I2C enabled LCD screen using a Hitachi HD44780 // Note: This feature requires an I2C enabled LCD screen using a Hitachi HD44780
// controller and a commonly available PCF8574 based I2C 'backpack'. // controller and a commonly available PCF8574 based I2C 'backpack'.
// To enable, uncomment one of the #define lines below // To enable, uncomment one of the #define lines below
// define LCD_DRIVER for I2C address 0x27, 16 cols, 2 rows // define LCD_DRIVER for I2C address 0x27, 16 cols, 2 rows
// #define LCD_DRIVER 0x27,16,2 // #define LCD_DRIVER 0x27,16,2
//OR define OLED_DRIVER width,height[,address] in pixels (address auto detected if not supplied) //OR define OLED_DRIVER width,height[,address] in pixels (address auto detected if not supplied)
// 128x32 or 128x64 I2C SSD1306-based devices are supported. // 128x32 or 128x64 I2C SSD1306-based devices are supported.
// Use 132,64 for a SH1106-based I2C device with a 128x64 display. // Use 132,64 for a SH1106-based I2C device with a 128x64 display.
// #define OLED_DRIVER 0x3c,128,32 // #define OLED_DRIVER 0x3c,128,32
// Define scroll mode as 0, 1 or 2 // Define scroll mode as 0, 1 or 2
// * #define SCROLLMODE 0 is scroll continuous (fill screen if poss), // * #define SCROLLMODE 0 is scroll continuous (fill screen if poss),
// * #define SCROLLMODE 1 is by page (alternate between pages), // * #define SCROLLMODE 1 is by page (alternate between pages),
// * #define SCROLLMODE 2 is by row (move up 1 row at a time). // * #define SCROLLMODE 2 is by row (move up 1 row at a time).
#define SCROLLMODE 1 #define SCROLLMODE 1
///////////////////////////////////////////////////////////////////////////////////// // In order to avoid wasting memory the current scroll buffer is limited
// DISABLE EEPROM // to 8 lines. Some users wishing to display additional information
// // such as TrackManager power states have requested additional rows aware
// If you do not need the EEPROM at all, you can disable all the code that saves // of the warning that this will take extra RAM. if you wish to include additional rows
// data in the EEPROM. You might want to do that if you are in a Arduino UNO // uncomment the following #define and set the number of lines you need.
// and want to use the EXRAIL automation. Otherwise you do not have enough RAM //#define MAX_CHARACTER_ROWS 12
// to do that. Of course, then none of the EEPROM related commands work.
//
// EEPROM does not work on ESP32. So on ESP32, EEPROM will always be disabled, /////////////////////////////////////////////////////////////////////////////////////
// at least until it works. // DISABLE EEPROM
// //
// #define DISABLE_EEPROM // If you do not need the EEPROM at all, you can disable all the code that saves
// data in the EEPROM. You might want to do that if you are in a Arduino UNO
///////////////////////////////////////////////////////////////////////////////////// // and want to use the EXRAIL automation. Otherwise you do not have enough RAM
// DISABLE PROG // to do that. Of course, then none of the EEPROM related commands work.
// //
// If you do not need programming capability, you can disable all programming related // EEPROM does not work on ESP32. So on ESP32, EEPROM will always be disabled,
// commands. You might want to do that if you are using an Arduino UNO and still want // at least until it works.
// to use EXRAIL automation, as the Uno is lacking in RAM and Flash to run both. //
// // #define DISABLE_EEPROM
// Note this disables all programming functionality, including EXRAIL.
// /////////////////////////////////////////////////////////////////////////////////////
// #define DISABLE_PROG // DISABLE PROG
//
///////////////////////////////////////////////////////////////////////////////////// // If you do not need programming capability, you can disable all programming related
// REDEFINE WHERE SHORT/LONG ADDR break is. According to NMRA the last short address // commands. You might want to do that if you are using an Arduino UNO and still want
// is 127 and the first long address is 128. There are manufacturers which have // to use EXRAIL automation, as the Uno is lacking in RAM and Flash to run both.
// another view. Lenz CS for example have considered addresses long from 100. If //
// you want to change to that mode, do // Note this disables all programming functionality, including EXRAIL.
//#define HIGHEST_SHORT_ADDR 99 //
// If you want to run all your locos addressed long format, you could even do a // #define DISABLE_PROG
//#define HIGHEST_SHORT_ADDR 0
// We do not support to use the same address, for example 100(long) and 100(short) /////////////////////////////////////////////////////////////////////////////////////
// at the same time, there must be a border. // DISABLE / ENABLE VDPY
//
///////////////////////////////////////////////////////////////////////////////////// // The Virtual display "VDPY" feature is by default enabled everywhere
// // but on Uno and Nano. If you think you can fit it (for example
// DEFINE TURNOUTS/ACCESSORIES FOLLOW NORM RCN-213 // having disabled some of the features above) you can enable it with
// // ENABLE_VDPY. You can even disable it on all other CPUs with
// According to norm RCN-213 a DCC packet with a 1 is closed/straight // DISABLE_VDPY
// and one with a 0 is thrown/diverging. In DCC++ Classic, and in previous //
// versions of DCC++EX, a turnout throw command was implemented in the packet as // #define DISABLE_VDPY
// '1' and a close command as '0'. The #define below makes the states // #define ENABLE_VDPY
// match with the norm. But we don't want to cause havoc on existent layouts,
// so we define this only for new installations. If you don't want this, /////////////////////////////////////////////////////////////////////////////////////
// don't add it to your config.h. // DISABLE / ENABLE DIAG
//#define DCC_TURNOUTS_RCN_213 //
// To diagose different errors, you can turn on differnet messages. This costs
// By default, the driver which defines a DCC accessory decoder // program memory which we do not have enough on the Uno and Nano, so it is
// does send out the same state change on the DCC packet as it // by default DISABLED on those. If you think you can fit it (for example
// receives. This means a VPIN state=1 sends D=1 (close turnout // having disabled some of the features above) you can enable it with
// or signal green) in the DCC packet. This can be reversed if // ENABLE_DIAG. You can even disable it on all other CPUs with
// necessary. // DISABLE_DIAG
//#define HAL_ACCESSORY_COMMAND_REVERSE //
// #define DISABLE_DIAG
// If you have issues with that the direction of the accessory commands is // #define ENABLE_DIAG
// reversed (for example when converting from another CS to DCC-EX) then
// you can use this to reverse the sense of all accessory commmands sent /////////////////////////////////////////////////////////////////////////////////////
// over DCC++. This #define likewise inverts the behaviour of the <a> command // REDEFINE WHERE SHORT/LONG ADDR break is. According to NMRA the last short address
// for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a // is 127 and the first long address is 128. There are manufacturers which have
// DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0 // another view. Lenz CS for example have considered addresses long from 100. If
// (throw turnout). // you want to change to that mode, do
//#define DCC_ACCESSORY_RCN_213 //#define HIGHEST_SHORT_ADDR 99
// // If you want to run all your locos addressed long format, you could even do a
// HANDLING MULTIPLE SERIAL THROTTLES //#define HIGHEST_SHORT_ADDR 0
// The command station always operates with the default Serial port. // We do not support to use the same address, for example 100(long) and 100(short)
// Diagnostics are only emitted on the default serial port and not broadcast. // at the same time, there must be a border.
// Other serial throttles may be added to the Serial1, Serial2, Serial3, Serial4,
// Serial5, and Serial6 ports which may or may not exist on your CPU. (Mega has 3, /////////////////////////////////////////////////////////////////////////////////////
// SAMD/SAMC and STM32 have up to 6.) // Some newer 32bit microcontrollers boot very quickly, so powering on I2C and other
// To monitor a throttle on one or more serial ports, uncomment the defines below. // peripheral devices at the same time may result in the CommandStation booting too
// NOTE: do not define here the WiFi shield serial port or your wifi will not work. // quickly to detect them.
// // To work around this, uncomment the STARTUP_DELAY line below and set a value in
//#define SERIAL1_COMMANDS // milliseconds that works for your environment, default is 3000 (3 seconds).
//#define SERIAL2_COMMANDS // #define STARTUP_DELAY 3000
//#define SERIAL3_COMMANDS
//#define SERIAL4_COMMANDS /////////////////////////////////////////////////////////////////////////////////////
//#define SERIAL5_COMMANDS //
//#define SERIAL6_COMMANDS // DEFINE TURNOUTS/ACCESSORIES FOLLOW NORM RCN-213
// //
// BLUETOOTH SERIAL ON ESP32 // According to norm RCN-213 a DCC packet with a 1 is closed/straight
// On ESP32 you have the possibility to use the builtin BT serial to connect to // and one with a 0 is thrown/diverging. In DCC++ Classic, and in previous
// the CS. // versions of DCC++EX, a turnout throw command was implemented in the packet as
// // '1' and a close command as '0'. The #define below makes the states
// The CS shows up as a pairable BT Clasic device. Name is "DCCEX-hexnumber". // match with the norm. But we don't want to cause havoc on existent layouts,
// BT is as an additional serial port, debug messages are still sent over USB, // so we define this only for new installations. If you don't want this,
// not BT serial. // don't add it to your config.h.
// //#define DCC_TURNOUTS_RCN_213
// If you enable this there are some implications:
// 1. WiFi will sleep more (as WiFi and BT share the radio. So WiFi performance // By default, the driver which defines a DCC accessory decoder
// may suffer // does send out the same state change on the DCC packet as it
// 2. The app will be bigger that 1.2MB, so the default partition scheme will not // receives. This means a VPIN state=1 sends D=1 (close turnout
// work any more. You need to choose a partition scheme with 2MB (or bigger). // or signal green) in the DCC packet. This can be reversed if
// For example "NO OTA (2MB APP, 2MB SPIFFS)" in the Arduino IDE. // necessary.
// 3. There is no securuity (PIN) implemented. Everyone in radio range can pair //#define HAL_ACCESSORY_COMMAND_REVERSE
// with your CS.
// // If you have issues with that the direction of the accessory commands is
//#define SERIAL_BT_COMMANDS // reversed (for example when converting from another CS to DCC-EX) then
// you can use this to reverse the sense of all accessory commmands sent
// SABERTOOTH // over DCC++. This #define likewise inverts the behaviour of the <a> command
// // for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a
// This is a very special option and only useful if you happen to have a // DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0
// sabertooth motor controller from dimension engineering configured to // (throw turnout).
// take commands from and ESP32 via serial at 9600 baud from GPIO17 (TX) //#define DCC_ACCESSORY_RCN_213
// and GPIO16 (RX, currently unused). //
// The number defined is the DCC address for which speed controls are sent // HANDLING MULTIPLE SERIAL THROTTLES
// to the sabertooth controller _as_well_. Default: Undefined. // The command station always operates with the default Serial port.
// // Diagnostics are only emitted on the default serial port and not broadcast.
//#define SABERTOOTH 1 // Other serial throttles may be added to the Serial1, Serial2, Serial3, Serial4,
// // Serial5, and Serial6 ports which may or may not exist on your CPU. (Mega has 3,
///////////////////////////////////////////////////////////////////////////////////// // SAMD/SAMC and STM32 have up to 6.)
// // To monitor a throttle on one or more serial ports, uncomment the defines below.
// SENSORCAM // NOTE: do not define here the WiFi shield serial port or your wifi will not work.
// ESP32-CAM based video sensors require #define to use appropriate base vpin number. //
#define SENSORCAM_VPIN 700 //#define SERIAL1_COMMANDS
// For shortcut to vPin number, define CAM for ex-rail use e.g. AT(CAM 012) for S12 etc. //#define SERIAL2_COMMANDS
#define CAM SENSORCAM_VPIN+ //#define SERIAL3_COMMANDS
//#define SERIAL4_COMMANDS
//#define SENSORCAM2_VPIN 600 //define other CAM's if installed. //#define SERIAL5_COMMANDS
//#define CAM2 SENSORCAM2_VPIN+ //for EX-RAIL commands e.g. IFLT(CAM2 020,1)1 //#define SERIAL6_COMMANDS
// //
// For smoother power-up, define a STARTUP_DELAY to allow CAM to initialise ref images // BLUETOOTH SERIAL ON ESP32
#define STARTUP_DELAY 5000 // up to 20sec. CS delay // On ESP32 you have the possibility to use the builtin BT serial to connect to
// the CS.
//
///////////////////////////////////////////////////////////////////////////////////// // The CS shows up as a pairable BT Clasic device. Name is "DCCEX-hexnumber".
// BT is as an additional serial port, debug messages are still sent over USB,
// not BT serial.
//
// If you enable this there are some implications:
// 1. WiFi will sleep more (as WiFi and BT share the radio. So WiFi performance
// may suffer
// 2. The app will be bigger that 1.2MB, so the default partition scheme will not
// work any more. You need to choose a partition scheme with 2MB (or bigger).
// For example "NO OTA (2MB APP, 2MB SPIFFS)" in the Arduino IDE.
// 3. There is no securuity (PIN) implemented. Everyone in radio range can pair
// with your CS.
//
//#define SERIAL_BT_COMMANDS
// BOOSTER PIN INPUT ON ESP32 CS
// On ESP32 you have the possibility to define a pin as booster input
//
// Arduino pin D2 is GPIO 26 is Booster Input on ESPDuino32
//#define BOOSTER_INPUT 26
//
// GPIO 32 is Booster Input on EX-CSB1
//#define BOOSTER_INPUT 32
// ESP32 LED Wifi Indicator
// GPIO 2 on ESPduino32
//#define WIFI_LED 2
//
// GPIO 33 on EX-CSB1
//#define WIFI_LED 33
// SABERTOOTH
//
// This is a very special option and only useful if you happen to have a
// sabertooth motor controller from dimension engineering configured to
// take commands from and ESP32 via serial at 9600 baud from GPIO17 (TX)
// and GPIO16 (RX, currently unused).
// The number defined is the DCC address for which speed controls are sent
// to the sabertooth controller _as_well_. Default: Undefined.
//
//#define SABERTOOTH 1
/////////////////////////////////////////////////////////////////////////////////////

View File

@ -11,9 +11,9 @@
[platformio] [platformio]
default_envs = default_envs =
mega2560 mega2560
uno ; uno
unowifiR2 ; unowifiR2
nano ; nano
samd21-dev-usb samd21-dev-usb
samd21-zero-usb samd21-zero-usb
ESP32 ESP32
@ -164,7 +164,11 @@ monitor_echo = yes
build_flags = -mcall-prologues build_flags = -mcall-prologues
[env:ESP32] [env:ESP32]
platform = espressif32 ; Lock version to 6.7.0 as that is
; Arduino v2.0.16 (based on IDF v4.4.7)
; which is the latest version based
; on IDF v4. We can not use IDF v5.
platform = espressif32 @ 6.7.0
board = esp32dev board = esp32dev
framework = arduino framework = arduino
lib_deps = ${env.lib_deps} lib_deps = ${env.lib_deps}

View File

@ -3,7 +3,34 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.2.59" #define VERSION "5.2.76"
// 5.2.76 - Bugfix: EXRAIL: Catch CV read errors in the callback
// 5.2.75 - Bugfix: Serial lines 4 to 6 OK
// 5.2.74 - Bugfix: ESP32 turn on the joined prog (as main) again after a prog operation
// 5.2.73 - Bugfix: STM32 further fixes to shadowPORT entries in TrackManager.cpp for PORTG and PORTH
// 5.2.72 - Bugfix: added shadowPORT entries in TrackManager.cpp for PORTG and PORTH on STM32, fixed typo in MotorDriver.cpp
// 5.2.71 - Broadcasts of loco forgets.
// 5.2.70 - IO_RocoDriver renamed to IO_EncoderThrottle.
// - and included in IODEvice.h (circular dependency removed)
// 5.2.69 - IO_RocoDriver. Direct drive train with rotary encoder hw.
// 5.2.68 - Revert function map to signed (from 5.2.66) to avoid
// incompatibilities with ED etc for F31 frequency flag.
// 5.2.67 - EXRAIL AFTER optional debounce time variable (default 500mS)
// - AFTER(42) == AFTER(42,500) sets time sensor must
// - be continuously off.
// 5.2.66 - <F cab DCFREQ 0..3>
// - EXRAIL SETFREQ drop loco param (breaking since 5.2.28)
// 5.2.65 - Speedup Exrail SETFREQ
// 5.2.64 - Bugfix: <0 PROG> updated to undo JOIN
// 5.2.63 - Implement WIFI_LED for ESP32, ESPduino32 and EX-CSB1, that is turned on when STA mode connects or AP mode is up
// - Add BOOSTER_INPUT definitions for ESPduino32 and EX-CSB1 to config.example.h
// - Add WIFI_LED definitions for ESPduino32 and EX-CSB1 to config.example.h
// 5.2.62 - Allow acks way longer than standard
// 5.2.61 - Merg CBUS ACON/ACOF/ONACON/ONACOF Adapter interface.
// - LCC Adapter interface throttled startup,
// (Breaking change with Adapter base code)
// 5.2.60 - Bugfix: Opcode AFTEROVERLOAD does not have an argument that is a pin and needs to be initialized
// - Remove inrush throttle after half good time so that we go to mode overload if problem persists
// 5.2.59 - STM32 bugfix correct Serial1 definition for Nucleo-F401RE // 5.2.59 - STM32 bugfix correct Serial1 definition for Nucleo-F401RE
// - STM32 add support for ARDUINO_NUCLEO_F4X9ZI type to span F429/F439 in upcoming STM32duino release v2.8 as a result of our PR // - STM32 add support for ARDUINO_NUCLEO_F4X9ZI type to span F429/F439 in upcoming STM32duino release v2.8 as a result of our PR
// 5.2.58 - EXRAIL ALIAS allows named pins // 5.2.58 - EXRAIL ALIAS allows named pins