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 void beginEthernet (uint8_t *inMac, uint8_t *inIp, EthernetProtocol inProtocol = EthernetProtocol::TCP)
 
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 readCvMain (int inLocoId, byte inCvId)
 
static void writeCvMain (int inLocoId, int inCvId, byte inValue)
 
static void setFunctionsMain (int nReg, int inLocoId, FunctionsState &inStates)
 
static bool setSpeedProg (int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inForward)
 
static int readCvProg (int inLocoId, byte inCvId)
 
static void writeCvProg (int inLocoId, int inCvId, byte inValue)
 
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 291 of file DCCpp.cpp.

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

Initializes the main line.

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 line.

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 181 of file DCCpp.cpp.

static void beginMainMotorShield ( )
static

Initializes the main line for an Arduino Motor Shield.

Definition at line 108 of file DCCpp.hpp.

static void beginProgMotorShield ( )
static

Initializes the programming line for an Arduino Motor Shield.

Definition at line 111 of file DCCpp.hpp.

static void beginMainPololu ( )
static

Initializes the main line for a Pololu MC33926 Motor Shield.

Definition at line 115 of file DCCpp.hpp.

static void beginProgPololu ( )
static

Initializes the programming line for a Pololu MC33926 Motor Shield.

Definition at line 118 of file DCCpp.hpp.

void beginEthernet ( uint8_t *  inMac,
uint8_t *  inIp,
EthernetProtocol  inProtocol = EthernetProtocol::TCP 
)
static

Initializes the Ethernet link.

Parameters
inMacMac address of this network element.
inIpIP address, or NULL for DHCP configuration.
inProtocolCan be HTTP or TCP. Default is TCP.

Definition at line 327 of file DCCpp.cpp.

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 lines.

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

Definition at line 529 of file DCCpp.cpp.

void powerOn ( )
static

Stop the power on all the lines.

Definition at line 546 of file DCCpp.cpp.

void powerOff ( )
static

Restore the power on all the lines.

Definition at line 558 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 line.

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

Definition at line 146 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 line.

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

Definition at line 150 of file DCCpp.hpp.

static float getCurrentMain ( )
static

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

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

Definition at line 154 of file DCCpp.hpp.

static float getCurrentProg ( )
static

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

Returns
Current value between 0 and 1023.

Definition at line 158 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 line.

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

static int readCvMain ( int  inLocoId,
byte  inCvId 
)
static

For the given decoder id, read the given CV on the main line.

Parameters
inLocoIdDecoder address in short or long format.
inCvIdCV id from 0 to 255.
Returns
CV value.

Definition at line 174 of file DCCpp.hpp.

static void writeCvMain ( int  inLocoId,
int  inCvId,
byte  inValue 
)
static

For the given decoder id, write the given CV on the main line.

Parameters
inLocoIdDecoder address in short or long format.
inCvIdCV id from 0 to 255.
inValueCV new value from 0 to 255.

Definition at line 180 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 line.

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 186 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 line.

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

static int readCvProg ( int  inLocoId,
byte  inCvId 
)
static

For the given decoder id, read the given CV on the programming line.

Parameters
inLocoIdDecoder address in short or long format.
inCvIdCV id from 0 to 255.
Returns
CV value.

Definition at line 203 of file DCCpp.hpp.

static void writeCvProg ( int  inLocoId,
int  inCvId,
byte  inValue 
)
static

For the given decoder id, write the given CV on the programming line.

Parameters
inLocoIdDecoder address in short or long format.
inCvIdCV id from 0 to 255.
inValueCV new value from 0 to 255.

Definition at line 209 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 line.

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 215 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 736 of file DCCpp.cpp.