Accessories
Arduino for motors and lights library.
AccessoryGroup.hpp
1 //-------------------------------------------------------------------
2 #ifndef __accessoryGroup_H__
3 #define __accessoryGroup_H__
4 //-------------------------------------------------------------------
5 
6 #include "Accessory.hpp"
7 #include "Chain.hpp"
8 
9 //-------------------------------------------------------------------
10 
11 #ifndef NO_GROUP
12 
16 {
17  friend class GroupState;
18 
19  private:
21  Accessory *pAccessory;
23  ACC_STATE State;
25  unsigned int Delay;
26 
27  public:
29  GroupStateItem() { this->pAccessory = NULL; this->State = STATE_NONE; this->Delay = 0; }
35  GroupStateItem(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0) { this->pAccessory = inpAccessory; this->State = inState; this->Delay = inDelay; }
36 
37 #ifdef ACCESSORIES_PRINT_ACCESSORIES
38  public:
42  void printAccessory();
43 #endif
44 };
45 
49 {
50  private:
52  unsigned long Id;
58  bool Synchronous;
59 
60  private:
61  unsigned long startActionTime;
62 
63  public:
65  GroupState() { this->Id = UNDEFINED_ID; this->Synchronous = false; }
66 
72  GroupState(unsigned long inId, bool inSynchronous = true);
73 
75  void begin();
76 
80  void StartAction();
81 
85  void ResetAction() { this->Items.ResetCurrent(); }
86 
90  bool IsActionItemPending() { return this->Items.HasCurrent(); }
91 
95  unsigned long GetId() const { return this->Id; }
96 
100  void loop();
101 
107  void Add(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0);
108 
109 #ifdef ACCESSORIES_PRINT_ACCESSORIES
110  public:
114  void printAccessory();
115 #endif
116 };
117 
121 {
122  private:
123  static AccessoryGroup *pFirstGroup;
124  inline void SetNextGroup(AccessoryGroup *inAccessory) { this->pNextGroup = inAccessory; }
125  inline AccessoryGroup *GetNextGroup() const { return this->pNextGroup; }
126  static void AddGroup(AccessoryGroup *inGroup);
127  AccessoryGroup *pNextGroup;
129 
130  public:
131  /*Default constructor.*/
132  AccessoryGroup();
133 
135  void begin();
136 
140  inline void AddState(GroupState *inpState) { this->States.AddItem(inpState); }
141 
146  inline void AddState(unsigned long inId, bool inSynchronous = true) { this->States.AddItem(new GroupState(inId, inSynchronous)); }
153  void AddStateItem(unsigned long inId, Accessory &inAccessory, ACC_STATE inState, unsigned int inDelay = 0);
154 
158  void AddRange(const AccessoryGroup &inGroup);
159 
164  GroupState *GetByID(unsigned long inId) const;
165 
170  ACCSCHAINEDLISTITEM<GroupState> *GetItemByID(unsigned long inId) const;
171 
177  void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
178 
184  static void EventAll(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
185 
190  void StartAction(GroupState *inpState);
191 
195  void ResetAction() { this->States.ResetCurrent(); }
196 
200  bool IsActionItemPending();
201 
205  bool loop();
206 
210  bool Toggle(unsigned long inId);
211 
212 #ifndef NO_EEPROM
213 
216  int EEPROMSave(int inPos, bool inSimulate = false);
217 
221  int EEPROMLoad(int inPos);
222 #endif
223 
227  static bool loops();
228 
232  static uint8_t GetCount();
233 
237  static int EEPROMSaveAll(int inPos, bool inSimulate = false);
238 
242  static int EEPROMLoadAll(int inPos);
243 
244 #ifdef ACCESSORIES_PRINT_ACCESSORIES
245  public:
249  static void printGroups();
253  void printAccessory();
254 #endif
255 };
256 #endif
257 
258 
259 //-------------------------------------------------------------------
260 #endif
261 //-------------------------------------------------------------------
static int EEPROMLoadAll(int inPos)
static int EEPROMSaveAll(int inPos, bool inSimulate = false)
static bool loops()
int EEPROMSave(int inPos, bool inSimulate = false)
void StartAction(GroupState *inpState)
static void EventAll(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
ACCSCHAINEDLISTITEM< GroupState > * GetItemByID(unsigned long inId) const
GroupState * GetByID(unsigned long inId) const
void AddRange(const AccessoryGroup &inGroup)
void AddStateItem(unsigned long inId, Accessory &inAccessory, ACC_STATE inState, unsigned int inDelay = 0)
void AddState(unsigned long inId, bool inSynchronous = true)
void AddItem(T *t)
Definition: Chain.hpp:71
int EEPROMLoad(int inPos)
void AddState(GroupState *inpState)
void Add(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0)
static uint8_t GetCount()
unsigned long GetId() const
bool IsActionItemPending()
void ResetCurrent()
Definition: Chain.hpp:53
void ResetAction()
bool Toggle(unsigned long inId)
void StartAction()
bool IsActionItemPending()
bool HasCurrent()
Definition: Chain.hpp:59
GroupStateItem(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0)