-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strategy.h
108 lines (87 loc) · 1.91 KB
/
Strategy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Strategy.h
*
* Created on: 9.6.2016
* Author: kimmo.toivanen
*/
#ifndef STRATEGY_H_
#define STRATEGY_H_
#include "Adafruit_SoftServo.h"
#define ARM_MIN_VALUE 0
#define ARM_MAX_VALUE 230
#define LID_MIN_VALUE 30
#define LID_MAX_VALUE 180
#define SEQ_END -1
#define LIDANGLE 0
#define ARMANGLE 1
#define PWMVALUE 2
#define DURATION 3
#define DELAYAFTER 4
class Strategy {
public:
/**
* Sequence of positions and pwm at the end of period
*/
struct SequenceStep {
int lidAngle; /// lid servo angle after duration
int armAngle; /// arm servo angle after duration
int pwmValue; /// backlight brightness after duration
int duration; /// time to move to end values
int delayAfter; /// time after move before next step
};
// enum Action {
// hold = 0, open, out, in, close, end
// };
Strategy();
virtual ~Strategy();
/**
* Set servos to the strategy
*/
void setServos(Adafruit_SoftServo *lid_, Adafruit_SoftServo *arm_) {
lid = lid_;
arm = arm_;
}
;
/**
* Set pwm pin for backlight
*/
void setPwmPin(int pin) {
pwmPin = pin;
}
;
/**
* execute behaviour
*
* abort true if switch set while running
* return true when complete
*/
virtual bool execute(bool abort);
protected:
/**
* Set pwm value
*/
void writePwmPin(int value);
Adafruit_SoftServo *lid;
Adafruit_SoftServo *arm;
int pwmPin;
// virtual int getStepCount() = 0;
// virtual const Strategy::SequenceStep * getSequenceAddress() = 0;
virtual int getSequenceValue(int step, int index) = 0;
// const Strategy::SequenceStep *sequence;
//
// const int stepCount;
// int step;
// unsigned long startTime;
// Action action;
int lidStart;
int armStart;
int pwmStart;
int lidPos;
int armPos;
int pwmPos;
int duration;
int delayAfter;
int step;
unsigned long startTime;
};
#endif /* STRATEGY_H_ */