mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
format/indentation change only
This commit is contained in:
parent
1934fdd0e1
commit
b0915e8332
|
@ -42,8 +42,7 @@ void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream
|
||||||
if (buffer[0] == '<') {
|
if (buffer[0] == '<') {
|
||||||
clients[clientId]=COMMAND_TYPE;
|
clients[clientId]=COMMAND_TYPE;
|
||||||
DCCEXParser::parse(stream, buffer, ring);
|
DCCEXParser::parse(stream, buffer, ring);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
clients[clientId]=WITHROTTLE_TYPE;
|
clients[clientId]=WITHROTTLE_TYPE;
|
||||||
WiThrottle::getThrottle(clientId)->parse(ring, buffer);
|
WiThrottle::getThrottle(clientId)->parse(ring, buffer);
|
||||||
}
|
}
|
||||||
|
@ -81,19 +80,19 @@ void CommandDistributor::broadcast(bool includeWithrottleClients) {
|
||||||
broadcastBufferWriter->flush();
|
broadcastBufferWriter->flush();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// For a UNO/NANO we can broadcast direct to just one Serial instead of the ring
|
// For a UNO/NANO we can broadcast direct to just one Serial instead of the ring
|
||||||
// Redirect ring output ditrect to Serial
|
// Redirect ring output ditrect to Serial
|
||||||
#define broadcastBufferWriter &Serial
|
#define broadcastBufferWriter &Serial
|
||||||
// and ignore the internal broadcast call.
|
// and ignore the internal broadcast call.
|
||||||
void CommandDistributor::broadcast(bool includeWithrottleClients) {
|
void CommandDistributor::broadcast(bool includeWithrottleClients) {
|
||||||
(void)includeWithrottleClients;
|
(void)includeWithrottleClients;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CommandDistributor::broadcastSensor(int16_t id, bool on ) {
|
void CommandDistributor::broadcastSensor(int16_t id, bool on ) {
|
||||||
StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id);
|
StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id);
|
||||||
broadcast(false);
|
broadcast(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
|
void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
|
||||||
// For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed;
|
// For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed;
|
||||||
|
@ -104,9 +103,9 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
|
||||||
StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id);
|
StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id);
|
||||||
#endif
|
#endif
|
||||||
broadcast(true);
|
broadcast(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDistributor::broadcastLoco(byte slot) {
|
void CommandDistributor::broadcastLoco(byte slot) {
|
||||||
DCC::LOCO * sp=&DCC::speedTable[slot];
|
DCC::LOCO * sp=&DCC::speedTable[slot];
|
||||||
StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %l>\n"),
|
StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %l>\n"),
|
||||||
sp->loco,slot,sp->speedCode,sp->functions);
|
sp->loco,slot,sp->speedCode,sp->functions);
|
||||||
|
@ -133,5 +132,3 @@ void CommandDistributor::broadcastPower() {
|
||||||
LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
|
LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
|
||||||
broadcast(true);
|
broadcast(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ void loop()
|
||||||
// Responsibility 2: handle any incoming commands on USB connection
|
// Responsibility 2: handle any incoming commands on USB connection
|
||||||
SerialManager::loop();
|
SerialManager::loop();
|
||||||
|
|
||||||
// Responsibility 3: Optionally handle any incoming WiFi traffic
|
// Responsibility 3: Optionally handle any incoming WiFi traffic
|
||||||
#if WIFI_ON
|
#if WIFI_ON
|
||||||
WifiInterface::loop();
|
WifiInterface::loop();
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,8 +146,7 @@ void loop()
|
||||||
static int ramLowWatermark = __INT_MAX__; // replaced on first loop
|
static int ramLowWatermark = __INT_MAX__; // replaced on first loop
|
||||||
|
|
||||||
int freeNow = minimumFreeMemory();
|
int freeNow = minimumFreeMemory();
|
||||||
if (freeNow < ramLowWatermark)
|
if (freeNow < ramLowWatermark) {
|
||||||
{
|
|
||||||
ramLowWatermark = freeNow;
|
ramLowWatermark = freeNow;
|
||||||
LCD(3,F("Free RAM=%5db"), ramLowWatermark);
|
LCD(3,F("Free RAM=%5db"), ramLowWatermark);
|
||||||
}
|
}
|
||||||
|
|
37
RMFT2.cpp
37
RMFT2.cpp
|
@ -87,28 +87,28 @@ LookList * RMFT2::onDeactivateLookup=NULL;
|
||||||
#define SKIPOP progCounter+=3
|
#define SKIPOP progCounter+=3
|
||||||
|
|
||||||
|
|
||||||
LookList::LookList(int16_t size) {
|
LookList::LookList(int16_t size) {
|
||||||
m_size=size;
|
m_size=size;
|
||||||
m_loaded=0;
|
m_loaded=0;
|
||||||
if (size) {
|
if (size) {
|
||||||
m_lookupArray=new int16_t[size];
|
m_lookupArray=new int16_t[size];
|
||||||
m_resultArray=new int16_t[size];
|
m_resultArray=new int16_t[size];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LookList::add(int16_t lookup, int16_t result) {
|
void LookList::add(int16_t lookup, int16_t result) {
|
||||||
if (m_loaded==m_size) return; // and forget
|
if (m_loaded==m_size) return; // and forget
|
||||||
m_lookupArray[m_loaded]=lookup;
|
m_lookupArray[m_loaded]=lookup;
|
||||||
m_resultArray[m_loaded]=result;
|
m_resultArray[m_loaded]=result;
|
||||||
m_loaded++;
|
m_loaded++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LookList::find(int16_t value) {
|
int16_t LookList::find(int16_t value) {
|
||||||
for (int16_t i=0;i<m_size;i++) {
|
for (int16_t i=0;i<m_size;i++) {
|
||||||
if (m_lookupArray[i]==value) return m_resultArray[i];
|
if (m_lookupArray[i]==value) return m_resultArray[i];
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void RMFT2::begin() {
|
/* static */ void RMFT2::begin() {
|
||||||
DCCEXParser::setRMFTFilter(RMFT2::ComandFilter);
|
DCCEXParser::setRMFTFilter(RMFT2::ComandFilter);
|
||||||
|
@ -392,7 +392,7 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This emits Routes and Automations to Withrottle
|
// This emits Routes and Automations to Withrottle
|
||||||
|
@ -431,8 +431,7 @@ RMFT2::RMFT2(int progCtr) {
|
||||||
if (loopTask==NULL) {
|
if (loopTask==NULL) {
|
||||||
loopTask=this;
|
loopTask=this;
|
||||||
next=this;
|
next=this;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
next=loopTask->next;
|
next=loopTask->next;
|
||||||
loopTask->next=this;
|
loopTask->next=this;
|
||||||
}
|
}
|
||||||
|
@ -442,8 +441,11 @@ RMFT2::RMFT2(int progCtr) {
|
||||||
RMFT2::~RMFT2() {
|
RMFT2::~RMFT2() {
|
||||||
driveLoco(1); // ESTOP my loco if any
|
driveLoco(1); // ESTOP my loco if any
|
||||||
setFlag(taskId,0,TASK_FLAG); // we are no longer using this id
|
setFlag(taskId,0,TASK_FLAG); // we are no longer using this id
|
||||||
if (next==this) loopTask=NULL;
|
if (next==this)
|
||||||
else for (RMFT2* ring=next;;ring=ring->next) if (ring->next == this) {
|
loopTask=NULL;
|
||||||
|
else
|
||||||
|
for (RMFT2* ring=next;;ring=ring->next)
|
||||||
|
if (ring->next == this) {
|
||||||
ring->next=next;
|
ring->next=next;
|
||||||
loopTask=next;
|
loopTask=next;
|
||||||
break;
|
break;
|
||||||
|
@ -928,7 +930,7 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) {
|
void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) {
|
||||||
// Hunt for an ONTHROW/ONCLOSE for this turnout
|
// Hunt for an ONTHROW/ONCLOSE for this turnout
|
||||||
int pc= (closed?onCloseLookup:onThrowLookup)->find(turnoutId);
|
int pc= (closed?onCloseLookup:onThrowLookup)->find(turnoutId);
|
||||||
if (pc<0) return;
|
if (pc<0) return;
|
||||||
|
@ -946,9 +948,9 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||||
|
|
||||||
task=new RMFT2(pc); // new task starts at this instruction
|
task=new RMFT2(pc); // new task starts at this instruction
|
||||||
task->onTurnoutId=turnoutId; // flag for recursion detector
|
task->onTurnoutId=turnoutId; // flag for recursion detector
|
||||||
}
|
}
|
||||||
|
|
||||||
void RMFT2::activateEvent(int16_t addr, bool activate) {
|
void RMFT2::activateEvent(int16_t addr, bool activate) {
|
||||||
// Hunt for an ONACTIVATE/ONDEACTIVATE for this accessory
|
// Hunt for an ONACTIVATE/ONDEACTIVATE for this accessory
|
||||||
int pc= (activate?onActivateLookup:onDeactivateLookup)->find(addr);
|
int pc= (activate?onActivateLookup:onDeactivateLookup)->find(addr);
|
||||||
if (pc<0) return;
|
if (pc<0) return;
|
||||||
|
@ -966,15 +968,14 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||||
|
|
||||||
task->onActivateAddr=addr; // flag for recursion detector
|
task->onActivateAddr=addr; // flag for recursion detector
|
||||||
task=new RMFT2(pc); // new task starts at this instruction
|
task=new RMFT2(pc); // new task starts at this instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
void RMFT2::printMessage2(const FSH * msg) {
|
void RMFT2::printMessage2(const FSH * msg) {
|
||||||
DIAG(F("EXRAIL(%d) %S"),loco,msg);
|
DIAG(F("EXRAIL(%d) %S"),loco,msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called by emitRouteDescriptions to emit a withrottle description for a route or autoomation.
|
// This is called by emitRouteDescriptions to emit a withrottle description for a route or autoomation.
|
||||||
void RMFT2::emitRouteDescription(Print * stream, char type, int id, const FSH * description) {
|
void RMFT2::emitRouteDescription(Print * stream, char type, int id, const FSH * description) {
|
||||||
StringFormatter::send(stream,F("]\\[%c%d}|{%S}|{%c"),
|
StringFormatter::send(stream,F("]\\[%c%d}|{%S}|{%c"),
|
||||||
type,id,description, type=='R'?'2':'4');
|
type,id,description, type=='R'?'2':'4');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,11 +117,11 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
for(Turnout *tt=Turnout::first();tt!=NULL;tt=tt->next()){
|
for(Turnout *tt=Turnout::first();tt!=NULL;tt=tt->next()){
|
||||||
int id=tt->getId();
|
int id=tt->getId();
|
||||||
StringFormatter::send(stream,F("]\\[%d}|{"), id);
|
StringFormatter::send(stream,F("]\\[%d}|{"), id);
|
||||||
#ifdef RMFT_ACTIVE
|
#ifdef RMFT_ACTIVE
|
||||||
RMFT2::emitTurnoutDescription(stream,id);
|
RMFT2::emitTurnoutDescription(stream,id);
|
||||||
#else
|
#else
|
||||||
StringFormatter::send(stream,F("%d"), id);
|
StringFormatter::send(stream,F("%d"), id);
|
||||||
#endif
|
#endif
|
||||||
StringFormatter::send(stream,F("}|{%c"), Turnout::isClosed(id)?'2':'4');
|
StringFormatter::send(stream,F("}|{%c"), Turnout::isClosed(id)?'2':'4');
|
||||||
}
|
}
|
||||||
StringFormatter::send(stream,F("\n"));
|
StringFormatter::send(stream,F("\n"));
|
||||||
|
@ -137,8 +137,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
// allow heartbeat to slow down once all metadata sent
|
// allow heartbeat to slow down once all metadata sent
|
||||||
StringFormatter::send(stream,F("*%d\n"),HEARTBEAT_SECONDS);
|
StringFormatter::send(stream,F("*%d\n"),HEARTBEAT_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cmd[0]) {
|
while (cmd[0]) {
|
||||||
|
@ -226,6 +224,7 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
if (*cmd!='\0') cmd++; // skip \r or \n
|
if (*cmd!='\0') cmd++; // skip \r or \n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int WiThrottle::getInt(byte * cmd) {
|
int WiThrottle::getInt(byte * cmd) {
|
||||||
int i=0;
|
int i=0;
|
||||||
while (cmd[0]>='0' && cmd[0]<='9') {
|
while (cmd[0]>='0' && cmd[0]<='9') {
|
||||||
|
@ -248,7 +247,7 @@ void WiThrottle::multithrottle(RingStream * stream, byte * cmd){
|
||||||
while(*aval !=';' && *aval !='\0') aval++;
|
while(*aval !=';' && *aval !='\0') aval++;
|
||||||
if (*aval) aval+=2; // skip ;>
|
if (*aval) aval+=2; // skip ;>
|
||||||
|
|
||||||
// DIAG(F("Multithrottle aval=%c cab=%d"), aval[0],locoid);
|
// DIAG(F("Multithrottle aval=%c cab=%d"), aval[0],locoid);
|
||||||
switch(cmd[2]) {
|
switch(cmd[2]) {
|
||||||
case '+': // add loco request
|
case '+': // add loco request
|
||||||
if (cmd[3]=='*') {
|
if (cmd[3]=='*') {
|
||||||
|
@ -351,7 +350,7 @@ void WiThrottle::multithrottle(RingStream * stream, byte * cmd){
|
||||||
|
|
||||||
void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar, int cab){
|
void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar, int cab){
|
||||||
// Note cab=-1 for all cabs in the consist called throttleChar.
|
// Note cab=-1 for all cabs in the consist called throttleChar.
|
||||||
// DIAG(F("Loco Action aval=%c%c throttleChar=%c, cab=%d"), aval[0],aval[1],throttleChar, cab);
|
// DIAG(F("Loco Action aval=%c%c throttleChar=%c, cab=%d"), aval[0],aval[1],throttleChar, cab);
|
||||||
(void) stream;
|
(void) stream;
|
||||||
switch (aval[0]) {
|
switch (aval[0]) {
|
||||||
case 'V': // Vspeed
|
case 'V': // Vspeed
|
||||||
|
@ -411,14 +410,14 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert between DCC++ speed values and WiThrottle speed values
|
// convert between DCC++ speed values and WiThrottle speed values
|
||||||
int WiThrottle::DCCToWiTSpeed(int DCCSpeed) {
|
int WiThrottle::DCCToWiTSpeed(int DCCSpeed) {
|
||||||
if (DCCSpeed == 0) return 0; //stop is stop
|
if (DCCSpeed == 0) return 0; //stop is stop
|
||||||
if (DCCSpeed == 1) return -1; //eStop value
|
if (DCCSpeed == 1) return -1; //eStop value
|
||||||
return DCCSpeed - 1; //offset others by 1
|
return DCCSpeed - 1; //offset others by 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert between WiThrottle speed values and DCC++ speed values
|
// convert between WiThrottle speed values and DCC++ speed values
|
||||||
int WiThrottle::WiTToDCCSpeed(int WiTSpeed) {
|
int WiThrottle::WiTToDCCSpeed(int WiTSpeed) {
|
||||||
if (WiTSpeed == 0) return 0; //stop is stop
|
if (WiTSpeed == 0) return 0; //stop is stop
|
||||||
if (WiTSpeed == -1) return 1; //eStop value
|
if (WiTSpeed == -1) return 1; //eStop value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user