@@ -27,6 +27,8 @@ static float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
27
27
28
28
lv_obj_t * counter;
29
29
lv_obj_t * btnm;
30
+ lv_obj_t * menu_screen = nullptr ;
31
+ lv_obj_t * stop_screen = nullptr ;
30
32
const char * btnm_map[] = { " RECORD" , " \n " , " REPLAY" , " \n " , " ZERO_POSITION" , " \n " , " \0 " };
31
33
32
34
static float sample_buf[SAMPLE_BUF_SIZE];
@@ -90,6 +92,17 @@ void custom_main_menu()
90
92
lv_obj_align (counter, LV_ALIGN_CENTER, 0 , 80 );
91
93
92
94
lv_obj_add_event_cb (btnm, event_handler_menu, LV_EVENT_ALL, NULL );
95
+
96
+ /* Store a pointer to the screen in the menu_screen variable. */
97
+ menu_screen = lv_scr_act ();
98
+
99
+ /* Create a separate screen for the stop sign image. */
100
+ LV_IMG_DECLARE (stop_sign);
101
+ stop_screen = lv_img_create (NULL );
102
+ lv_img_set_src (stop_screen, &stop_sign);
103
+ lv_obj_align (stop_screen, LV_ALIGN_CENTER, 0 , 0 );
104
+ lv_obj_set_size (stop_screen, 240 , 240 );
105
+
93
106
Braccio.lvgl_unlock ();
94
107
95
108
Braccio.connectJoystickTo (btnm);
@@ -166,7 +179,28 @@ State * RecordState::handle_OnTimerTick()
166
179
167
180
/* We still have space, let's sample some data. */
168
181
Braccio.positions (sample_buf + sample_cnt);
169
- sample_cnt += 6 ;
182
+
183
+ /* Check if any of the servos reports a position of
184
+ * 0.0 degrees. In this case we've entered the dead
185
+ * zone and should display a warning on the screen.
186
+ **/
187
+ int const count = std::count_if (sample_buf + sample_cnt,
188
+ sample_buf + sample_cnt + 6 ,
189
+ [](float const v)
190
+ {
191
+ float const EPSILON = 0.01 ;
192
+ return (fabs (v) < EPSILON);
193
+ });
194
+ if (count > 0 ) {
195
+ if (lv_scr_act () != stop_screen)
196
+ lv_scr_load (stop_screen);
197
+ }
198
+ else {
199
+ sample_cnt += 6 ;
200
+ /* Reload the menu screen if it has not been currently loaded. */
201
+ if (lv_scr_act () != menu_screen)
202
+ lv_scr_load (menu_screen);
203
+ }
170
204
171
205
/* Update sample counter. */
172
206
lv_label_set_text_fmt (counter, " Counter: %d" , (sample_cnt / 6 ));
0 commit comments