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 
127 {
128  private:
129  static AccessoryGroup *pFirstGroup;
130  inline void SetNextGroup(AccessoryGroup *inAccessory) { this->pNextGroup = inAccessory; }
131  inline AccessoryGroup *GetNextGroup() const { return this->pNextGroup; }
132  static void AddGroup(AccessoryGroup *inGroup);
133  AccessoryGroup *pNextGroup;
135 
136  public:
137  /*Default constructor.*/
138  AccessoryGroup();
139 
141  void begin();
142 
146  inline void AddState(GroupState *inpState) { this->States.AddItem(inpState); }
147 
152  inline void AddState(unsigned long inId, bool inSynchronous = true) { this->States.AddItem(new GroupState(inId, inSynchronous)); }
159  void AddStateItem(unsigned long inId, Accessory &inAccessory, ACC_STATE inState, unsigned int inDelay = 0);
160 
164  void AddRange(const AccessoryGroup &inGroup);
165 
170  GroupState *GetByID(unsigned long inId) const;
171 
176  ACCSCHAINEDLISTITEM<GroupState> *GetItemByID(unsigned long inId) const;
177 
183  void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
184 
190  static void EventAll(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
191 
196  void StartAction(GroupState *inpState);
197 
201  void ResetAction() { this->States.ResetCurrent(); }
202 
206  bool IsActionItemPending();
207 
211  bool loop();
212 
216  bool Toggle(unsigned long inId);
217 
218 #ifndef NO_EEPROM
219 
222  int EEPROMSave(int inPos, bool inSimulate = false);
223 
227  int EEPROMLoad(int inPos);
228 #endif
229 
233  static bool loops();
234 
238  static uint8_t GetCount();
239 
243  static int EEPROMSaveAll(int inPos, bool inSimulate = false);
244 
248  static int EEPROMLoadAll(int inPos);
249 
250 #ifdef ACCESSORIES_PRINT_ACCESSORIES
251  public:
255  static void printGroups();
259  void printAccessory();
260 #endif
261 };
262 #endif
263 
264 
265 //-------------------------------------------------------------------
266 #endif
267 //-------------------------------------------------------------------
static int EEPROMLoadAll(int inPos)
static int EEPROMSaveAll(int inPos, bool inSimulate = false)
static uint8_t GetCount()
static bool loops()
int EEPROMLoad(int inPos)
int EEPROMSave(int inPos, bool inSimulate = false)
bool Toggle(unsigned long inId)
bool IsActionItemPending()
void StartAction(GroupState *inpState)
static void EventAll(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 AddState(unsigned long inId, bool inSynchronous = true)
void AddItem(T *t)
Definition: Chain.hpp:71
void AddState(GroupState *inpState)
void Add(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0)
void AddStateItem(unsigned long inId, Accessory &inAccessory, ACC_STATE inState, unsigned int inDelay = 0)
unsigned long GetId() const
void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
bool HasCurrent()
Definition: Chain.hpp:59
bool IsActionItemPending()
void ResetAction()
void StartAction()
void AddRange(const AccessoryGroup &inGroup)
GroupStateItem(Accessory *inpAccessory, ACC_STATE inState, unsigned int inDelay = 0)
void ResetCurrent()
Definition: Chain.hpp:53