Commanders
Arduino buttons/bus library
|
#include "DccCommander.hpp"
Public Member Functions | |
DccCommanderClass () | |
void | begin (int i, int j, int k, boolean inInterruptMonitor = false, boolean inUseRawDccAddresses = false) |
void | PriorityLoop () |
unsigned long | loop () |
unsigned long | GetLastDccId () |
void | printCommander () |
Static Public Member Functions | |
static void | SetAccessoryDecoderPacketHandler (DccAccDecoderPacket func) |
static void | DccAccessoryDecoderPacket (int address, boolean activate, uint8_t data) |
static DccCommanderClass & | GetCurrent () |
static void | printEvent (unsigned long inId, COMMANDERS_EVENT_TYPE inEventType, int inEventData) |
This commanders receive accessory packets from DCC controler, and convert it in Commanders events. The event id is a compressed version of dcc id and dcc accessory id.
Text from NMRA standard definition (https://www.nmra.org/sites/default/files/s-9.2.1_2012_07.pdf , paragraph 420):
The format for packets intended for Accessory Digital Decoders is:
{preamble} 0 10AAAAAA 0 1AAACDDD 0 EEEEEEEE 1Accessory Digital Decoders can be designed to control momentary or constant-on devices, the duration of time each output is active being controlled by configuration variables CVs #515 through 518. Bit 3 of the second byte "C" is used to activate or deactivate the addressed device. (Note if the duration the device is intended to be on is less than or equal the set duration, no deactivation is necessary.) Since most devices are paired, the convention is that bit "0" of the second byte is used to distinguish between which of a pair of outputs the accessory decoder is activating or 430 deactivating. Bits 1 and 2 of byte two are used to indicate which of 4 pairs of outputs the packet is controlling. The most significant bits of the 9-bit address are bits 4-6 of the second data byte. By convention these bits (bits 4-6 of the second data byte) are in ones complement.
When an accessory is activated through my MS2, these packets are sent:
id / data / 1 id / data / 1 id / data / 1 id / data / 0
In the Commanders interpretation of a DCC packet, id is given by 'A' bits, data from the 'D' bits, and the activate flag by the 'C' bit. The id is not the number you can see on a MS2, and on most DCC controlers. There is a small computation between id and data to obtain the real MS2 accessory number : real_id (1 to 320) and real_data (0 or 1 for right or left). It works on all known controlers, except on Multimaus...
The translated id and the activation flag are then translated into an unsigned long to be used as a Commanders id. The formula is
real_data * 10000 + real_id .
DCCINT is the macro used to build the unsigned long, DCCID the one to use to get the real id number from this long int, and DCCACTIVATION the other to get the real_data.
This flag is to activate for a while (three times at 1 !) and then desactivate the motor ! DccCommander will react only on the desactivate flag to avoid double events.
Events thrown:
reason | id | type | data |
---|---|---|---|
data = 0 | accessory id | COMMANDERS_EVENT_MOVE | COMMANDERS_MOVE_RIGHT |
data = 1 | accessory id | COMMANDERS_EVENT_MOVE | COMMANDERS_MOVE_LEFT |
Definition at line 73 of file DccCommander.hpp.
|
inline |
Default constructor.
Definition at line 83 of file DccCommander.hpp.
void DccCommanderClass::begin | ( | int | i, |
int | j, | ||
int | k, | ||
boolean | inInterruptMonitor = false , |
||
boolean | inUseRawDccAddresses = false |
||
) |
Initialize the instance.
i | Manufacturer ID of this decoder. Can be 0 in common case... |
j | Manufacturer version number for this decoder. Can be 0 in common case... |
k | Interrupt number used by DCC_Decoder. The interrupt is raised when a signal is detected on the associated pin. |
inInterruptMonitor | If true, ths Commnaders status led will blink when DccCommander receive a new accessory packet. Default is false. |
inUseRawDccAddresses | Dcc id and accessory id are converted into a more readable way to be used, but if this flag is true, the original values can be preserved instead of these converted value. Default is false. |
Definition at line 97 of file DccCommander.cpp.
|
static |
Decode the packet data, and raise a Commander event.
address | raw address of the decoder, directly got from the DCC packet. |
activate | flag from the DCC packet. True means activate the accessory motor. |
data | additionnal data, adding bits to decoder accessory, and including the number of the accessory. |
Definition at line 23 of file DccCommander.cpp.
|
inlinestatic |
Get the current instance of DccCommanderClass
Definition at line 115 of file DccCommander.hpp.
|
inline |
Gets the last DCC id received.
Definition at line 109 of file DccCommander.hpp.
|
virtual |
void DccCommanderClass::printCommander | ( | ) |
Print this commander on the console.
Definition at line 230 of file DccCommander.cpp.
|
static |
Print thhe given event on the console.
Definition at line 179 of file DccCommander.cpp.
|
virtual |
Priority loop function. Just a new call to the loop function. By this way, the DCC commander loop is sure to be called two or more times when other commanders are only called once !
Reimplemented from Commander.
Definition at line 118 of file DccCommander.cpp.
|
static |
Set the callback function whih will be called when an accessory packet will be decoded. Set it to NULL or 0 to inactivate this function.
Definition at line 173 of file DccCommander.cpp.