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 beginMainDccSignal (uint8_t inSignalPin)
 
static void beginProgDccSignal (uint8_t inSignalPin)
 
static void setDebugDccMode ()
 
static bool IsMainTrack (volatile RegisterList *apRegs)
 
static void loop ()
 
static void panicStop (bool inStop)
 
static void powerOn (bool inMain=true, bool inProg=true)
 
static void powerOff (bool inMain=true, bool inProg=true)
 
static byte setAckThreshold (byte inNewValue)
 
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 byte ackThreshold = 0
 
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 DCCpp::begin ( )
static

Begins the DCCpp library.

Definition at line 186 of file DCCpp.cpp.

void DCCpp::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 119 of file DCCpp.cpp.

static void DCCpp::beginMainDccSignal ( uint8_t  inSignalPin)
static

Initializes the main track.

Parameters
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...).
void DCCpp::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 157 of file DCCpp.cpp.

static void DCCpp::beginProgDccSignal ( uint8_t  inSignalPin)
static

Initializes the programming track.

Parameters
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...).
static float DCCpp::getCurrentMain ( )
inlinestatic

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 228 of file DCCpp.hpp.

static float DCCpp::getCurrentProg ( )
inlinestatic

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

Returns
Current value between 0 and 1023.

Definition at line 233 of file DCCpp.hpp.

static int DCCpp::identifyLocoIdMain ( )
inlinestatic

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 249 of file DCCpp.hpp.

static int DCCpp::identifyLocoIdProg ( )
inlinestatic

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 290 of file DCCpp.hpp.

static bool DCCpp::IsMainTrack ( volatile RegisterList apRegs)
inlinestatic

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 186 of file DCCpp.hpp.

void DCCpp::loop ( )
static

Main loop function of the library.

Definition at line 93 of file DCCpp.cpp.

void DCCpp::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 372 of file DCCpp.cpp.

void DCCpp::powerOff ( bool  inMain = true,
bool  inProg = true 
)
static

Stop the power on all the tracks by default, or on the chosen track according .

Parameters
inMainIf true, power off the main track.
inProgIf true, power off the programmation track.

Definition at line 413 of file DCCpp.cpp.

void DCCpp::powerOn ( bool  inMain = true,
bool  inProg = true 
)
static

Set the power on all the tracks by default, or on the chosen track according .

Parameters
inMainIf true, power on the main track.
inProgIf true, power on the programmation track.

Definition at line 389 of file DCCpp.cpp.

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

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 258 of file DCCpp.hpp.

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

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 299 of file DCCpp.hpp.

void DCCpp::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 626 of file DCCpp.cpp.

byte DCCpp::setAckThreshold ( byte  inNewValue)
static

Set the minimum threshold value to validate a CV reading or writing..

Parameters
inNewValueMaximum value between 0 and 1023. Default is 30. The threshold that the exponentially-smoothed analogRead samples (after subtracting the baseline current) must cross to establish ACKNOWLEDGEMENT.
Returns
Previous value.

Definition at line 436 of file DCCpp.cpp.

static void DCCpp::setCurrentSampleMaxMain ( float  inMax)
inlinestatic

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 218 of file DCCpp.hpp.

static void DCCpp::setCurrentSampleMaxProg ( float  inMax)
inlinestatic

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 223 of file DCCpp.hpp.

static void DCCpp::setDebugDccMode ( )
static

Set the tracks in slow 'debug' mode only for tests.

static void DCCpp::setFunctionsMain ( int  nReg,
int  inLocoId,
FunctionsState inStates 
)
inlinestatic

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 274 of file DCCpp.hpp.

static void DCCpp::setFunctionsProg ( int  nReg,
int  inLocoId,
FunctionsState inStates 
)
inlinestatic

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 314 of file DCCpp.hpp.

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

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 244 of file DCCpp.hpp.

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

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 285 of file DCCpp.hpp.

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

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 267 of file DCCpp.hpp.

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

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 307 of file DCCpp.hpp.


The documentation for this class was generated from the following files: