#include "Turnout.h"
Public Member Functions | |
void | begin (int id, int add, int subAdd) |
void | set (int id, int add, int subAdd) |
void | activate (int s = 1) |
void | inactivate () |
bool | isActivated () |
Public Attributes | |
struct TurnoutData | data |
Turnout * | nextTurnout |
int | eepromPos |
Static Public Attributes | |
static Turnout * | firstTurnout = NULL |
DCC++ BASE STATION can keep track of the direction of any turnout that is controlled by a DCC stationary accessory decoder.
If the TextCommand is used, all turnouts, as well as any other DCC accessories connected in this fashion, can always be operated using the DCC BASE STATION Accessory command:
<a ADDRESS SUBADDRESS ACTIVATE>
However, this general command simply sends the appropriate DCC instruction packet to the main tracks to operate connected accessories. It does not store or retain any information regarding the current status of that accessory.
To have this sketch store and retain the direction of DCC-connected turnouts, as well as automatically invoke the required command as needed, first define/edit/delete such turnouts using the following variations of the "T" command:
<T ID ADDRESS SUBADDRESS>
creates a new turnout ID, with specified ADDRESS and SUBADDRESS if turnout ID already exists, it is updated with specificed ADDRESS and SUBADDRESS returns: <O> if successful and <X> if unsuccessful (e.g. out of memory)
<T ID>
deletes definition of turnout ID returns: <O> if successful and <X> if unsuccessful (e.g. ID does not exist)
<T>
lists all defined turnouts returns: <H id="" address="" subaddress="" throw>=""> for each defined turnout or <X> if no turnouts defined
where
ID: the numeric ID (0-32767) of the turnout to control ADDRESS: the primary address of the decoder controlling this turnout (0-511) SUBADDRESS: the subaddress of the decoder controlling this turnout (0-3)
Once all turnouts have been properly defined, use the <E> command to store their definitions to EEPROM. If you later make edits/additions/deletions to the turnout definitions, you must invoke the <E> command if you want those new definitions updated in the EEPROM. You can also clear everything stored in the EEPROM by invoking the <e> command.
To "throw" turnouts that have been defined use:
<T ID THROW>
sets turnout ID to either the "thrown" or "unthrown" position returns: <H id="" throw>="">, or <X> if turnout ID does not exist
where
ID: the numeric ID (0-32767) of the turnout to control THROW: 0 (unthrown) or 1 (thrown)
When controlled as such, the Arduino updates and stores the direction of each Turnout in EEPROM so that it is retained even without power. A list of the current directions of each Turnout in the form <H id="" throw>=""> is generated by this sketch whenever the <s> status command is invoked. This provides an efficient way of initializing the directions of any Turnouts being monitored or controlled by a separate interface or GUI program.
Without TextCommand, this is a classic C++ usage. An instance of the structure is created by the user, and fonctions like begin() and activate() can be applied on this instance. load() and store() of the class can still be used (if EEPROM is activated).