Skip to content

Commit 149c046

Browse files
committed
One SW event per button event.
1 parent 7ceb29c commit 149c046

File tree

3 files changed

+238
-253
lines changed

3 files changed

+238
-253
lines changed

examples/Controlling_Manually_Braccio/AppState.cpp

Lines changed: 37 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,197 +6,145 @@
66

77
#include <Braccio++.h>
88

9-
extern lv_obj_t * label;
10-
extern lv_obj_t * direction_btnm;
9+
/**************************************************************************************
10+
* EXTERN
11+
**************************************************************************************/
1112

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;
1814

1915
/**************************************************************************************
20-
* State
16+
* GLOBAL VARIABLES
2117
**************************************************************************************/
2218

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);
3825

3926
/**************************************************************************************
4027
* ShoulderState
4128
**************************************************************************************/
4229

43-
void ShoulderState::onEnter()
30+
ShoulderState::ShoulderState()
4431
{
4532
Braccio.lvgl_lock();
4633
lv_label_set_text(label, "Shoulder");
4734
Braccio.lvgl_unlock();
4835
}
4936

50-
void ShoulderState::onExit()
37+
State * ShoulderState::handle_OnEnter()
5138
{
52-
53-
}
54-
55-
State * ShoulderState::handle_OnButtonDownPressed()
56-
{
57-
State::handle_OnButtonDownPressed();
58-
return this;
39+
return new ElbowState();
5940
}
6041

61-
State * ShoulderState::handle_OnButtonDownReleased()
42+
State * ShoulderState::handle_OnUp()
6243
{
63-
State::handle_OnButtonDownReleased();
6444
return this;
6545
}
6646

67-
State * ShoulderState::handle_OnButtonUp()
47+
State * ShoulderState::handle_OnDown()
6848
{
6949
return this;
7050
}
7151

72-
State * ShoulderState::handle_OnButtonLeft()
52+
State * ShoulderState::handle_OnLeft()
7353
{
7454
return this;
7555
}
7656

77-
State * ShoulderState::handle_OnButtonRight()
57+
State * ShoulderState::handle_OnRight()
7858
{
7959
return this;
8060
}
8161

82-
State * ShoulderState::handle_OnButtonEnter()
83-
{
84-
return new ElbowState();
85-
}
86-
8762
/**************************************************************************************
8863
* ElbowState
8964
**************************************************************************************/
9065

91-
void ElbowState::onEnter()
66+
ElbowState::ElbowState()
9267
{
9368
Braccio.lvgl_lock();
9469
lv_label_set_text(label, "Elbow");
9570
Braccio.lvgl_unlock();
9671
}
9772

98-
void ElbowState::onExit()
73+
State * ElbowState::handle_OnEnter()
9974
{
100-
75+
return new WristState();
10176
}
10277

103-
State * ElbowState::handle_OnButtonDownPressed()
78+
State * ElbowState::handle_OnUp()
10479
{
105-
State::handle_OnButtonDownPressed();
10680
return this;
10781
}
10882

109-
State * ElbowState::handle_OnButtonDownReleased()
83+
State * ElbowState::handle_OnDown()
11084
{
111-
State::handle_OnButtonDownReleased();
11285
return this;
11386
}
11487

115-
State * ElbowState::handle_OnButtonUp()
116-
{
117-
return new WristState();
118-
}
119-
120-
State * ElbowState::handle_OnButtonEnter()
121-
{
122-
return new WristState();
123-
}
124-
12588
/**************************************************************************************
12689
* WristState
12790
**************************************************************************************/
12891

129-
void WristState::onEnter()
92+
WristState::WristState()
13093
{
13194
Braccio.lvgl_lock();
13295
lv_label_set_text(label, "Wrist");
13396
Braccio.lvgl_unlock();
13497
}
13598

136-
void WristState::onExit()
137-
{
138-
139-
}
140-
141-
State * WristState::handle_OnButtonDownPressed()
99+
State * WristState::handle_OnEnter()
142100
{
143-
State::handle_OnButtonDownPressed();
144-
return this;
101+
return new PinchState();
145102
}
146103

147-
State * WristState::handle_OnButtonDownReleased()
104+
State * WristState::handle_OnUp()
148105
{
149-
State::handle_OnButtonDownReleased();
150106
return this;
151107
}
152108

153-
State * WristState::handle_OnButtonUp()
109+
State * WristState::handle_OnDown()
154110
{
155111
return this;
156112
}
157113

158-
State * WristState::handle_OnButtonLeft()
114+
State * WristState::handle_OnLeft()
159115
{
160116
return this;
161117
}
162118

163-
State * WristState::handle_OnButtonRight()
119+
State * WristState::handle_OnRight()
164120
{
165121
return this;
166122
}
167123

168-
State * WristState::handle_OnButtonEnter()
169-
{
170-
return new PinchState();
171-
}
172-
173124
/**************************************************************************************
174125
* PinchState
175126
**************************************************************************************/
176127

177-
void PinchState::onEnter()
128+
PinchState::PinchState()
178129
{
179130
Braccio.lvgl_lock();
180131
lv_label_set_text(label, "Pinch");
181132
Braccio.lvgl_unlock();
182133
}
183134

184-
void PinchState::onExit()
135+
State * PinchState::handle_OnEnter()
185136
{
186-
137+
return new ShoulderState();
187138
}
188139

189-
State * PinchState::handle_OnButtonLeft()
140+
State * PinchState::handle_OnLeft()
190141
{
142+
gripper.move().to(gripper.position() + 10.0f).in(10ms);
191143
return this;
192144
}
193145

194-
State * PinchState::handle_OnButtonRight()
146+
State * PinchState::handle_OnRight()
195147
{
148+
gripper.move().to(gripper.position() - 10.0f).in(10ms);
196149
return this;
197150
}
198-
199-
State * PinchState::handle_OnButtonEnter()
200-
{
201-
return new ShoulderState();
202-
}

0 commit comments

Comments
 (0)