DCCpp
This is the library version of a program for Arduino to control railroading DCC devices.
DCCpp.hpp
1 //-------------------------------------------------------------------
2 #ifndef __DCCpp_hpp__
3 #define __DCCpp_hpp__
4 //-------------------------------------------------------------------
5 
6 #include "DCCpp.h"
7 
9 {
10  private:
11  // Four bytes : 32 bits : from function 0 to 28, maximum for Dcc.
12  // A bit at true is an activated function.
13  byte activeFlags[4];
14 
15  inline byte ByteNumber(byte inFunctionNumber) { return inFunctionNumber / 8; }
16  inline byte BitNumber(byte inFunctionNumber) { return inFunctionNumber % 8; }
17 
18  public:
20 
21  void Clear();
22  void Activate(byte inFunctionNumber);
23  void Inactivate(byte inFunctionNumber);
24  bool IsActivated(byte inFunctionNumber);
25 
26 #ifdef DCCPP_DEBUG_MODE
27  void printActivated();
28 #endif
29 };
30 
32 {
33  private:
34  bool programMode;
35  bool panicStopped;
36 
37  bool SetThrottle(volatile RegisterList *inReg, int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inToLeft);
38  int ReadCv(volatile RegisterList *inReg, int inLocoId, byte inCvId);
39  void WriteCv(volatile RegisterList *inReg, int inLocoId, int inCvId, byte inCvValue);
40  void SetFunctions(volatile RegisterList *inReg, int nReg, int inLocoId, FunctionsState inStates);
41 
42  public:
43  static volatile RegisterList mainRegs, progRegs;
44  static CurrentMonitor MainMonitor;
45  static CurrentMonitor ProgMonitor;
46 
47  DCCppClass();
48 
49  public:
50  // begins
51  void begin();
52  void beginMain(uint8_t OptionalDirectionMotor, uint8_t Dummy, uint8_t SignalEnablePin, uint8_t CurrentMonitor);
53  void beginProg(uint8_t OptionalDirectionMotor, uint8_t Dummy, uint8_t SignalEnablePin, uint8_t CurrentMonitor);
54 #ifdef USE_ETHERNET
55  void beginEthernet(uint8_t *inMac, uint8_t *inIp);
56 #endif
57 
58  // DCCpp global functions
59  void loop();
60  void PanicStop(bool inStop);
61  void StartProgramMode();
62  void EndProgramMode();
63 
64  // Main driving functions
65  inline bool SetSpeedMain(int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inToLeft) { return this->SetThrottle(&(this->mainRegs), nReg, inLocoId, inStepsNumber, inNewSpeed, inToLeft); }
66  inline int ReadCvMain(int inLocoId, byte inCvId) { return this->ReadCv(&(this->mainRegs), inLocoId, inCvId); }
67  inline void WriteCvMain(int inLocoId, int inCvId, byte inValue) { this->WriteCv(&(this->mainRegs), inLocoId, inCvId, inValue); }
68  inline void SetFunctionsMain(int nReg, int inLocoId, FunctionsState inStates) { this->SetFunctions(&(this->mainRegs), nReg, inLocoId, inStates); }
69 
70  // Prog driving functions
71  inline bool SetSpeedProg(int nReg, int inLocoId, int inStepsNumber, int inNewSpeed, bool inToLeft) { return this->SetThrottle(&(this->progRegs), nReg, inLocoId, inStepsNumber, inNewSpeed, inToLeft); }
72  inline int ReadCvProg(int inLocoId, byte inCvId) { return this->ReadCv(&(this->progRegs), inLocoId, inCvId); }
73  inline void WriteCvProg(int inLocoId, int inCvId, byte inValue) { this->WriteCv(&(this->progRegs), inLocoId, inCvId, inValue); }
74  inline void SetFunctionsProg(int nReg, int inLocoId, FunctionsState inStates) { this->SetFunctions(&(this->progRegs), nReg, inLocoId, inStates); }
75 
76 #ifdef DCCPP_PRINT_DCCPP
77  static void showConfiguration();
78 #endif
79 
80  static DCCppClass DCCppInstance;
81 };
82 
83 #define DCCpp DCCppClass::DCCppInstance
84 
85 //-------------------------------------------------------------------
86 #endif
87 //-------------------------------------------------------------------
DCCppClass()
DCCpp class.
Definition: DCCpp.cpp:79