@@ -31,11 +31,17 @@ static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITIO
31
31
32
32
33
33
static void eventHandlerMenu (lv_event_t * e) {
34
+ Braccio.lvgl_lock ();
34
35
lv_event_code_t code = lv_event_get_code (e);
35
36
lv_obj_t * obj = lv_event_get_target (e);
36
37
38
+ if (code == LV_EVENT_KEY && lv_indev_get_key (lv_indev_get_act ()) == LV_KEY_HOME) {
39
+ Braccio.lvgl_unlock ();
40
+ state = ZERO_POSITION;
41
+ return ;
42
+ }
37
43
38
- if (code == LV_EVENT_CLICKED || (code == LV_EVENT_KEY && Braccio. getKey () == BUTTON_ENTER) ) {
44
+ if (code == LV_EVENT_CLICKED) {
39
45
uint32_t id = lv_btnmatrix_get_selected_btn (obj);
40
46
const char * txt = lv_btnmatrix_get_btn_text (obj, id);
41
47
@@ -93,9 +99,12 @@ static void eventHandlerMenu(lv_event_t * e) {
93
99
break ;
94
100
}
95
101
}
102
+ Braccio.lvgl_unlock ();
96
103
}
97
104
98
- void mainMenu () {
105
+ void mainMenu ()
106
+ {
107
+ Braccio.lvgl_lock ();
99
108
static lv_style_t style_focus;
100
109
lv_style_init (&style_focus);
101
110
lv_style_set_outline_color (&style_focus, lv_color_hex (COLOR_ORANGE));
@@ -127,6 +136,7 @@ void mainMenu() {
127
136
lv_obj_align (counter, LV_ALIGN_CENTER, 0 , 80 );
128
137
129
138
lv_obj_add_event_cb (btnm, eventHandlerMenu, LV_EVENT_ALL, NULL );
139
+ Braccio.lvgl_unlock ();
130
140
131
141
Braccio.connectJoystickTo (btnm);
132
142
}
@@ -149,8 +159,10 @@ void loop() {
149
159
if (sample_cnt >= MAX_SAMPLES) {
150
160
state = ZERO_POSITION;
151
161
Serial.println (" ZERO_POSITION" );
162
+ Braccio.lvgl_lock ();
152
163
btnm_map[0 ] = " RECORD" ; // reset the label of the first button back to "RECORD"
153
164
lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_CHECKABLE);
165
+ Braccio.lvgl_unlock ();
154
166
}
155
167
/* Capture those samples. */
156
168
Braccio.positions (idx);
@@ -164,12 +176,16 @@ void loop() {
164
176
if (idx >= final_idx) {
165
177
Serial.println (" REPLAY done" );
166
178
state = ZERO_POSITION;
179
+ Braccio.lvgl_lock ();
167
180
btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
168
181
lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
182
+ Braccio.lvgl_unlock ();
169
183
}
170
184
}
171
185
delay (100 );
172
186
if (state != ZERO_POSITION) {
187
+ Braccio.lvgl_lock ();
173
188
lv_label_set_text_fmt (counter, " Counter: %d" , (sample_cnt / 6 ));
189
+ Braccio.lvgl_unlock ();
174
190
}
175
191
}
0 commit comments