88// ENTER button
99#define BUTTON_ENTER 6
1010
11- enum states {
11+ enum class State
12+ {
1213 RECORD,
1314 REPLAY,
1415 ZERO_POSITION
1516};
1617
17- int state = ZERO_POSITION;
18+ State state = State:: ZERO_POSITION;
1819
1920static int const MAX_SAMPLES = 6 *100 *2 ; /* 20 seconds. */
2021
@@ -45,7 +46,7 @@ static void eventHandlerMenu(lv_event_t * e)
4546 case 0 : // if the button pressed is the first one
4647 if (txt == " RECORD" )
4748 {
48- state = RECORD;
49+ state = State:: RECORD;
4950 sample_cnt = 0 ;
5051 Braccio.disengage (); // allow the user to freely move the braccio
5152 lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_CHECKED);
@@ -55,7 +56,7 @@ static void eventHandlerMenu(lv_event_t * e)
5556 }
5657 else if (txt == " STOP" )
5758 {
58- state = ZERO_POSITION;
59+ state = State:: ZERO_POSITION;
5960 Braccio.engage (); // enable the steppers so that the braccio stands still
6061 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
6162 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)
6566 btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
6667 if (txt == " REPLAY" )
6768 {
68- state = REPLAY;
69+ state = State:: REPLAY;
6970 replay_cnt = 0 ;
7071 btnm_map[2 ] = " STOP" ; // change the label of the second button to "STOP"
7172 Braccio.engage ();
7273 lv_btnmatrix_set_btn_ctrl (btnm, 1 , LV_BTNMATRIX_CTRL_CHECKED);
7374 }
7475 else if (txt==" STOP" )
7576 {
76- state = ZERO_POSITION;
77+ state = State:: ZERO_POSITION;
7778 Braccio.engage (); // enable the steppers so that the braccio stands still
7879 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
7980 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)
8283 break ;
8384
8485 default :
85- state = ZERO_POSITION;
86+ state = State:: ZERO_POSITION;
8687 btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
8788 btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
8889 Braccio.engage ();
@@ -154,12 +155,12 @@ void loop()
154155 {
155156 prev = now;
156157
157- if (state == RECORD)
158+ if (state == State:: RECORD)
158159 {
159160 /* Check if we still have space for samples. */
160161 if (sample_cnt >= MAX_SAMPLES)
161162 {
162- state = ZERO_POSITION;
163+ state = State:: ZERO_POSITION;
163164 replay_cnt = 0 ;
164165 Braccio.lvgl_lock ();
165166 btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
@@ -178,14 +179,14 @@ void loop()
178179 Braccio.lvgl_unlock ();
179180 }
180181
181- if (state == REPLAY)
182+ if (state == State:: REPLAY)
182183 {
183184 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 ]);
184185 replay_cnt += 6 ;
185186
186187 if (replay_cnt >= sample_cnt)
187188 {
188- state = ZERO_POSITION;
189+ state = State:: ZERO_POSITION;
189190 Braccio.lvgl_lock ();
190191 btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
191192 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
@@ -197,7 +198,7 @@ void loop()
197198 Braccio.lvgl_unlock ();
198199 }
199200
200- if (state == ZERO_POSITION)
201+ if (state == State:: ZERO_POSITION)
201202 {
202203 Braccio.engage ();
203204 Braccio.moveTo (homePos[0 ], homePos[1 ], homePos[2 ], homePos[3 ], homePos[4 ], homePos[5 ]);
0 commit comments