10 #include "ActionsStack.hpp" 15 this->minimumPosition = 0;
16 this->maximumPosition = 180;
17 this->powerState = PowerNoAction;
21 int inMinimumPosition,
int inMaximumPosition,
int inMovingPositionsNumber)
23 this->
pPort = inpPort;
27 this->minimumPosition = inMinimumPosition;
28 this->maximumPosition = inMaximumPosition;
32 this->currentPosition = this->minimumPosition;
33 this->targetPosition = -1;
34 this->targetSpeed = 0;
35 this->powerCommandPin = (GPIO_pin_t)DP_INVALID;
37 this->powerState = PowerNoAction;
43 this->powerCommandPin = Arduino_to_GPIO_pin(inPin);
45 pinMode2f(this->powerCommandPin, OUTPUT);
48 this->powerDelay = inDelay;
51 void AccessoryServo::PowerOn()
53 if (this->powerCommandPin != DP_INVALID)
54 digitalWrite2f(this->powerCommandPin, HIGH);
57 void AccessoryServo::PowerOff()
59 if (this->powerCommandPin != DP_INVALID)
60 digitalWrite2f(this->powerCommandPin, LOW);
67 #ifdef ACCESSORIES_DEBUG_MODE 68 Serial.println(F(
"AccessoryServo MoveMinimum()"));
76 #ifdef ACCESSORIES_DEBUG_MODE 77 Serial.println(F(
"AccessoryServo MoveMaximum()"));
88 #ifdef ACCESSORIES_DEBUG_MODE 89 Serial.print(F(
"AccessoryServo MoveToggle() : "));
100 void AccessoryServo::SetState(ACC_STATE inState)
102 #ifdef ACCESSORIES_DEBUG_MODE 103 Serial.print(F(
"AccessoryServo SetState("));
109 #ifdef ACCESSORIES_DEBUG_MODE 110 Serial.println(F(
"MINIMUM)"));
116 #ifdef ACCESSORIES_DEBUG_MODE 117 Serial.println(F(
"MAXIMUM)"));
129 #ifdef ACCESSORIES_DEBUG_MODE 130 Serial.println(F(
"AccessoryServo Move()"));
142 if (position == MINIMUM || position == MAXIMUM)
143 this->SetState((ACC_STATE)position);
153 this->InternalMovePosition(inPosition);
160 case ACCESSORIES_EVENT_MOVE:
163 case ACCESSORIES_MOVE_STRAIGHT:
164 case ACCESSORIES_MOVE_TOP:
165 case ACCESSORIES_MOVE_LEFT:
168 case ACCESSORIES_MOVE_DIVERGE:
169 case ACCESSORIES_MOVE_BOTTOM:
170 case ACCESSORIES_MOVE_RIGHT:
173 case ACCESSORIES_MOVE_OFF:
174 case ACCESSORIES_MOVE_STOP:
179 case ACCESSORIES_MOVE_MORE:
180 case ACCESSORIES_MOVE_LESS:
182 int pos = this->currentPosition + inData;
183 if (pos > this->maximumPosition)
184 pos = this->maximumPosition;
185 if (pos < this->minimumPosition)
186 pos = this->minimumPosition;
193 case ACCESSORIES_EVENT_MOVEPOSITION:
197 case ACCESSORIES_EVENT_TOGGLE:
198 case ACCESSORIES_EVENT_MOVEPOSITIONID:
202 case ACCESSORIES_EVENT_MOVEPOSITIONINDEX:
206 case ACCESSORIES_EVENT_SETSPEED:
210 case ACCESSORIES_EVENT_SETDURATION:
214 case ACCESSORIES_EVENT_EXTERNALMOVE:
223 void AccessoryServo::InternalMovePosition(
int inPosition)
225 if (this->currentPosition == inPosition)
227 #ifdef ACCESSORIES_DEBUG_MODE 228 Serial.println(F(
"AccessoryServo::MovePosition : same position - no move!"));
233 #ifdef ACCESSORIES_DEBUG_MODE 234 Serial.println(F(
"AccessoryServo InternalMovePosition()"));
243 this->currentPosition = inPosition;
247 for (
int pos = this->currentPosition; pos < inPosition; pos++)
249 this->currentPosition = inPosition;
252 case ServoActionStack:
254 this->targetPosition = inPosition;
255 this->targetSpeed = (this->currentPosition < this->targetPosition) ? 1 : -1;
261 this->targetPosition = inPosition;
262 this->targetSpeed = (this->currentPosition < this->targetPosition) ? 1 : -1;
266 if (inPosition == this->minimumPosition)
272 if (inPosition == this->maximumPosition)
284 bool AccessoryServo::ActionEnded()
289 if (this->powerCommandPin == DP_INVALID || this->powerState == PowerRunning)
291 if (this->targetSpeed == 0)
294 this->targetPosition = -1;
296 if (this->powerState == PowerRunning && this->powerCommandPin != DP_INVALID)
298 #ifdef ACCESSORIES_DEBUG_MODE 299 Serial.println(F(
"AccessoryServo after running"));
301 this->powerState = PowerAfterRunning;
312 this->currentPosition += this->targetSpeed;
315 if (this->targetPosition == this->currentPosition)
317 this->targetPosition = -1;
318 this->targetSpeed = 0;
320 if (this->powerState == PowerRunning && this->powerCommandPin != DP_INVALID)
322 #ifdef ACCESSORIES_DEBUG_MODE 323 Serial.println(F(
"AccessoryServo after running"));
325 this->powerState = PowerAfterRunning;
337 if (this->powerState == PowerNoAction)
339 #ifdef ACCESSORIES_DEBUG_MODE 340 Serial.println(F(
"AccessoryServo start power command"));
343 this->powerState = PowerBeforeRunning;
351 if (this->powerState == PowerBeforeRunning)
353 #ifdef ACCESSORIES_DEBUG_MODE 354 Serial.println(F(
"AccessoryServo running"));
356 this->powerState = PowerRunning;
361 if (this->powerState == PowerAfterRunning)
363 #ifdef ACCESSORIES_DEBUG_MODE 364 Serial.println(F(
"AccessoryServo end running"));
366 this->powerState = PowerNoAction;
384 return ServoActionStack;
402 #ifdef ACCESSORIES_PRINT_ACCESSORIES 403 void AccessoryServo::printAccessory()
405 Serial.print(F(
" Servo : "));
406 this->printMovingPositions();
410 Serial.print(F(
" / Speed "));
411 Serial.print(this->
GetPort()->GetSpeed());
413 if (this->powerCommandPin != (GPIO_pin_t)DP_INVALID)
415 Serial.print(F(
" / PowerPin "));
416 Port::printPortPin(this->powerCommandPin, DIGITAL);
417 Serial.print(F(
" / PowerDelay "));
418 Serial.print(this->powerDelay);
420 Serial.print(F(
" / Delay "));
422 Serial.print(F(
"ms / "));
425 Serial.println(F(
" "));
unsigned int GetDebounceDelay() const
virtual int EEPROMLoad(int inPos)
int EEPROMLoad(int inPos)
unsigned long GetActionStartingMillis() const
unsigned long GetDuration() const
virtual void MovePosition(unsigned long inDuration, int inEndPosition)
MovementSpeed GetMovementSpeed() const
void ExternalMove(ACC_STATE inNewState)
virtual int SetSpeed(int inSpeed)
unsigned long GetMovingPositionIdByIndex(uint8_t inIndex) const
void Event(unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0)
virtual void StartAction()
uint8_t IndexOfMovingPositionById(unsigned long inId) const
const uint8_t GetMovingPositionSize() const
void Move(unsigned long inId)
ACC_STATE GetState() const
bool IsActionDelayPending() const
void MovePosition(int inPosition)
void SetPowerCommand(int inPin, unsigned long inDelay = 100)
void AdjustMovingPositionsSize(uint8_t inNewSize)
virtual void beginByAccessory(int inStartingPosition)
int GetMovingPositionValueById(unsigned long inId) const
void begin(ACC_STATE inStartingState = STATE_NONE)
void SetDuration(unsigned long inDuration)
void SetLastMovingPosition(uint8_t inLastPositionIndex)
virtual void ResetAction()
void begin(Port *inpPort, unsigned long inDurationMilli = 0, int inMinimumPosition = 0, int inMaximumPosition = 180, int inMovingPositionsNumber = 1)
void SetStateRaw(ACC_STATE inNewState)