Accessories
Arduino for motors and lights library.
AccessoryMotor.hpp
1 //-------------------------------------------------------------------
2 #ifndef __accessoryMotor_H__
3 #define __accessoryMotor_H__
4 //-------------------------------------------------------------------
5 
6 #include "Accessory.hpp"
7 class Driver;
8 
9 //-------------------------------------------------------------------
10 
11 #ifndef NO_MOTOR
12 
13 // This class describes a motor powered by a driver.
14 
16 #define LEFT STATE_FIRST
17 
18 #define RIGHT STATE_SECOND
19 
20 #define STOP STATE_NONE
21 
23 enum DIRECTION
24 {
25  ONLYLEFT,
26  ONLYRIGHT,
27  BOTHDIRS
28 };
29 
33 class AccessoryMotor : public Accessory
34 {
35  public:
38 
43  bool ActionEnded();
44 
48  inline bool IsLeft() const { return this->IsFirst(); }
49 
53  inline bool IsRight() const { return this->IsSecond(); }
54 
58  inline bool IsStopped() const { return this->IsNone(); }
59 
66  void begin(Port *inpPort, unsigned long inId, int inSpeed, unsigned long inDurationMilli = 0);
67 
73  void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0);
74 
75 #ifndef NO_EEPROM
76 
79  int EEPROMLoad(int inPos);
80 #endif
81 
85  void Move(unsigned long inId);
86 
91  inline virtual void MoveLeft(unsigned long inDuration = 0, int inSpeed = 0) { this->InternalMove(LEFT, inDuration, inSpeed); }
92 
97  inline virtual void MoveRight(unsigned long inDuration = 0, int inSpeed = 0) { this->InternalMove(RIGHT, inDuration, inSpeed); }
98 
104  virtual ACC_STATE MoveToggle(unsigned long inDuration = 0, int inSpeed = 0) = 0;
105 
107  virtual void MoveStop();
108 
112  void ExternalMove(ACC_STATE inNewState) { this->SetStateRaw(inNewState); }
113 
114  protected:
115  void SetState(ACC_STATE instate);
116  inline ACC_STATE Toggle() { return MoveToggle(); }
117  private:
118  ACC_STATE InternalMove(ACC_STATE inStateToReach, unsigned long inDuration = 0, int inSpeed = 0);
119 };
120 #endif
121 
122 
123 //-------------------------------------------------------------------
124 #endif
125 //-------------------------------------------------------------------
126 
ACC_STATE Toggle()
void SetState(ACC_STATE instate)
void ExternalMove(ACC_STATE inNewState)
virtual void MoveStop()
virtual void MoveLeft(unsigned long inDuration = 0, int inSpeed = 0)
void Move(unsigned long inId)
int EEPROMLoad(int inPos)
void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
Definition: Port.hpp:61
virtual ACC_STATE MoveToggle(unsigned long inDuration = 0, int inSpeed = 0) = 0
void begin(Port *inpPort, unsigned long inId, int inSpeed, unsigned long inDurationMilli = 0)
bool IsNone() const
Definition: Accessory.hpp:240
bool IsStopped() const
bool IsSecond() const
Definition: Accessory.hpp:250
bool IsFirst() const
Definition: Accessory.hpp:245
bool IsLeft() const
void SetStateRaw(ACC_STATE inNewState)
Definition: Accessory.cpp:224
virtual void MoveRight(unsigned long inDuration = 0, int inSpeed = 0)
bool IsRight() const