DCCpp
This is the library version of a program for Arduino to control railroading DCC devices.
DCCpp Class Reference

#include "DCCpp.hpp"

Static Public Member Functions

static void begin ()
 
static void beginMain (uint8_t inOptionalDirectionMotor, uint8_t inSignalPin, uint8_t inSignalEnablePin, uint8_t inCurrentMonitor)
 
static void beginProg (uint8_t inOptionalDirectionMotor, uint8_t inSignalPin, uint8_t inSignalEnablePin, uint8_t inCurrentMonitor)
 
static void beginMainMotorShield ()
 
static void beginProgMotorShield ()
 
static void beginMainPololu ()
 
static void beginProgPololu ()
 
static bool IsMainTrack (volatile RegisterList *apRegs)
 
static void loop ()
 
static void panicStop (bool inStop)
 
static void powerOn ()
 
static void powerOff ()
 
static void setCurrentSampleMaxMain (float inMax)
 
static void setCurrentSampleMaxProg (float inMax)
 
static float getCurrentMain ()
 
static float getCurrentProg ()
 
static bool setSpeedMain (int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inForward)
 
static int identifyLocoIdMain ()
 
static int readCvMain (int inCvId, int callBack = 100, int callBackSub = 200)
 
static void writeCvMain (int inCvId, byte inValue, int callBack = 100, int callBackSub = 200)
 
static void setFunctionsMain (int nReg, int inLocoId, FunctionsState &inStates)
 
static bool setSpeedProg (int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inForward)
 
static int identifyLocoIdProg ()
 
static int readCvProg (int inCvId, int callBack = 100, int callBackSub = 200)
 
static void writeCvProg (int inCvId, byte inValue, int callBack = 100, int callBackSub = 200)
 
static void setFunctionsProg (int nReg, int inLocoId, FunctionsState &inStates)
 
static void setAccessory (int inAddress, byte inSubAddress, byte inActivate)
 

Static Public Attributes

static volatile RegisterList mainRegs
 
static volatile RegisterList progRegs
 
static CurrentMonitor mainMonitor
 
static CurrentMonitor progMonitor
 

Detailed Description

This is the main class of the library. All data and functions are static. There is no needs to instantiate this class.

Definition at line 70 of file DCCpp.hpp.

Member Function Documentation

void begin ( )
static

Begins the DCCpp library.

Definition at line 293 of file DCCpp.cpp.

void beginMain ( uint8_t  inOptionalDirectionMotor,
uint8_t  inSignalPin,
uint8_t  inSignalEnablePin,
uint8_t  inCurrentMonitor 
)
static

Initializes the main track.

Parameters
inOptionalDirectionMotorPin for the rerouting of shields direction pin, set it to UNDEFINED_PIN if not used.
inSignalPinPin for the signal pin, the one driven by an interruption, set it to UNDEFINED_PIN if not used (but the line will be always down...).
inSignalEnablePinPin for the enable/PWM pin, set it to UNDEFINED_PIN if not used.
inCurrentMonitorPin for the current monitor analog pin, set it to UNDEFINED_PIN if not used.

Definition at line 117 of file DCCpp.cpp.

void beginProg ( uint8_t  inOptionalDirectionMotor,
uint8_t  inSignalPin,
uint8_t  inSignalEnablePin,
uint8_t  inCurrentMonitor 
)
static

Initializes the programming track.

Parameters
inOptionalDirectionMotorPin for the rerouting of shields direction pin, set it to UNDEFINED_PIN if not used.
inSignalPinPin for the signal pin, the one driven by an interruption, set it to UNDEFINED_PIN if not used (but the line will be always down...).
inSignalEnablePinPin for the enable/PWM pin, set it to UNDEFINED_PIN if not used.
inCurrentMonitorPin for the current monitor analog pin, set it to UNDEFINED_PIN if not used.

Definition at line 182 of file DCCpp.cpp.

static void beginMainMotorShield ( )
static

Initializes the main track for an Arduino Motor Shield.

Definition at line 109 of file DCCpp.hpp.

static void beginProgMotorShield ( )
static

Initializes the programming track for an Arduino Motor Shield.

Definition at line 112 of file DCCpp.hpp.

static void beginMainPololu ( )
static

Initializes the main track for a Pololu MC33926 Motor Shield.

Definition at line 116 of file DCCpp.hpp.

static void beginProgPololu ( )
static

Initializes the programming track for a Pololu MC33926 Motor Shield.

Definition at line 119 of file DCCpp.hpp.

static bool IsMainTrack ( volatile RegisterList apRegs)
static

Checks if the given RegisterList is from the main track or not.

Parameters
apRegsRegisterList to check.
Returns
true if the RegisterList is mainRegs, the one from the main track.

Definition at line 135 of file DCCpp.hpp.

void loop ( )
static

Main loop function of the library.

Definition at line 92 of file DCCpp.cpp.

void panicStop ( bool  inStop)
static

Stop/restore the power on all the tracks.

Parameters
inStopIf true, stop the power, otherwise restore the power.

Definition at line 531 of file DCCpp.cpp.

void powerOn ( )
static

Stop the power on all the tracks.

Definition at line 548 of file DCCpp.cpp.

void powerOff ( )
static

Restore the power on all the tracks.

Definition at line 560 of file DCCpp.cpp.

static void setCurrentSampleMaxMain ( float  inMax)
static

Set the maximum current value before an event 'too much current consumption detected !' for main track.

Parameters
inMaxMaximum value between 0 and 1023. Default is 300.

Definition at line 157 of file DCCpp.hpp.

static void setCurrentSampleMaxProg ( float  inMax)
static

Set the maximum current value before an event 'too much current consumption detected !' for programming track.

Parameters
inMaxMaximum value between 0 and 1023. Default is 300.

Definition at line 162 of file DCCpp.hpp.

static float getCurrentMain ( )
static

Get the actual analog level for the current detection pin for the main track.

Returns
Current value between 0 and 1023 using an exponential smoother...

Definition at line 167 of file DCCpp.hpp.

static float getCurrentProg ( )
static

Get the actual analog level for the current detection pin for the programming track.

Returns
Current value between 0 and 1023.

Definition at line 172 of file DCCpp.hpp.

static bool setSpeedMain ( int  nReg,
int  inLocoId,
int  inStepsNumber,
int  inNewSpeed,
bool  inForward 
)
static

For the given decoder id, set the speed and the direction on the main track.

Parameters
nRegRegister number. Avoid register 0, used for one shot commands like accessories or CV programming.
inLocoIdDecoder address in short or long format.
inStepsNumberAccording to the decoder configuration, set it to 14, 28 or 128 .
inNewSpeedSpeed of the loco, between 2 and the steps number - 1 (13, 27 or 127). 0 means normal complete stop. 1 means emergency stop.
inForwardTrue means forward move, false means backward.

Definition at line 183 of file DCCpp.hpp.

static int identifyLocoIdMain ( )
static

Try to identify the address of a decoder on the main track. Be sure there is only one loco on the track to call this function !

Returns
CV 1 value: the loco decoder Id or -1 if no decoder identified.

Definition at line 188 of file DCCpp.hpp.

static int readCvMain ( int  inCvId,
int  callBack = 100,
int  callBackSub = 200 
)
static

Try to read a CV from a decoder on the main track. Be sure there is only one loco on the track before calling this function !

Parameters
inCvIdCV id from 0 to 255.
callBackan arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs that call this function. Default 100.
callBackSuba second arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs (e.g. DCC++ Interface) that call this function. Default 200
Returns
CV value: the CV value if the value cannot be read.

Definition at line 197 of file DCCpp.hpp.

static void writeCvMain ( int  inCvId,
byte  inValue,
int  callBack = 100,
int  callBackSub = 200 
)
static

Write the given CV on the main track. Be sure there is only one loco on the track before calling this function !

Parameters
inCvIdCV id from 0 to 255.
inValueCV new value from 0 to 255.
callBackan arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs that call this function. Default 100.
callBackSuba second arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs (e.g. DCC++ Interface) that call this function. Default 200

Definition at line 206 of file DCCpp.hpp.

static void setFunctionsMain ( int  nReg,
int  inLocoId,
FunctionsState inStates 
)
static

Set the functions states of the given decoder on the main track.

Parameters
nRegRegister number. Avoid register 0, used for one shot commands like accessories or CV programming.
inLocoIdDecoder address in short or long format.
inStatesFunctionsState class with the wanted new status.

Definition at line 213 of file DCCpp.hpp.

static bool setSpeedProg ( int  nReg,
int  inLocoId,
int  inStepsNumber,
int  inNewSpeed,
bool  inForward 
)
static

For the given decoder id, set the speed and the direction on the programming track.

Parameters
nRegRegister number. Avoid register 0, used for one shot commands like accessories or CV programming.
inLocoIdDecoder address in short or long format.
inStepsNumberAccording to the decoder configuration, set it to 14, 28 or 128 .
inNewSpeedSpeed of the loco, between 2 and the steps number - 1 (13, 27 or 127). 0 means normal complete stop. 1 means emergency stop.
inForwardTrue means forward move, false means backward.

Definition at line 224 of file DCCpp.hpp.

static int identifyLocoIdProg ( )
static

Try to identify the address of a decoder on the programming track. Be sure there is only one loco on the track to call this function !

Returns
CV 1 value: the loco decoder Id or -1 if no decoder identified.

Definition at line 229 of file DCCpp.hpp.

static int readCvProg ( int  inCvId,
int  callBack = 100,
int  callBackSub = 200 
)
static

Try to read a CV from a decoder on the programming track. Be sure there is only one loco on the track before calling this function !

Parameters
inCvIdCV id from 0 to 255.
callBackan arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs that call this function. Default 100.
callBackSuba second arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs (e.g. DCC++ Interface) that call this function. Default 200
Returns
CV value: the CV value if the value cannot be read.

Definition at line 238 of file DCCpp.hpp.

static void writeCvProg ( int  inCvId,
byte  inValue,
int  callBack = 100,
int  callBackSub = 200 
)
static

Write the given CV on the programming track.

Parameters
inCvIdCV id from 0 to 255.
inValueCV new value from 0 to 255.
callBackan arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs that call this function. Default 100.
callBackSuba second arbitrary integer (0-32767) that is ignored by the Base Station and is simply echoed back in the output - useful for external programs (e.g. DCC++ Interface) that call this function. Default 200

Definition at line 246 of file DCCpp.hpp.

static void setFunctionsProg ( int  nReg,
int  inLocoId,
FunctionsState inStates 
)
static

Set the functions states of the given decoder on the programming track.

Parameters
nRegRegister number. Avoid register 0, used for one shot commands like accessories or CV programming.
inLocoIdDecoder address in short or long format.
inStatesFunctionsState class with the wanted new status.

Definition at line 253 of file DCCpp.hpp.

void setAccessory ( int  inAddress,
byte  inSubAddress,
byte  inActivate 
)
static

Activates or not the given accessory

Parameters
inAddressmain address of the accessory decoder, from 0 to 511.
inSubAddressaccessory number inside the decoder, from 0 to 3.
inActivateTrue to activate the accessory, false to deactivate.

Definition at line 755 of file DCCpp.cpp.