@@ -164,6 +164,17 @@ extern "C" void app_main(void) {
164164 lv_line_set_points (line1, line_points1, 2 );
165165 lv_obj_add_style (line1, &style_line1, 0 );
166166
167+ static auto rotate_display = [&]() {
168+ std::lock_guard<std::recursive_mutex> lock (lvgl_mutex);
169+ clear_circles ();
170+ static auto rotation = LV_DISPLAY_ROTATION_0;
171+ rotation = static_cast <lv_display_rotation_t >((static_cast <int >(rotation) + 1 ) % 4 );
172+ lv_display_t *disp = lv_display_get_default ();
173+ lv_disp_set_rotation (disp, rotation);
174+ // update the size of the screen
175+ lv_obj_set_size (bg, box.rotated_display_width (), box.rotated_display_height ());
176+ };
177+
167178 // add a button in the top left which (when pressed) will rotate the display
168179 // through 0, 90, 180, 270 degrees
169180 lv_obj_t *btn = lv_btn_create (lv_screen_active ());
@@ -174,16 +185,7 @@ extern "C" void app_main(void) {
174185 // center the text in the button
175186 lv_obj_align (label_btn, LV_ALIGN_CENTER, 0 , 0 );
176187 lv_obj_add_event_cb (
177- btn,
178- [](auto event) {
179- std::lock_guard<std::recursive_mutex> lock (lvgl_mutex);
180- clear_circles ();
181- static auto rotation = LV_DISPLAY_ROTATION_0;
182- rotation = static_cast <lv_display_rotation_t >((static_cast <int >(rotation) + 1 ) % 4 );
183- lv_display_t *disp = lv_display_get_default ();
184- lv_disp_set_rotation (disp, rotation);
185- },
186- LV_EVENT_PRESSED, nullptr );
188+ btn, [](auto event) { rotate_display (); }, LV_EVENT_PRESSED, nullptr );
187189
188190 // disable scrolling on the screen (so that it doesn't behave weirdly when
189191 // rotated and drawing with your finger)
@@ -276,13 +278,15 @@ extern "C" void app_main(void) {
276278
277279 // use the pitch to to draw a line on the screen indiating the
278280 // direction from the center of the screen to "down"
279- int x0 = box.lcd_width () / 2 ;
280- int y0 = box.lcd_height () / 2 ;
281+ int x0 = box.rotated_display_width () / 2 ;
282+ int y0 = box.rotated_display_height () / 2 ;
281283
282284 int x1 = x0 + 50 * gravity_vector.x ;
283285 int y1 = y0 + 50 * gravity_vector.y ;
284286
285287 static lv_point_precise_t line_points0[] = {{x0, y0}, {x1, y1}};
288+ line_points0[0 ].x = x0;
289+ line_points0[0 ].y = y0;
286290 line_points0[1 ].x = x1;
287291 line_points0[1 ].y = y1;
288292
@@ -317,6 +321,8 @@ extern "C" void app_main(void) {
317321 y1 = y0 + 50 * vy;
318322
319323 static lv_point_precise_t line_points1[] = {{x0, y0}, {x1, y1}};
324+ line_points1[0 ].x = x0;
325+ line_points1[0 ].y = y0;
320326 line_points1[1 ].x = x1;
321327 line_points1[1 ].y = y1;
322328
0 commit comments