reformatted the NmraDcc.h & NmraDcc.cpp files using the astyle rules in the new file: .astyle as per the PR from David Zuhn (davidzuhn)
This commit is contained in:
858
NmraDcc.cpp
858
NmraDcc.cpp
File diff suppressed because it is too large
Load Diff
119
NmraDcc.h
119
NmraDcc.h
@@ -49,9 +49,9 @@
|
||||
//#define NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#ifndef NMRADCC_IS_IN
|
||||
@@ -126,13 +126,14 @@ typedef struct
|
||||
#define PRIO_DCC_IRQ 9
|
||||
#define PRIO_SYSTIC 8 // MUST be higher priority than DCC Irq
|
||||
#elif defined(ARDUINO_ARCH_RP2040)
|
||||
#define MAXCV 256 // todo: maybe somebody knows a good define for it
|
||||
#define MAXCV 256 // todo: maybe somebody knows a good define for it
|
||||
|
||||
#else
|
||||
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */
|
||||
CV29_F0_LOCATION = 0b00000010, /** bit 1: F0 location: "0" = bit 4 in Speed and Direction instructions, "1" = bit 4 in function group one instruction */
|
||||
CV29_APS = 0b00000100, /** bit 2: Alternate Power Source (APS) "0" = NMRA Digital only, "1" = Alternate power source set by CV12 */
|
||||
@@ -143,20 +144,23 @@ typedef enum {
|
||||
CV29_ACCESSORY_DECODER = 0b10000000, /** bit 7: "0" = Multi-Function Decoder Mode "1" = Accessory Decoder Mode */
|
||||
} CV_29_BITS;
|
||||
|
||||
typedef enum {
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
typedef enum
|
||||
{
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
SPEED_STEP_14 = 15, /**< ESTOP=0, 1 to 15 */
|
||||
#endif
|
||||
#endif
|
||||
SPEED_STEP_28 = 29, /**< ESTOP=0, 1 to 29 */
|
||||
SPEED_STEP_128 = 127 /**< ESTOP=0, 1 to 127 */
|
||||
} DCC_SPEED_STEPS;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
DCC_DIR_REV = 0, /** The locomotive to go in the reverse direction */
|
||||
DCC_DIR_FWD = 1, /** The locomotive should move in the forward direction */
|
||||
} DCC_DIRECTION;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
DCC_ADDR_SHORT, /** Short address is used. The range is 0 to 127. */
|
||||
DCC_ADDR_LONG, /** Long Address is used. The range is 1 to 10239 */
|
||||
} DCC_ADDR_TYPE;
|
||||
@@ -168,9 +172,9 @@ typedef enum
|
||||
FN_9_12,
|
||||
FN_13_20,
|
||||
FN_21_28,
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
FN_0 /** function light is controlled by base line package (14 speed steps) */
|
||||
#endif
|
||||
#endif
|
||||
} FN_GROUP;
|
||||
|
||||
#define FN_BIT_00 0x10
|
||||
@@ -209,20 +213,21 @@ typedef enum
|
||||
|
||||
//#define DCC_DBGVAR
|
||||
#ifdef DCC_DBGVAR
|
||||
typedef struct countOf_t {
|
||||
typedef struct countOf_t
|
||||
{
|
||||
unsigned long Tel;
|
||||
unsigned long Err;
|
||||
}countOf_t ;
|
||||
} countOf_t ;
|
||||
|
||||
extern struct countOf_t countOf;
|
||||
#endif
|
||||
|
||||
class NmraDcc
|
||||
{
|
||||
private:
|
||||
private:
|
||||
DCC_MSG Msg ;
|
||||
|
||||
public:
|
||||
public:
|
||||
NmraDcc();
|
||||
|
||||
// Flag values to be logically ORed together and passed into the init() method
|
||||
@@ -247,7 +252,7 @@ class NmraDcc
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void pin( uint8_t ExtIntNum, uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
void pin (uint8_t ExtIntNum, uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
|
||||
/*+
|
||||
* pin() is called from setup() and sets up the pin used to receive DCC packets.
|
||||
@@ -260,9 +265,9 @@ class NmraDcc
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
#ifdef digitalPinToInterrupt
|
||||
void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
#endif
|
||||
#ifdef digitalPinToInterrupt
|
||||
void pin (uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
#endif
|
||||
|
||||
/*+
|
||||
* init() is called from setup() after the pin() command is called.
|
||||
@@ -285,7 +290,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV );
|
||||
void init (uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV);
|
||||
|
||||
/*+
|
||||
* initAccessoryDecoder() is called from setup() for accessory decoders.
|
||||
@@ -302,7 +307,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV );
|
||||
void initAccessoryDecoder (uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV);
|
||||
|
||||
/*+
|
||||
* process() is called from loop() to process DCC packets.
|
||||
@@ -328,7 +333,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* since nothing will have been set in that EEPROM position.
|
||||
* Calls notifyCVRead() if it is defined.
|
||||
*/
|
||||
uint8_t getCV( uint16_t CV );
|
||||
uint8_t getCV (uint16_t CV);
|
||||
|
||||
/*+
|
||||
* setCV() sets the value of a CV.
|
||||
@@ -343,7 +348,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Calls notifyCVWrite() if it is defined.
|
||||
* Calls notifyCVChange() if the value is changed by this call.
|
||||
*/
|
||||
uint8_t setCV( uint16_t CV, uint8_t Value);
|
||||
uint8_t setCV (uint16_t CV, uint8_t Value);
|
||||
|
||||
/*+
|
||||
* setAccDecDCCAddrNextReceived() enables/disables the setting of the board address from the next received turnout command
|
||||
@@ -353,7 +358,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
*
|
||||
* Returns:
|
||||
*/
|
||||
void setAccDecDCCAddrNextReceived(uint8_t enable);
|
||||
void setAccDecDCCAddrNextReceived (uint8_t enable);
|
||||
|
||||
/*+
|
||||
* isSetCVReady() returns 1 if EEPROM is ready to write.
|
||||
@@ -368,7 +373,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Note: It returns the value returned by notifyIsSetCVReady() if it is defined.
|
||||
* Calls notifyIsSetCVReady() if it is defined.
|
||||
*/
|
||||
uint8_t isSetCVReady( void );
|
||||
uint8_t isSetCVReady (void);
|
||||
|
||||
/*+
|
||||
* getAddr() return the currently active decoder address.
|
||||
@@ -381,7 +386,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Adr - The current decoder address based on decoder type(Multifunction, Accessory)
|
||||
* and short or long address selection for Multifunction decoders.
|
||||
*/
|
||||
uint16_t getAddr(void);
|
||||
uint16_t getAddr (void);
|
||||
|
||||
/*+
|
||||
* getX() return debugging data if DCC_DEBUG is defined.
|
||||
@@ -403,13 +408,13 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* is not handling packets fast enough or some other error is occurring.
|
||||
*/
|
||||
// #define DCC_DEBUG
|
||||
#ifdef DCC_DEBUG
|
||||
uint8_t getIntCount(void);
|
||||
uint8_t getTickCount(void);
|
||||
uint8_t getBitCount(void);
|
||||
uint8_t getState(void);
|
||||
uint8_t getNestedIrqCount(void);
|
||||
#endif
|
||||
#ifdef DCC_DEBUG
|
||||
uint8_t getIntCount (void);
|
||||
uint8_t getTickCount (void);
|
||||
uint8_t getBitCount (void);
|
||||
uint8_t getState (void);
|
||||
uint8_t getNestedIrqCount (void);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
@@ -418,7 +423,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
************************************************************************************/
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*+
|
||||
@@ -431,7 +436,7 @@ void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccReset(uint8_t hardReset ) __attribute__ ((weak));
|
||||
extern void notifyDccReset (uint8_t hardReset) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccIdle() Callback for a DCC idle command.
|
||||
@@ -442,7 +447,7 @@ extern void notifyDccReset(uint8_t hardReset ) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccIdle(void) __attribute__ ((weak));
|
||||
extern void notifyDccIdle (void) __attribute__ ( (weak));
|
||||
|
||||
|
||||
/*+
|
||||
@@ -463,7 +468,7 @@ extern void notifyDccIdle(void) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSpeed( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Speed, DCC_DIRECTION Dir, DCC_SPEED_STEPS SpeedSteps ) __attribute__ ((weak));
|
||||
extern void notifyDccSpeed (uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Speed, DCC_DIRECTION Dir, DCC_SPEED_STEPS SpeedSteps) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccSpeedRaw() Callback for a multifunction decoder speed command.
|
||||
@@ -477,7 +482,7 @@ extern void notifyDccSpeed( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Sp
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSpeedRaw( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Raw) __attribute__ ((weak));
|
||||
extern void notifyDccSpeedRaw (uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Raw) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccFunc() Callback for a multifunction decoder function command.
|
||||
@@ -499,7 +504,7 @@ extern void notifyDccSpeedRaw( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccFunc( uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP FuncGrp, uint8_t FuncState) __attribute__ ((weak));
|
||||
extern void notifyDccFunc (uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP FuncGrp, uint8_t FuncState) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccTurnoutBoard() Board oriented callback for a turnout accessory decoder.
|
||||
@@ -521,7 +526,7 @@ extern void notifyDccFunc( uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP Fu
|
||||
* None
|
||||
*/
|
||||
|
||||
extern void notifyDccAccTurnoutBoard( uint16_t BoardAddr, uint8_t OutputPair, uint8_t Direction, uint8_t OutputPower ) __attribute__ ((weak));
|
||||
extern void notifyDccAccTurnoutBoard (uint16_t BoardAddr, uint8_t OutputPair, uint8_t Direction, uint8_t OutputPower) __attribute__ ( (weak));
|
||||
/*+
|
||||
* notifyDccAccTurnoutOutput() Output oriented callback for a turnout accessory decoder.
|
||||
* Most useful when CV29_OUTPUT_ADDRESS_MODE IS set.
|
||||
@@ -539,7 +544,7 @@ extern void notifyDccAccTurnoutBoard( uint16_t BoardAddr, uint8_t OutputPair,
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint8_t OutputPower ) __attribute__ ((weak));
|
||||
extern void notifyDccAccTurnoutOutput (uint16_t Addr, uint8_t Direction, uint8_t OutputPower) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccBoardAddrSet() Board oriented callback for a turnout accessory decoder.
|
||||
@@ -555,7 +560,7 @@ extern void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccBoardAddrSet( uint16_t BoardAddr) __attribute__ ((weak));
|
||||
extern void notifyDccAccBoardAddrSet (uint16_t BoardAddr) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccOutputAddrSet() Output oriented callback for a turnout accessory decoder.
|
||||
@@ -571,7 +576,7 @@ extern void notifyDccAccBoardAddrSet( uint16_t BoardAddr) __attribute__ ((wea
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccOutputAddrSet( uint16_t Addr) __attribute__ ((weak));
|
||||
extern void notifyDccAccOutputAddrSet (uint16_t Addr) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccSigOutputState() Callback for a signal aspect accessory decoder.
|
||||
@@ -584,7 +589,7 @@ extern void notifyDccAccOutputAddrSet( uint16_t Addr) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSigOutputState( uint16_t Addr, uint8_t State) __attribute__ ((weak));
|
||||
extern void notifyDccSigOutputState (uint16_t Addr, uint8_t State) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyDccMsg() Raw DCC packet callback.
|
||||
@@ -599,7 +604,7 @@ extern void notifyDccSigOutputState( uint16_t Addr, uint8_t State) __attribut
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccMsg( DCC_MSG * Msg ) __attribute__ ((weak));
|
||||
extern void notifyDccMsg (DCC_MSG * Msg) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVValid() Callback to determine if a given CV is valid.
|
||||
@@ -617,7 +622,7 @@ extern void notifyDccMsg( DCC_MSG * Msg ) __attribute__ ((weak));
|
||||
* 1 - CV is valid.
|
||||
* 0 - CV is not valid.
|
||||
*/
|
||||
extern uint8_t notifyCVValid( uint16_t CV, uint8_t Writable ) __attribute__ ((weak));
|
||||
extern uint8_t notifyCVValid (uint16_t CV, uint8_t Writable) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVRead() Callback to read a CV.
|
||||
@@ -633,7 +638,7 @@ extern uint8_t notifyCVValid( uint16_t CV, uint8_t Writable ) __attribute__ ((we
|
||||
* Returns:
|
||||
* Value - Value of the CV.
|
||||
*/
|
||||
extern uint8_t notifyCVRead( uint16_t CV) __attribute__ ((weak));
|
||||
extern uint8_t notifyCVRead (uint16_t CV) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVWrite() Callback to write a value to a CV.
|
||||
@@ -650,7 +655,7 @@ extern uint8_t notifyCVRead( uint16_t CV) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* Value - Value of the CV.
|
||||
*/
|
||||
extern uint8_t notifyCVWrite( uint16_t CV, uint8_t Value) __attribute__ ((weak));
|
||||
extern uint8_t notifyCVWrite (uint16_t CV, uint8_t Value) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyIsSetCVReady() Callback to to determine if CVs can be written.
|
||||
@@ -670,7 +675,7 @@ extern uint8_t notifyCVWrite( uint16_t CV, uint8_t Value) __attribute__ ((weak))
|
||||
* 1 - CV is ready to be written.
|
||||
* 0 - CV is not ready to be written.
|
||||
*/
|
||||
extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak));
|
||||
extern uint8_t notifyIsSetCVReady (void) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVChange() Called when a CV value is changed.
|
||||
@@ -688,8 +693,8 @@ extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak));
|
||||
extern void notifyDccCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak));
|
||||
extern void notifyCVChange (uint16_t CV, uint8_t Value) __attribute__ ( (weak));
|
||||
extern void notifyDccCVChange (uint16_t CV, uint8_t Value) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVResetFactoryDefault() Called when CVs must be reset.
|
||||
@@ -706,7 +711,7 @@ extern void notifyDccCVChange( uint16_t CV, uint8_t Value) __attribute__ ((we
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyCVResetFactoryDefault(void) __attribute__ ((weak));
|
||||
extern void notifyCVResetFactoryDefault (void) __attribute__ ( (weak));
|
||||
|
||||
/*+
|
||||
* notifyCVAck() Called when a CV write must be acknowledged.
|
||||
@@ -719,7 +724,7 @@ extern void notifyCVResetFactoryDefault(void) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyCVAck(void) __attribute__ ((weak));
|
||||
extern void notifyCVAck (void) __attribute__ ( (weak));
|
||||
/*+
|
||||
* notifyAdvancedCVAck() Called when a CV write must be acknowledged via Advanced Acknowledgement.
|
||||
* This callback must send the Advanced Acknowledgement via RailComm.
|
||||
@@ -730,7 +735,7 @@ extern void notifyCVAck(void) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyAdvancedCVAck(void) __attribute__ ((weak));
|
||||
extern void notifyAdvancedCVAck (void) __attribute__ ( (weak));
|
||||
/*+
|
||||
* notifyServiceMode(bool) Called when state of 'inServiceMode' changes
|
||||
*
|
||||
@@ -740,12 +745,12 @@ extern void notifyAdvancedCVAck(void) __attribute__ ((weak));
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyServiceMode(bool) __attribute__ ((weak));
|
||||
extern void notifyServiceMode (bool) __attribute__ ( (weak));
|
||||
|
||||
// Deprecated, only for backward compatibility with version 1.4.2.
|
||||
// Don't use in new designs. These functions may be dropped in future versions
|
||||
extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) __attribute__ ((weak));
|
||||
extern void notifyDccSigState( uint16_t Addr, uint8_t OutputIndex, uint8_t State) __attribute__ ((weak));
|
||||
extern void notifyDccAccState (uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State) __attribute__ ( (weak));
|
||||
extern void notifyDccSigState (uint16_t Addr, uint8_t OutputIndex, uint8_t State) __attribute__ ( (weak));
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user