Accessories
Arduino for motors and lights library.
AccessoryBaseLight.hpp
1 //-------------------------------------------------------------------
2 #ifndef __accessoryBaseLight2_H__
3 #define __accessoryBaseLight2_H__
4 //-------------------------------------------------------------------
5 
6 #include "Accessory.hpp"
7 
8 //-------------------------------------------------------------------
9 
10 #ifndef NO_LIGHT
11 
13 #define LIGHTON STATE_FIRST
14 
15 #define LIGHTBLINK STATE_SECOND
16 
17 #define LIGHTOFF STATE_NONE
18 
20 #define FADING_FULL_DELAY (this->fadingStep == 0 ? 0 : ((255UL / this->fadingStep)+1) * this->fadingDelay)
21 
27 {
28  private:
29  // Fix data from creator
30  Port *pPort;
31  uint8_t fadingStep;
32  uint8_t fadingDelay;
33  unsigned long blinkingDelay;
34 
35  // State of the light
36  ACC_STATE state;
37  enum LightState { LIGHT_ON, LIGHT_OFF, LIGHT_ASCENDING, LIGHT_DESCENDING };
38  LightState currentState;
39  uint8_t fadingCurrentValue;
40  unsigned long startingMillis;
41 
42  friend class AccessoryLight;
43  friend class AccessoryLightMulti;
44 
45  Accessory *pOwner;
46 
47  public:
49  AccessoryBaseLight(Accessory *inpOwner = 0);
50 
56  void begin(Port *inpPort, int inIntensity = 255, Accessory *inpOwner = 0);
57 
61  inline Port *GetPort() const { return this->pPort; }
65  inline bool IsOn() const { return this->state == LIGHTON; }
69  inline bool IsBlinking() const { return this->state == LIGHTBLINK; }
74  inline bool IsFading() const { return this->fadingStep > 0; }
75 
80  void Event(ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
84  inline void SetBlinking(unsigned long inBlinkingDelay) { this->blinkingDelay = inBlinkingDelay; }
89  void SetFading(uint8_t inStep, uint8_t inDelay);
90 
91  private:
92  void SetState(ACC_STATE instate);
93  void SetStateRaw(ACC_STATE instate);
94  ACC_STATE Toggle();
95  void LightOn();
96  void LightOff();
97  inline void Blink() { this->SetState(LIGHTBLINK); this->StartAction(); }
98 
99  inline bool IsGroupActionPending() const { return false; }
100  inline unsigned long GetActionStartingMillis() const { return this->startingMillis; }
101  inline void ResetAction() { this->startingMillis = 0; }
102  void StartAction();
103  bool ActionEnded();
104 
105  void LightOnRaw();
106  void LightOffRaw();
107  void LightFadingRaw(uint8_t inValue);
108 #ifndef NO_EEPROM
109  int EEPROMSave(int inPos, bool inSimulate = false);
110  int EEPROMLoad(int inPos);
111 #endif
112 #ifdef ACCESSORIES_PRINT_ACCESSORIES
113  public:
117  void printAccessory();
118 #endif
119 };
120 #endif
121 
122 //-------------------------------------------------------------------
123 #endif
124 //-------------------------------------------------------------------
virtual void ResetAction()
Definition: Accessory.hpp:411
unsigned long GetActionStartingMillis() const
Definition: Accessory.hpp:392
virtual bool IsGroupActionPending() const
Definition: Accessory.hpp:430
virtual void StartAction()
Definition: Accessory.cpp:135
void SetStateRaw(ACC_STATE inNewState)
Definition: Accessory.cpp:223
void SetBlinking(unsigned long inBlinkingDelay)
void Event(ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
Port * pPort
Definition: Accessory.hpp:187
Port * GetPort() const
void begin(Port *inpPort, int inIntensity = 255, Accessory *inpOwner = 0)
AccessoryBaseLight(Accessory *inpOwner = 0)
Definition: Port.hpp:61
void SetFading(uint8_t inStep, uint8_t inDelay)