1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

Merge branch 'master' into TrackManager

This commit is contained in:
Asbelos 2022-03-07 18:40:32 +00:00
commit 4437f870b6
10 changed files with 67 additions and 43 deletions

View File

@ -136,3 +136,8 @@ 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);
} }
void CommandDistributor::broadcastText(const FSH * msg) {
StringFormatter::send(broadcastBufferWriter,F("%S"),msg);
broadcast(false);
}

View File

@ -32,6 +32,7 @@ public :
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 broadcastPower(); static void broadcastPower();
static void broadcastText(const FSH * msg);
static void forget(byte clientId); static void forget(byte clientId);
private: private:
static void broadcast(bool includeWithrottleClients); static void broadcast(bool includeWithrottleClients);

View File

@ -42,8 +42,9 @@
#include "Turnouts.h" #include "Turnouts.h"
#include "Sensors.h" #include "Sensors.h"
#include "Outputs.h" #include "Outputs.h"
#include "EXRAIL.h"
#include "CommandDistributor.h" #include "CommandDistributor.h"
#include "TrackManager.h" #include "TrackManager.h"
#include "DCCTimer.h" #include "DCCTimer.h"
#include "EXRAIL.h"
#endif #endif

View File

@ -67,11 +67,11 @@ const int16_t HASH_KEYWORD_ROUTES=-3702;
// One instance of RMFT clas is used for each "thread" in the automation. // One instance of RMFT clas is used for each "thread" in the automation.
// Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation. // Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation.
// The thrrads exist in a ring, each time through loop() the next thread in the ring is serviced. // The threads exist in a ring, each time through loop() the next thread in the ring is serviced.
// Statics // Statics
const int16_t LOCO_ID_WAITING=-99; // waiting for loco id from prog track const int16_t LOCO_ID_WAITING=-99; // waiting for loco id from prog track
int16_t RMFT2::progtrackLocoId; // used for callback when detecting a loco on prograck int16_t RMFT2::progtrackLocoId; // used for callback when detecting a loco on prog track
bool RMFT2::diag=false; // <D EXRAIL ON> bool RMFT2::diag=false; // <D EXRAIL ON>
RMFT2 * RMFT2::loopTask=NULL; // loopTask contains the address of ONE of the tasks in a ring. RMFT2 * RMFT2::loopTask=NULL; // loopTask contains the address of ONE of the tasks in a ring.
RMFT2 * RMFT2::pausingTask=NULL; // Task causing a PAUSE. RMFT2 * RMFT2::pausingTask=NULL; // Task causing a PAUSE.
@ -809,6 +809,12 @@ void RMFT2::loop2() {
CommandDistributor::broadcastPower(); CommandDistributor::broadcastPower();
break; break;
case OPCODE_POWERON:
DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON);
DCC::setProgTrackSyncMain(false);
CommandDistributor::broadcastPower();
break;
case OPCODE_UNJOIN: case OPCODE_UNJOIN:
DCCWaveform::setJoin(false); DCCWaveform::setJoin(false);
CommandDistributor::broadcastPower(); CommandDistributor::broadcastPower();
@ -884,13 +890,13 @@ void RMFT2::loop2() {
break; break;
case OPCODE_AUTOSTART: // Handled only during begin process case OPCODE_AUTOSTART: // Handled only during begin process
case OPCODE_PAD: // Just a padding for previous opcode needing >1 operad byte. case OPCODE_PAD: // Just a padding for previous opcode needing >1 operand byte.
case OPCODE_TURNOUT: // Turnout definition ignored at runtime case OPCODE_TURNOUT: // Turnout definition ignored at runtime
case OPCODE_SERVOTURNOUT: // Turnout definition ignored at runtime case OPCODE_SERVOTURNOUT: // Turnout definition ignored at runtime
case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime
case OPCODE_ONCLOSE: // Turnout event catcers ignored here case OPCODE_ONCLOSE: // Turnout event catchers ignored here
case OPCODE_ONTHROW: case OPCODE_ONTHROW:
case OPCODE_ONACTIVATE: // Activate event catcers ignored here case OPCODE_ONACTIVATE: // Activate event catchers ignored here
case OPCODE_ONDEACTIVATE: case OPCODE_ONDEACTIVATE:
break; break;

View File

@ -32,6 +32,7 @@
#undef ATTIMEOUT #undef ATTIMEOUT
#undef AUTOMATION #undef AUTOMATION
#undef AUTOSTART #undef AUTOSTART
#undef BROADCAST
#undef CALL #undef CALL
#undef CLOSE #undef CLOSE
#undef DEACTIVATE #undef DEACTIVATE
@ -124,6 +125,7 @@
#define ATTIMEOUT(sensor_id,timeout_ms) #define ATTIMEOUT(sensor_id,timeout_ms)
#define AUTOMATION(id, description) #define AUTOMATION(id, description)
#define AUTOSTART #define AUTOSTART
#define BROADCAST(msg)
#define CALL(route) #define CALL(route)
#define CLOSE(id) #define CLOSE(id)
#define DEACTIVATE(addr,subaddr) #define DEACTIVATE(addr,subaddr)

View File

@ -69,6 +69,8 @@ void RMFT2::emitWithrottleDescriptions(Print * stream) {
// Pass 3... Create Text sending functions // Pass 3... Create Text sending functions
#include "EXRAIL2MacroReset.h" #include "EXRAIL2MacroReset.h"
const int StringMacroTracker1=__COUNTER__; const int StringMacroTracker1=__COUNTER__;
#undef BROADCAST
#define BROADCAST(msg) case (__COUNTER__ - StringMacroTracker1) : CommandDistributor::broadcastText(F(msg));break;
#undef PRINT #undef PRINT
#define PRINT(msg) case (__COUNTER__ - StringMacroTracker1) : printMessage2(F(msg));break; #define PRINT(msg) case (__COUNTER__ - StringMacroTracker1) : printMessage2(F(msg));break;
#undef LCN #undef LCN
@ -170,6 +172,7 @@ const FLASH int16_t RMFT2::SignalDefinitions[] = {
#define ATTIMEOUT(sensor_id,timeout) OPCODE_ATTIMEOUT1,0,0,OPCODE_ATTIMEOUT2,V(sensor_id),OPCODE_PAD,V(timeout/100L), #define ATTIMEOUT(sensor_id,timeout) OPCODE_ATTIMEOUT1,0,0,OPCODE_ATTIMEOUT2,V(sensor_id),OPCODE_PAD,V(timeout/100L),
#define AUTOMATION(id, description) OPCODE_AUTOMATION, V(id), #define AUTOMATION(id, description) OPCODE_AUTOMATION, V(id),
#define AUTOSTART OPCODE_AUTOSTART,0,0, #define AUTOSTART OPCODE_AUTOSTART,0,0,
#define BROADCAST(msg) PRINT(msg)
#define CALL(route) OPCODE_CALL,V(route), #define CALL(route) OPCODE_CALL,V(route),
#define CLOSE(id) OPCODE_CLOSE,V(id), #define CLOSE(id) OPCODE_CLOSE,V(id),
#define DEACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1), #define DEACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1),

View File

@ -519,25 +519,32 @@ char WiThrottle::stashThrottleChar;
void WiThrottle::getLocoCallback(int16_t locoid) { void WiThrottle::getLocoCallback(int16_t locoid) {
stashStream->mark(stashClient); stashStream->mark(stashClient);
if (locoid<=0) if (locoid<=0) {
StringFormatter::send(stashStream,F("HMNo loco found on prog track\n")); StringFormatter::send(stashStream,F("HMNo loco found on prog track\n"));
else { stashStream->commit(); // done here, commit and return
// short or long return;
char addrchar;
if (locoid & LONG_ADDR_MARKER) { // long addr
locoid = locoid ^ LONG_ADDR_MARKER;
addrchar = 'L';
} else
addrchar = 'S';
if (addrchar == 'L' && locoid <= HIGHEST_SHORT_ADDR )
StringFormatter::send(stashStream,F("HMLong addr %d <= %d not supported\n"), locoid,HIGHEST_SHORT_ADDR);
else {
char addcmd[20]={'M',stashThrottleChar,'+', addrchar};
itoa(locoid,addcmd+4,10);
stashInstance->multithrottle(stashStream, (byte *)addcmd);
TrackManager::setMainPower(POWERMODE::ON);
DCCWaveform::setJoin(true); // <1 JOIN> so we can drive loco away
}
} }
// short or long
char addrchar;
if (locoid & LONG_ADDR_MARKER) { // maker bit indicates long addr
locoid = locoid ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr
if (locoid <= HIGHEST_SHORT_ADDR ) { // out of range for long addr
StringFormatter::send(stashStream,F("HMLong addr %d <= %d unsupported\n"), locoid, HIGHEST_SHORT_ADDR);
stashStream->commit(); // done here, commit and return
return;
}
addrchar = 'L';
} else {
addrchar = 'S';
}
char addcmd[20]={'M',stashThrottleChar,'+', addrchar};
itoa(locoid,addcmd+4,10);
stashInstance->multithrottle(stashStream, (byte *)addcmd);
DCCWaveform::progTrack.setPowerMode(POWERMODE::ON);
DCC::setProgTrackSyncMain(true); // <1 JOIN> so we can drive loco away
stashStream->commit(); stashStream->commit();
CommandDistributor::broadcastPower();
} }

View File

@ -29,7 +29,7 @@ The configuration file for DCC-EX Command Station
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// 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 resitor 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.
// //
@ -85,7 +85,7 @@ The configuration file for DCC-EX Command Station
// 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 conain ``"'' (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
@ -129,6 +129,9 @@ The configuration file for DCC-EX Command Station
// #define OLED_DRIVER 128,32 // #define OLED_DRIVER 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 1 is by page (alternate between pages),
// * #define SCROLLMODE 2 is by row (move up 1 row at a time).
#define SCROLLMODE 1 #define SCROLLMODE 1
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
@ -137,7 +140,7 @@ The configuration file for DCC-EX Command Station
// If you do not need the EEPROM at all, you can disable all the code that saves // 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 // data in the EEPROM. You might want to do that if you are in a Arduino UNO
// and want to use the EX-RAIL automation. Otherwise you do not have enough RAM // and want to use the EX-RAIL automation. Otherwise you do not have enough RAM
// to do that. Of course, then none of the EEPROM related commands works. // to do that. Of course, then none of the EEPROM related commands work.
// //
// #define DISABLE_EEPROM // #define DISABLE_EEPROM
@ -174,7 +177,7 @@ The configuration file for DCC-EX Command Station
// If you have issues with that the direction of the accessory commands is // If you have issues with that the direction of the accessory commands is
// reversed (for example when converting from another CS to DCC-EX) then // reversed (for example when converting from another CS to DCC-EX) then
// you can use this to revese the sense of all accessory commmands sent // 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 // 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 // for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a
// DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0 // DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0

View File

@ -1,19 +1,18 @@
/* This is an automation example file. /* This is an automation example file.
* The presence of a file called "myAutomation.h" brings EX-RAIL code into * The presence of a file called "myAutomation.h" brings EX-RAIL code into
* the command station. * the command station.
* The auotomation may have multiple concurrent tasks. * The automation may have multiple concurrent tasks.
* A task may * A task may
* - Act as a ROUTE setup macro for a user to drive over * - Act as a ROUTE setup macro for a user to drive over
* - drive a loco through an AUTOMATION * - drive a loco through an AUTOMATION
* - automate some cosmetic part of the layout without any loco. * - automate some cosmetic part of the layout without any loco.
* *
* At startup, a single task is created to execute the first * At startup, a single task is created to execute the startup sequence.
* instruction after E$XRAIL.
* This task may simply follow a route, or may START * This task may simply follow a route, or may START
* further tasks (thats is.. send a loco out along a route). * further tasks (that is.. send a loco out along a route).
* *
* Where the loco id is not known at compile time, a new task * Where the loco id is not known at compile time, a new task
* can be creatd with the command: * can be created with the command:
* </ START [cab] route> * </ START [cab] route>
* *
* A ROUTE, AUTOMATION or SEQUENCE are internally identical in ExRail terms * A ROUTE, AUTOMATION or SEQUENCE are internally identical in ExRail terms
@ -24,11 +23,10 @@
* *
*/ */
EXRAIL // myAutomation must start with the EXRAIL instruction // This is the startup sequence, AKA SEQUENCE(0)
// This is the default starting route, AKA SEQUENCE(0) SENDLOCO(3,1) // send loco 3 off along route 1
SENDLOCO(3,1) // send loco 3 off along route 1 SENDLOCO(10,2) // send loco 10 off along route 2
SENDLOCO(10,2) // send loco 10 off along route 2 DONE // This just ends the startup thread, leaving 2 others running.
DONE // This just ends the startup thread, leaving 2 others running.
/* SEQUENCE(1) is a simple shuttle between 2 sensors /* SEQUENCE(1) is a simple shuttle between 2 sensors
* S20 and S21 are sensors on arduino pins 20 and 21 * S20 and S21 are sensors on arduino pins 20 and 21
@ -78,7 +76,3 @@ EXRAIL // myAutomation must start with the EXRAIL instruction
AT(33) STOP AT(33) STOP
DELAY(20000) // wait 20 seconds DELAY(20000) // wait 20 seconds
FOLLOW(2) // follow sequence 2... ie repeat the process FOLLOW(2) // follow sequence 2... ie repeat the process
ENDEXRAIL // marks the end of the EXRAIL program.

View File

@ -3,7 +3,9 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "4.0.0" #define VERSION "4.0.1"
// 4.0.1 EXRAIL BROADCAST("msg")
// EXRAIL POWERON
// 4.0.0 Major functional and non-functional changes. // 4.0.0 Major functional and non-functional changes.
// Engine Driver "DriveAway" feature enhancement // Engine Driver "DriveAway" feature enhancement
//.......JMRI feature enhancement. Provides for multiple additional DCC++EX wifi //.......JMRI feature enhancement. Provides for multiple additional DCC++EX wifi