77
88enum states {
99 LEARN,
10- REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO
11- IDLE
10+ REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO
11+ ZERO_POSITION
1212};
1313
14- int state = IDLE ;
14+ int state = ZERO_POSITION ;
1515
1616float values[10000 ];
1717float * idx = values;
@@ -21,15 +21,15 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
2121static lv_obj_t * counter;
2222static lv_obj_t * btnm;
2323
24- static const char * btnm_map[] = { " LEARN" , " \n " , " REPLAY " , " \n " , " IDLE " , " \n " , " \0 " };
24+ static const char * btnm_map[] = { " LEARN" , " \n " , " REPEAT " , " \n " , " ZERO_POSITION " , " \n " , " \0 " };
2525
2626
2727static void eventHandlerMenu (lv_event_t * e) {
2828 lv_event_code_t code = lv_event_get_code (e);
2929 lv_obj_t * obj = lv_event_get_target (e);
3030
3131 if (code == LV_EVENT_KEY && lv_indev_get_key (lv_indev_get_act ()) == LV_KEY_HOME) {
32- state = IDLE ;
32+ state = ZERO_POSITION ;
3333 return ;
3434 }
3535
@@ -54,27 +54,39 @@ static void eventHandlerMenu(lv_event_t * e) {
5454 btnm_map[0 ] = " STOP" ; // change the label of the first button to "STOP"
5555 }
5656 else if (txt == " STOP" ) {
57- state = IDLE ;
57+ state = ZERO_POSITION ;
5858 Braccio.engage (); // enable the steppers so that the braccio stands still
5959 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
6060 btnm_map[0 ] = " LEARN" ; // reset the label of the first button back to "LEARN"
6161 }
6262 break ;
6363 case 1 :
64- state = REPEAT;
6564 btnm_map[0 ] = " LEARN" ; // reset the label of the first button back to "LEARN"
65+ if (txt == " REPEAT" ){
66+ state = REPEAT;
67+ btnm_map[2 ] = " STOP" ; // change the label of the second button to "STOP"
6668 Braccio.engage ();
6769 lv_btnmatrix_set_btn_ctrl (btnm, 1 , LV_BTNMATRIX_CTRL_CHECKED);
6870 Serial.println (" REPEAT" );
71+ }
72+ else if (txt==" STOP" ){
73+ state = ZERO_POSITION;
74+ Braccio.engage (); // enable the steppers so that the braccio stands still
75+ lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
76+ btnm_map[2 ] = " REPEAT" ; // reset the label of the first button back to "REPEAT"
77+ }
78+
6979 break ;
80+
7081 default :
71- state = IDLE ;
82+ state = ZERO_POSITION ;
7283 btnm_map[0 ] = " LEARN" ; // reset the label of the first button back to "LEARN"
84+ btnm_map[2 ] = " REPEAT" ; // reset the label of the first button back to "REPEAT"
7385 Braccio.engage ();
7486 delay (500 );
7587 Braccio.moveTo (homePos[0 ], homePos[1 ], homePos[2 ], homePos[3 ], homePos[4 ], homePos[5 ]);
7688 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
77- Serial.println (" IDLE " );
89+ Serial.println (" ZERO_POSITION " );
7890 break ;
7991 }
8092 }
@@ -137,16 +149,17 @@ void loop() {
137149 idx += 6 ;
138150 if (idx >= final_idx) {
139151 Serial.println (" Repeat done" );
140- state = IDLE;
152+ state = ZERO_POSITION;
153+ btnm_map[2 ] = " REPEAT" ; // reset the label of the first button back to "REPEAT"
141154 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
142155 }
143156 }
144157 if (idx - values >= sizeof (values)) {
145- Serial.println (" IDLE " );
146- state = IDLE ;
158+ Serial.println (" ZERO_POSITION " );
159+ state = ZERO_POSITION ;
147160 }
148161 delay (100 );
149- if (state != IDLE ) {
162+ if (state != ZERO_POSITION ) {
150163 lv_label_set_text_fmt (counter, " Counter: %d" , idx - values);
151164 }
152165}
0 commit comments