8
8
// ENTER button
9
9
#define BUTTON_ENTER 6
10
10
11
- enum states {
11
+ enum class State
12
+ {
12
13
RECORD,
13
14
REPLAY,
14
15
ZERO_POSITION
15
16
};
16
17
17
- int state = ZERO_POSITION;
18
+ State state = State:: ZERO_POSITION;
18
19
19
20
static int const MAX_SAMPLES = 6 *100 *2 ; /* 20 seconds. */
20
21
@@ -45,7 +46,7 @@ static void eventHandlerMenu(lv_event_t * e)
45
46
case 0 : // if the button pressed is the first one
46
47
if (txt == " RECORD" )
47
48
{
48
- state = RECORD;
49
+ state = State:: RECORD;
49
50
sample_cnt = 0 ;
50
51
Braccio.disengage (); // allow the user to freely move the braccio
51
52
lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_CHECKED);
@@ -55,7 +56,7 @@ static void eventHandlerMenu(lv_event_t * e)
55
56
}
56
57
else if (txt == " STOP" )
57
58
{
58
- state = ZERO_POSITION;
59
+ state = State:: ZERO_POSITION;
59
60
Braccio.engage (); // enable the steppers so that the braccio stands still
60
61
lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
61
62
btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
@@ -65,15 +66,15 @@ static void eventHandlerMenu(lv_event_t * e)
65
66
btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
66
67
if (txt == " REPLAY" )
67
68
{
68
- state = REPLAY;
69
+ state = State:: REPLAY;
69
70
replay_cnt = 0 ;
70
71
btnm_map[2 ] = " STOP" ; // change the label of the second button to "STOP"
71
72
Braccio.engage ();
72
73
lv_btnmatrix_set_btn_ctrl (btnm, 1 , LV_BTNMATRIX_CTRL_CHECKED);
73
74
}
74
75
else if (txt==" STOP" )
75
76
{
76
- state = ZERO_POSITION;
77
+ state = State:: ZERO_POSITION;
77
78
Braccio.engage (); // enable the steppers so that the braccio stands still
78
79
lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
79
80
btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
@@ -82,7 +83,7 @@ static void eventHandlerMenu(lv_event_t * e)
82
83
break ;
83
84
84
85
default :
85
- state = ZERO_POSITION;
86
+ state = State:: ZERO_POSITION;
86
87
btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
87
88
btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
88
89
Braccio.engage ();
@@ -154,12 +155,12 @@ void loop()
154
155
{
155
156
prev = now;
156
157
157
- if (state == RECORD)
158
+ if (state == State:: RECORD)
158
159
{
159
160
/* Check if we still have space for samples. */
160
161
if (sample_cnt >= MAX_SAMPLES)
161
162
{
162
- state = ZERO_POSITION;
163
+ state = State:: ZERO_POSITION;
163
164
replay_cnt = 0 ;
164
165
Braccio.lvgl_lock ();
165
166
btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
@@ -178,14 +179,14 @@ void loop()
178
179
Braccio.lvgl_unlock ();
179
180
}
180
181
181
- if (state == REPLAY)
182
+ if (state == State:: REPLAY)
182
183
{
183
184
Braccio.moveTo (values[replay_cnt + 0 ], values[replay_cnt + 1 ], values[replay_cnt + 2 ], values[replay_cnt + 3 ], values[replay_cnt + 4 ], values[replay_cnt + 5 ]);
184
185
replay_cnt += 6 ;
185
186
186
187
if (replay_cnt >= sample_cnt)
187
188
{
188
- state = ZERO_POSITION;
189
+ state = State:: ZERO_POSITION;
189
190
Braccio.lvgl_lock ();
190
191
btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
191
192
lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
@@ -197,7 +198,7 @@ void loop()
197
198
Braccio.lvgl_unlock ();
198
199
}
199
200
200
- if (state == ZERO_POSITION)
201
+ if (state == State:: ZERO_POSITION)
201
202
{
202
203
Braccio.engage ();
203
204
Braccio.moveTo (homePos[0 ], homePos[1 ], homePos[2 ], homePos[3 ], homePos[4 ], homePos[5 ]);
0 commit comments