mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Power control plus EXRAIL
Power Control <0 A> etc plus EXRAIL SET_POWER Not yet fully tested.
This commit is contained in:
parent
8052090e0f
commit
aacb980dc8
|
@ -269,6 +269,6 @@ void CommandDistributor::broadcastRaw(clientType type, char * msg) {
|
||||||
broadcastReply(type, F("%s"),msg);
|
broadcastReply(type, F("%s"),msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter,char pmode, int16_t dcAddr) {
|
void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr) {
|
||||||
broadcastReply(COMMAND_TYPE, format,trackLetter,pmode, dcAddr);
|
broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public :
|
||||||
static int16_t retClockTime();
|
static int16_t retClockTime();
|
||||||
static void broadcastPower();
|
static void broadcastPower();
|
||||||
static void broadcastRaw(clientType type,char * msg);
|
static void broadcastRaw(clientType type,char * msg);
|
||||||
static void broadcastTrackState(const FSH* format,byte trackLetter,char pmode, int16_t dcAddr);
|
static void broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr);
|
||||||
template<typename... Targs> static void broadcastReply(clientType type, Targs... msg);
|
template<typename... Targs> static void broadcastReply(clientType type, Targs... msg);
|
||||||
static void forget(byte clientId);
|
static void forget(byte clientId);
|
||||||
|
|
||||||
|
|
|
@ -576,7 +576,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
||||||
uint8_t t = (p[0] - 'A');
|
byte t = (p[0] - 'A');
|
||||||
|
DIAG(F("Processing track - %d "), t);
|
||||||
if (TrackManager::isProg(t)) {
|
if (TrackManager::isProg(t)) {
|
||||||
main = false;
|
main = false;
|
||||||
prog = true;
|
prog = true;
|
||||||
|
@ -587,8 +588,10 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
prog=false;
|
prog=false;
|
||||||
}
|
}
|
||||||
singletrack=true;
|
singletrack=true;
|
||||||
if (main) TrackManager::SetMainTrackPower(POWERMODE::ON, t);
|
DIAG(F("Calling SetPower %d - %d - %d"), POWERMODE::ON, false, t);
|
||||||
if (prog) TrackManager::SetProgTrackPower(POWERMODE::ON, t);
|
if (main) TrackManager::setTrackPower(POWERMODE::ON, t);
|
||||||
|
//if (main) TrackManager::SetMainTrackPower(POWERMODE::ON, t);
|
||||||
|
//if (prog) TrackManager::SetProgTrackPower(POWERMODE::ON, t);
|
||||||
}
|
}
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
}
|
}
|
||||||
|
@ -621,8 +624,9 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
||||||
uint8_t t = (p[0] - 'A');
|
byte t = (p[0] - 'A');
|
||||||
if (TrackManager::isProg(t)) {
|
DIAG(F("Processing track - %d "), t);
|
||||||
|
if (TrackManager::isProg(t)) {
|
||||||
main = false;
|
main = false;
|
||||||
prog = true;
|
prog = true;
|
||||||
}
|
}
|
||||||
|
@ -632,8 +636,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
prog=false;
|
prog=false;
|
||||||
}
|
}
|
||||||
singletrack=true;
|
singletrack=true;
|
||||||
if (main) TrackManager::SetMainTrackPower(POWERMODE::OFF, t);
|
DIAG(F("Calling SetPower %d - %d - %d"), POWERMODE::OFF, false, t);
|
||||||
if (prog) TrackManager::SetProgTrackPower(POWERMODE::OFF, t);
|
if (main) TrackManager::setTrackPower(POWERMODE::OFF, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
|
|
14
EXRAIL2.cpp
14
EXRAIL2.cpp
|
@ -780,6 +780,20 @@ void RMFT2::loop2() {
|
||||||
TrackManager::setJoin(false);
|
TrackManager::setJoin(false);
|
||||||
CommandDistributor::broadcastPower();
|
CommandDistributor::broadcastPower();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPCODE_SET_POWER:
|
||||||
|
// operand is TRACK_POWER , trackid
|
||||||
|
|
||||||
|
switch (operand) {
|
||||||
|
case TRACK_POWER_0:
|
||||||
|
TrackManager::setTrackPower(POWERMODE::OFF, getOperand(1));
|
||||||
|
break;
|
||||||
|
case TRACK_POWER_1:
|
||||||
|
TrackManager::setTrackPower(POWERMODE::ON, getOperand(1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case OPCODE_SET_TRACK:
|
case OPCODE_SET_TRACK:
|
||||||
// operand is trackmode<<8 | track id
|
// operand is trackmode<<8 | track id
|
||||||
|
|
|
@ -59,7 +59,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
|
||||||
OPCODE_ROSTER,OPCODE_KILLALL,
|
OPCODE_ROSTER,OPCODE_KILLALL,
|
||||||
OPCODE_ROUTE,OPCODE_AUTOMATION,OPCODE_SEQUENCE,
|
OPCODE_ROUTE,OPCODE_AUTOMATION,OPCODE_SEQUENCE,
|
||||||
OPCODE_ENDTASK,OPCODE_ENDEXRAIL,
|
OPCODE_ENDTASK,OPCODE_ENDEXRAIL,
|
||||||
OPCODE_SET_TRACK,
|
OPCODE_SET_TRACK,OPCODE_SET_POWER,
|
||||||
OPCODE_ONRED,OPCODE_ONAMBER,OPCODE_ONGREEN,
|
OPCODE_ONRED,OPCODE_ONAMBER,OPCODE_ONGREEN,
|
||||||
OPCODE_ONCHANGE,
|
OPCODE_ONCHANGE,
|
||||||
OPCODE_ONCLOCKTIME,
|
OPCODE_ONCLOCKTIME,
|
||||||
|
|
|
@ -138,6 +138,7 @@
|
||||||
#undef SERVO_SIGNAL
|
#undef SERVO_SIGNAL
|
||||||
#undef SET
|
#undef SET
|
||||||
#undef SET_TRACK
|
#undef SET_TRACK
|
||||||
|
#undef SET_POWER
|
||||||
#undef SETLOCO
|
#undef SETLOCO
|
||||||
#undef SIGNAL
|
#undef SIGNAL
|
||||||
#undef SIGNALH
|
#undef SIGNALH
|
||||||
|
@ -275,6 +276,7 @@
|
||||||
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...)
|
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...)
|
||||||
#define SET(pin)
|
#define SET(pin)
|
||||||
#define SET_TRACK(track,mode)
|
#define SET_TRACK(track,mode)
|
||||||
|
#define SET_POWER(track,onoff)
|
||||||
#define SETLOCO(loco)
|
#define SETLOCO(loco)
|
||||||
#define SIGNAL(redpin,amberpin,greenpin)
|
#define SIGNAL(redpin,amberpin,greenpin)
|
||||||
#define SIGNALH(redpin,amberpin,greenpin)
|
#define SIGNALH(redpin,amberpin,greenpin)
|
||||||
|
|
|
@ -63,6 +63,11 @@
|
||||||
// (10#mins)%100)
|
// (10#mins)%100)
|
||||||
#define STRIP_ZERO(value) 10##value%100
|
#define STRIP_ZERO(value) 10##value%100
|
||||||
|
|
||||||
|
// These constants help EXRAIL macros convert Track Power e.g. SET_POWER(A ON|OFF).
|
||||||
|
//const byte TRACK_POWER_0=0, TRACK_POWER_OFF=0;
|
||||||
|
//const byte TRACK_POWER_1=1, TRACK_POWER_ON=1;
|
||||||
|
|
||||||
|
|
||||||
// Pass 1 Implements aliases
|
// Pass 1 Implements aliases
|
||||||
#include "EXRAIL2MacroReset.h"
|
#include "EXRAIL2MacroReset.h"
|
||||||
#undef ALIAS
|
#undef ALIAS
|
||||||
|
@ -407,11 +412,12 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
|
||||||
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...) OPCODE_SERVOTURNOUT,V(id),OPCODE_PAD,V(pin),OPCODE_PAD,V(activeAngle),OPCODE_PAD,V(inactiveAngle),OPCODE_PAD,V(PCA9685::ProfileType::profile),
|
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...) OPCODE_SERVOTURNOUT,V(id),OPCODE_PAD,V(pin),OPCODE_PAD,V(activeAngle),OPCODE_PAD,V(inactiveAngle),OPCODE_PAD,V(PCA9685::ProfileType::profile),
|
||||||
#define SET(pin) OPCODE_SET,V(pin),
|
#define SET(pin) OPCODE_SET,V(pin),
|
||||||
#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, TRACK_NUMBER_##track),
|
||||||
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
|
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
|
||||||
#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),
|
||||||
#define START(route) OPCODE_START,V(route),
|
#define START(route) OPCODE_START,V(route),
|
||||||
#define STOP OPCODE_SPEED,V(0),
|
#define STOP OPCODE_SPEED,V(0),
|
||||||
#define THROW(id) OPCODE_THROW,V(id),
|
#define THROW(id) OPCODE_THROW,V(id),
|
||||||
#ifndef IO_NO_HAL
|
#ifndef IO_NO_HAL
|
||||||
|
|
|
@ -354,47 +354,32 @@ void TrackManager::streamTrackState(Print* stream, byte t) {
|
||||||
if (track[t]==NULL) return;
|
if (track[t]==NULL) return;
|
||||||
auto format=F("");
|
auto format=F("");
|
||||||
bool pstate = TrackManager::isPowerOn(t);
|
bool pstate = TrackManager::isPowerOn(t);
|
||||||
//char PMODE[] = "OFF";
|
|
||||||
//if (pstate) PMODE="ON ";
|
|
||||||
//if (TrackManager::isPowerOn(t)) {char PMODE[] = "ON";}
|
|
||||||
// else {char PMODE[] = "OFF";}
|
|
||||||
|
|
||||||
switch(track[t]->getMode()) {
|
switch(track[t]->getMode()) {
|
||||||
case TRACK_MODE_MAIN:
|
case TRACK_MODE_MAIN:
|
||||||
format=F("<= %c MAIN %c>\n");
|
if (pstate) {format=F("<= %c MAIN ON \n");} else {format = F("<= %c MAIN OFF \n");}
|
||||||
break;
|
break;
|
||||||
#ifndef DISABLE_PROG
|
#ifndef DISABLE_PROG
|
||||||
case TRACK_MODE_PROG:
|
case TRACK_MODE_PROG:
|
||||||
format=F("<= %c PROG %c>\n");
|
if (pstate) {format=F("<= %c PROG ON>\n");} else {format=F("<= %c PROG OFF>\n");}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case TRACK_MODE_NONE:
|
case TRACK_MODE_NONE:
|
||||||
format=F("<= %c NONE %c>\n");
|
if (pstate) {format=F("<= %c NONE %ON>\n");} else {format=F("<= %c NONE %OFF>\n");}
|
||||||
break;
|
break;
|
||||||
case TRACK_MODE_EXT:
|
case TRACK_MODE_EXT:
|
||||||
format=F("<= %c EXT %c>\n");
|
if (pstate) {format=F("<= %c EXT ON>\n");} else {format=F("<= %c EXT OFF>\n");}
|
||||||
break;
|
break;
|
||||||
case TRACK_MODE_DC:
|
case TRACK_MODE_DC:
|
||||||
format=F("<= %c DC %c %d>\n");
|
if (pstate) {format=F("<= %c DC ON %d>\n");} else {format=F("<= %c DC OFF %d>\n");}
|
||||||
break;
|
break;
|
||||||
case TRACK_MODE_DCX:
|
case TRACK_MODE_DCX:
|
||||||
format=F("<= %c DCX %c %d>\n");
|
if (pstate) {format=F("<= %c DCX ON %d>\n");} else {format=F("<= %c DCX OFF %d>\n");}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break; // unknown, dont care
|
break; // unknown, dont care
|
||||||
}
|
}
|
||||||
switch (pstate) {
|
if (stream) StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]);
|
||||||
case true:
|
else CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]);
|
||||||
if (stream) StringFormatter::send(stream,format,'A'+t,"ON", trackDCAddr[t]);
|
|
||||||
else CommandDistributor::broadcastTrackState(format,'A'+t,"ON", trackDCAddr[t]);
|
|
||||||
break;
|
|
||||||
case false:
|
|
||||||
if (stream) StringFormatter::send(stream,format,'A'+t,"OFF", trackDCAddr[t]);
|
|
||||||
else CommandDistributor::broadcastTrackState(format,'A'+t,"OFF", trackDCAddr[t]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//if (stream) StringFormatter::send(stream,format,'A'+t,PMODE, trackDCAddr[t]);
|
|
||||||
//else CommandDistributor::broadcastTrackState(format,'A'+t,PMODE, trackDCAddr[t]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte TrackManager::nextCycleTrack=MAX_TRACKS;
|
byte TrackManager::nextCycleTrack=MAX_TRACKS;
|
||||||
|
@ -428,10 +413,9 @@ std::vector<MotorDriver *>TrackManager::getMainDrivers() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void TrackManager::setPower2(bool setProg,POWERMODE mode, bool doall, uint8_t thistrack) {
|
void TrackManager::setPower2(bool setProg,POWERMODE mode) {
|
||||||
if (!setProg) mainPowerGuess=mode;
|
if (!setProg) mainPowerGuess=mode;
|
||||||
FOR_EACH_TRACK(t) {
|
FOR_EACH_TRACK(t) {
|
||||||
if (doall==false && thistrack != t) break;
|
|
||||||
MotorDriver * driver=track[t];
|
MotorDriver * driver=track[t];
|
||||||
if (!driver) continue;
|
if (!driver) continue;
|
||||||
switch (track[t]->getMode()) {
|
switch (track[t]->getMode()) {
|
||||||
|
@ -469,9 +453,15 @@ void TrackManager::setPower2(bool setProg,POWERMODE mode, bool doall, uint8_t th
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void TrackManager::setTrackPower(bool progTrack,POWERMODE mode, uint8_t track) {
|
void TrackManager::setTrackPower(POWERMODE mode, byte thistrack) {
|
||||||
// // write the code for this.
|
|
||||||
// }
|
DIAG(F("SetPower Processing Track %d"), thistrack);
|
||||||
|
MotorDriver * driver=track[thistrack];
|
||||||
|
if (!driver) return;
|
||||||
|
|
||||||
|
driver->setPower(mode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
POWERMODE TrackManager::getProgPower() {
|
POWERMODE TrackManager::getProgPower() {
|
||||||
FOR_EACH_TRACK(t)
|
FOR_EACH_TRACK(t)
|
||||||
|
|
|
@ -39,6 +39,10 @@ const byte TRACK_NUMBER_5=5, TRACK_NUMBER_F=5;
|
||||||
const byte TRACK_NUMBER_6=6, TRACK_NUMBER_G=6;
|
const byte TRACK_NUMBER_6=6, TRACK_NUMBER_G=6;
|
||||||
const byte TRACK_NUMBER_7=7, TRACK_NUMBER_H=7;
|
const byte TRACK_NUMBER_7=7, TRACK_NUMBER_H=7;
|
||||||
|
|
||||||
|
// These constants help EXRAIL macros convert Track Power e.g. SET_POWER(A ON|OFF).
|
||||||
|
const byte TRACK_POWER_0=0, TRACK_POWER_OFF=0;
|
||||||
|
const byte TRACK_POWER_1=1, TRACK_POWER_ON=1;
|
||||||
|
|
||||||
class TrackManager {
|
class TrackManager {
|
||||||
public:
|
public:
|
||||||
static void Setup(const FSH * shieldName,
|
static void Setup(const FSH * shieldName,
|
||||||
|
@ -60,12 +64,13 @@ class TrackManager {
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
static std::vector<MotorDriver *>getMainDrivers();
|
static std::vector<MotorDriver *>getMainDrivers();
|
||||||
#endif
|
#endif
|
||||||
static void setPower2(bool progTrack,POWERMODE mode, bool doall, uint8_t thistrack);
|
static void setTrackPower(POWERMODE mode, byte thistrack);
|
||||||
|
static void setPower2(bool progTrack,POWERMODE mode);
|
||||||
static void setPower(POWERMODE mode) {setMainPower(mode); setProgPower(mode);}
|
static void setPower(POWERMODE mode) {setMainPower(mode); setProgPower(mode);}
|
||||||
static void setMainPower(POWERMODE mode) {setPower2(false,mode,true,0);}
|
static void setMainPower(POWERMODE mode) {setPower2(false,mode);}
|
||||||
static void setProgPower(POWERMODE mode) {setPower2(true,mode,true,0);}
|
static void setProgPower(POWERMODE mode) {setPower2(true,mode);}
|
||||||
static void SetMainTrackPower(POWERMODE mode, uint8_t track) {setPower2(false,mode,false,track);}
|
|
||||||
static void SetProgTrackPower(POWERMODE mode, uint8_t track) {setPower2(true,mode,false,track);}
|
|
||||||
|
|
||||||
static const int16_t MAX_TRACKS=8;
|
static const int16_t MAX_TRACKS=8;
|
||||||
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
|
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user