@@ -28,10 +28,12 @@ static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITIO
2828
2929
3030static void eventHandlerMenu (lv_event_t * e) {
31+ Braccio.lvgl_lock ();
3132 lv_event_code_t code = lv_event_get_code (e);
3233 lv_obj_t * obj = lv_event_get_target (e);
3334
3435 if (code == LV_EVENT_KEY && lv_indev_get_key (lv_indev_get_act ()) == LV_KEY_HOME) {
36+ Braccio.lvgl_unlock ();
3537 state = ZERO_POSITION;
3638 return ;
3739 }
@@ -94,9 +96,12 @@ static void eventHandlerMenu(lv_event_t * e) {
9496 break ;
9597 }
9698 }
99+ Braccio.lvgl_unlock ();
97100}
98101
99- void mainMenu () {
102+ void mainMenu ()
103+ {
104+ Braccio.lvgl_lock ();
100105 static lv_style_t style_focus;
101106 lv_style_init (&style_focus);
102107 lv_style_set_outline_color (&style_focus, lv_color_hex (COLOR_ORANGE));
@@ -128,6 +133,7 @@ void mainMenu() {
128133 lv_obj_align (counter, LV_ALIGN_CENTER, 0 , 80 );
129134
130135 lv_obj_add_event_cb (btnm, eventHandlerMenu, LV_EVENT_ALL, NULL );
136+ Braccio.lvgl_unlock ();
131137
132138 Braccio.connectJoystickTo (btnm);
133139}
@@ -150,8 +156,10 @@ void loop() {
150156 if (sample_cnt >= MAX_SAMPLES) {
151157 state = ZERO_POSITION;
152158 Serial.println (" ZERO_POSITION" );
159+ Braccio.lvgl_lock ();
153160 btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
154161 lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_CHECKABLE);
162+ Braccio.lvgl_unlock ();
155163 }
156164 /* Capture those samples. */
157165 Braccio.positions (idx);
@@ -165,12 +173,16 @@ void loop() {
165173 if (idx >= final_idx) {
166174 Serial.println (" REPLAY done" );
167175 state = ZERO_POSITION;
176+ Braccio.lvgl_lock ();
168177 btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
169178 lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
179+ Braccio.lvgl_unlock ();
170180 }
171181 }
172182 delay (100 );
173183 if (state != ZERO_POSITION) {
184+ Braccio.lvgl_lock ();
174185 lv_label_set_text_fmt (counter, " Counter: %d" , (sample_cnt / 6 ));
186+ Braccio.lvgl_unlock ();
175187 }
176188}
0 commit comments