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 
82 {
83  private:
84  unsigned long LastDccId;
85  unsigned long LastEventDate;
86  boolean UseRawDccAddresses;
87  boolean RaiseEventOnActivation;
88  int RaiseEventDebounceDelay;
89  static DccAccDecoderPacket func_AccPacket;
90  static DccCommanderClass *pDccCommander;
91 
92  public:
94  inline DccCommanderClass() : Commander() {}
95 
104  void begin(int i, int j, int k, boolean inInterruptMonitor = false, boolean inUseRawDccAddresses = false);
105 
111  void RaiseEventWhen(boolean inRaiseEventOnActivation, int inRaiseEventDebounceDelay = 200);
112 
116  void PriorityLoop();
118  unsigned long loop();
120  static void SetAccessoryDecoderPacketHandler(DccAccDecoderPacket func);
126  static void DccAccessoryDecoderPacket(int address, boolean activate, uint8_t data);
128  inline unsigned long GetLastDccId() { return this->LastDccId; }
129 
130  public:
134  static inline DccCommanderClass &GetCurrent()
135  {
136  if (pDccCommander == NULL)
137  pDccCommander = new DccCommanderClass();
138 
139  return *(DccCommanderClass::pDccCommander);
140  }
141 
142 #ifdef COMMANDERS_DEBUG_MODE
143 public:
147  static void printEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEventType, int inEventData);
148  #define PRINT_EVENT_DCC(id, type, data) DccCommander::printEvent(id, type, data);
149 #else
150  #define PRINT_EVENT_DCC(id, type, data)
151 #endif
152 #ifdef COMMANDERS_PRINT_COMMANDERS
153 private:
154  int8_t Interrupt;
155 public:
159  void printCommander();
160 #endif
161 };
162 
163 //-------------------------------------------------------------------
164 #endif
165 #endif
166 //-------------------------------------------------------------------
COMMANDERS_EVENT_TYPE
Definition: Events.h:25
static void printEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEventType, int inEventData)
static DccCommanderClass & GetCurrent()
unsigned long GetLastDccId()
static void DccAccessoryDecoderPacket(int address, boolean activate, uint8_t data)
unsigned long loop()
void RaiseEventWhen(boolean inRaiseEventOnActivation, int inRaiseEventDebounceDelay = 200)
void begin(int i, int j, int k, boolean inInterruptMonitor = false, boolean inUseRawDccAddresses = false)
static void SetAccessoryDecoderPacketHandler(DccAccDecoderPacket func)