Commanders
Arduino buttons/bus library
DccCommander.hpp
1 //-------------------------------------------------------------------
2 #ifndef __dccCommander_H__
3 #define __dccCommander_H__
4 //-------------------------------------------------------------------
5 
6 #include <Commanders.h>
7 
8 #ifndef NO_DCCCOMMANDER
9 
10 #include <DCC_Decoder.hpp>
11 
13 #define DccCommander DccCommanderClass::GetCurrent()
14 
15 //-------------------------------------------------------------------
16 
17 typedef void(*DccAccDecoderPacket)(int address, boolean activate, uint8_t data);
18 
19 // A dcc id is a long int with accessory id * 10000 + dcc id .
20 #define DCCID(id) ((id) % 10000)
21 #define DCCACTIVATION(id) ((uint8_t)((id) / 10000))
22 #define DCCINT(id, acc) ((acc) * 10000UL + (id))
23 
73 class DccCommanderClass : Commander
74 {
75  private:
76  unsigned long LastDccId;
77  boolean UseRawDccAddresses;
78  static DccAccDecoderPacket func_AccPacket;
79  static DccCommanderClass *pDccCommander;
80 
81  public:
83  inline DccCommanderClass() : Commander() {}
84 
93  void begin(int i, int j, int k, boolean inInterruptMonitor = false, boolean inUseRawDccAddresses = false);
97  void PriorityLoop();
99  unsigned long loop();
101  static void SetAccessoryDecoderPacketHandler(DccAccDecoderPacket func);
107  static void DccAccessoryDecoderPacket(int address, boolean activate, uint8_t data);
109  inline unsigned long GetLastDccId() { return this->LastDccId; }
110 
111  public:
115  static inline DccCommanderClass &GetCurrent()
116  {
117  if (pDccCommander == NULL)
118  pDccCommander = new DccCommanderClass();
119 
120  return *(DccCommanderClass::pDccCommander);
121  }
122 
123 #ifdef COMMANDERS_DEBUG_MODE
124 public:
128  static void printEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEventType, int inEventData);
129  #define PRINT_EVENT_DCC(id, type, data) DccCommander::printEvent(id, type, data);
130 #else
131  #define PRINT_EVENT_DCC(id, type, data)
132 #endif
133 #ifdef COMMANDERS_PRINT_COMMANDERS
134 private:
135  int8_t Interrupt;
136 public:
140  void printCommander();
141 #endif
142 };
143 
144 //-------------------------------------------------------------------
145 #endif
146 #endif
147 //-------------------------------------------------------------------
COMMANDERS_EVENT_TYPE
Definition: Events.h:25
virtual unsigned long loop()
Definition: Commander.hpp:44
virtual void PriorityLoop()
Definition: Commander.hpp:37