|
6 | 6 |
|
7 | 7 | #include <Braccio++.h>
|
8 | 8 |
|
9 |
| -extern lv_obj_t * label; |
10 |
| -extern lv_obj_t * direction_btnm; |
| 9 | +/************************************************************************************** |
| 10 | + * EXTERN |
| 11 | + **************************************************************************************/ |
11 | 12 |
|
12 |
| -enum BUTTONS { |
13 |
| - BTN_UP = 1, |
14 |
| - BTN_DOWN = 7, |
15 |
| - BTN_LEFT = 3, |
16 |
| - BTN_RIGHT = 5, |
17 |
| -}; |
| 13 | +extern lv_obj_t * label; |
18 | 14 |
|
19 | 15 | /**************************************************************************************
|
20 |
| - * State |
| 16 | + * GLOBAL VARIABLES |
21 | 17 | **************************************************************************************/
|
22 | 18 |
|
23 |
| -State * State::handle_OnButtonDownPressed() |
24 |
| -{ |
25 |
| - Braccio.lvgl_lock(); |
26 |
| - lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_CHECKED); |
27 |
| - Braccio.lvgl_unlock(); |
28 |
| - return this; |
29 |
| -} |
30 |
| - |
31 |
| -State * State::handle_OnButtonDownReleased() |
32 |
| -{ |
33 |
| - Braccio.lvgl_lock(); |
34 |
| - lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_CHECKED); |
35 |
| - Braccio.lvgl_unlock(); |
36 |
| - return this; |
37 |
| -} |
| 19 | +static auto gripper = Braccio.get(1); |
| 20 | +static auto wristRoll = Braccio.get(2); |
| 21 | +static auto wristPitch = Braccio.get(3); |
| 22 | +static auto elbow = Braccio.get(4); |
| 23 | +static auto shoulder = Braccio.get(5); |
| 24 | +static auto base = Braccio.get(6); |
38 | 25 |
|
39 | 26 | /**************************************************************************************
|
40 | 27 | * ShoulderState
|
41 | 28 | **************************************************************************************/
|
42 | 29 |
|
43 |
| -void ShoulderState::onEnter() |
| 30 | +ShoulderState::ShoulderState() |
44 | 31 | {
|
45 | 32 | Braccio.lvgl_lock();
|
46 | 33 | lv_label_set_text(label, "Shoulder");
|
47 | 34 | Braccio.lvgl_unlock();
|
48 | 35 | }
|
49 | 36 |
|
50 |
| -void ShoulderState::onExit() |
| 37 | +State * ShoulderState::handle_OnEnter() |
51 | 38 | {
|
52 |
| - |
53 |
| -} |
54 |
| - |
55 |
| -State * ShoulderState::handle_OnButtonDownPressed() |
56 |
| -{ |
57 |
| - State::handle_OnButtonDownPressed(); |
58 |
| - return this; |
| 39 | + return new ElbowState(); |
59 | 40 | }
|
60 | 41 |
|
61 |
| -State * ShoulderState::handle_OnButtonDownReleased() |
| 42 | +State * ShoulderState::handle_OnUp() |
62 | 43 | {
|
63 |
| - State::handle_OnButtonDownReleased(); |
64 | 44 | return this;
|
65 | 45 | }
|
66 | 46 |
|
67 |
| -State * ShoulderState::handle_OnButtonUp() |
| 47 | +State * ShoulderState::handle_OnDown() |
68 | 48 | {
|
69 | 49 | return this;
|
70 | 50 | }
|
71 | 51 |
|
72 |
| -State * ShoulderState::handle_OnButtonLeft() |
| 52 | +State * ShoulderState::handle_OnLeft() |
73 | 53 | {
|
74 | 54 | return this;
|
75 | 55 | }
|
76 | 56 |
|
77 |
| -State * ShoulderState::handle_OnButtonRight() |
| 57 | +State * ShoulderState::handle_OnRight() |
78 | 58 | {
|
79 | 59 | return this;
|
80 | 60 | }
|
81 | 61 |
|
82 |
| -State * ShoulderState::handle_OnButtonEnter() |
83 |
| -{ |
84 |
| - return new ElbowState(); |
85 |
| -} |
86 |
| - |
87 | 62 | /**************************************************************************************
|
88 | 63 | * ElbowState
|
89 | 64 | **************************************************************************************/
|
90 | 65 |
|
91 |
| -void ElbowState::onEnter() |
| 66 | +ElbowState::ElbowState() |
92 | 67 | {
|
93 | 68 | Braccio.lvgl_lock();
|
94 | 69 | lv_label_set_text(label, "Elbow");
|
95 | 70 | Braccio.lvgl_unlock();
|
96 | 71 | }
|
97 | 72 |
|
98 |
| -void ElbowState::onExit() |
| 73 | +State * ElbowState::handle_OnEnter() |
99 | 74 | {
|
100 |
| - |
| 75 | + return new WristState(); |
101 | 76 | }
|
102 | 77 |
|
103 |
| -State * ElbowState::handle_OnButtonDownPressed() |
| 78 | +State * ElbowState::handle_OnUp() |
104 | 79 | {
|
105 |
| - State::handle_OnButtonDownPressed(); |
106 | 80 | return this;
|
107 | 81 | }
|
108 | 82 |
|
109 |
| -State * ElbowState::handle_OnButtonDownReleased() |
| 83 | +State * ElbowState::handle_OnDown() |
110 | 84 | {
|
111 |
| - State::handle_OnButtonDownReleased(); |
112 | 85 | return this;
|
113 | 86 | }
|
114 | 87 |
|
115 |
| -State * ElbowState::handle_OnButtonUp() |
116 |
| -{ |
117 |
| - return new WristState(); |
118 |
| -} |
119 |
| - |
120 |
| -State * ElbowState::handle_OnButtonEnter() |
121 |
| -{ |
122 |
| - return new WristState(); |
123 |
| -} |
124 |
| - |
125 | 88 | /**************************************************************************************
|
126 | 89 | * WristState
|
127 | 90 | **************************************************************************************/
|
128 | 91 |
|
129 |
| -void WristState::onEnter() |
| 92 | +WristState::WristState() |
130 | 93 | {
|
131 | 94 | Braccio.lvgl_lock();
|
132 | 95 | lv_label_set_text(label, "Wrist");
|
133 | 96 | Braccio.lvgl_unlock();
|
134 | 97 | }
|
135 | 98 |
|
136 |
| -void WristState::onExit() |
137 |
| -{ |
138 |
| - |
139 |
| -} |
140 |
| - |
141 |
| -State * WristState::handle_OnButtonDownPressed() |
| 99 | +State * WristState::handle_OnEnter() |
142 | 100 | {
|
143 |
| - State::handle_OnButtonDownPressed(); |
144 |
| - return this; |
| 101 | + return new PinchState(); |
145 | 102 | }
|
146 | 103 |
|
147 |
| -State * WristState::handle_OnButtonDownReleased() |
| 104 | +State * WristState::handle_OnUp() |
148 | 105 | {
|
149 |
| - State::handle_OnButtonDownReleased(); |
150 | 106 | return this;
|
151 | 107 | }
|
152 | 108 |
|
153 |
| -State * WristState::handle_OnButtonUp() |
| 109 | +State * WristState::handle_OnDown() |
154 | 110 | {
|
155 | 111 | return this;
|
156 | 112 | }
|
157 | 113 |
|
158 |
| -State * WristState::handle_OnButtonLeft() |
| 114 | +State * WristState::handle_OnLeft() |
159 | 115 | {
|
160 | 116 | return this;
|
161 | 117 | }
|
162 | 118 |
|
163 |
| -State * WristState::handle_OnButtonRight() |
| 119 | +State * WristState::handle_OnRight() |
164 | 120 | {
|
165 | 121 | return this;
|
166 | 122 | }
|
167 | 123 |
|
168 |
| -State * WristState::handle_OnButtonEnter() |
169 |
| -{ |
170 |
| - return new PinchState(); |
171 |
| -} |
172 |
| - |
173 | 124 | /**************************************************************************************
|
174 | 125 | * PinchState
|
175 | 126 | **************************************************************************************/
|
176 | 127 |
|
177 |
| -void PinchState::onEnter() |
| 128 | +PinchState::PinchState() |
178 | 129 | {
|
179 | 130 | Braccio.lvgl_lock();
|
180 | 131 | lv_label_set_text(label, "Pinch");
|
181 | 132 | Braccio.lvgl_unlock();
|
182 | 133 | }
|
183 | 134 |
|
184 |
| -void PinchState::onExit() |
| 135 | +State * PinchState::handle_OnEnter() |
185 | 136 | {
|
186 |
| - |
| 137 | + return new ShoulderState(); |
187 | 138 | }
|
188 | 139 |
|
189 |
| -State * PinchState::handle_OnButtonLeft() |
| 140 | +State * PinchState::handle_OnLeft() |
190 | 141 | {
|
| 142 | + gripper.move().to(gripper.position() + 10.0f).in(10ms); |
191 | 143 | return this;
|
192 | 144 | }
|
193 | 145 |
|
194 |
| -State * PinchState::handle_OnButtonRight() |
| 146 | +State * PinchState::handle_OnRight() |
195 | 147 | {
|
| 148 | + gripper.move().to(gripper.position() - 10.0f).in(10ms); |
196 | 149 | return this;
|
197 | 150 | }
|
198 |
| - |
199 |
| -State * PinchState::handle_OnButtonEnter() |
200 |
| -{ |
201 |
| - return new ShoulderState(); |
202 |
| -} |
0 commit comments