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 bool IsMainTrackDeclared ()
 
static bool IsProgTrackDeclared ()
 
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 bool 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 void showConfiguration ()
 

Static Public Attributes

static byte ackThreshold = 0
 
static volatile RegisterList mainRegs
 
static volatile RegisterList progRegs
 
static CurrentMonitor mainMonitor
 
static CurrentMonitor progMonitor
 
static bool IsPowerOnMain = false
 
static bool IsPowerOnProg = false
 

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 188 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 121 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 159 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 240 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 245 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 262 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 304 of file DCCpp.hpp.

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

Checks if the given RegisterList is for 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 188 of file DCCpp.hpp.

static bool DCCpp::IsMainTrackDeclared ( )
inlinestatic

Checks if beginMain() has been called with the right arguments !

Returns
true if the main track is defined.

Definition at line 193 of file DCCpp.hpp.

static bool DCCpp::IsProgTrackDeclared ( )
inlinestatic

Checks if beginProg() has been called with the right arguments !

Returns
true if the prog track is defined.

Definition at line 198 of file DCCpp.hpp.

void DCCpp::loop ( )
static

Main loop function of the library.

Definition at line 95 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 374 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 417 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 391 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 or -1 if the value cannot be read.

Definition at line 271 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 or -1 if the value cannot be read.

Definition at line 313 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 634 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 442 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 230 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 235 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. Original DCC++ use register 0 to send function states only a few times. DCCpp Can use any register to be able to send function packets repeatedly like the speed packets,
inLocoIdDecoder address in short or long format.
inStatesFunctionsState class with the wanted new status.

Definition at line 287 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. Original DCC++ use register 0 to send function states only a few times. DCCpp Can use any register to be able to send function packets repeatedly like the speed packets,
inLocoIdDecoder address in short or long format.
inStatesFunctionsState class with the wanted new status.

Definition at line 329 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.
Returns
True if the value has been changed. At the moment, always return true...

Definition at line 257 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.
Returns
True if the value has been changed. At the moment, always return true...

Definition at line 299 of file DCCpp.hpp.

void DCCpp::showConfiguration ( )
static

Print the list of activated functions.

Remarks
Only available if DCCPP_PRINT_DCCPP is defined.

Definition at line 260 of file DCCpp.cpp.

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

static bool 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
Returns
False if the writing have failed.

Definition at line 322 of file DCCpp.hpp.


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