@@ -27,7 +27,18 @@ extern "C" void app_main(void) {
2727 espp::TDeck &tdeck = espp::TDeck::get ();
2828 tdeck.set_log_level (espp::Logger::Verbosity::INFO );
2929
30+ lv_obj_t *bg = nullptr ;
31+
3032 static auto rotation = LV_DISPLAY_ROTATION_0 ;
33+ static auto rotate_display = [&]() {
34+ std::lock_guard<std::recursive_mutex> lock (lvgl_mutex);
35+ clear_circles ();
36+ rotation = static_cast <lv_display_rotation_t >((static_cast <int >(rotation) + 1 ) % 4 );
37+ lv_display_t *disp = lv_display_get_default ();
38+ lv_disp_set_rotation (disp, rotation);
39+ // update the size of the screen
40+ lv_obj_set_size (bg, tdeck.rotated_display_width (), tdeck.rotated_display_height ());
41+ };
3142
3243 auto keypress_callback = [&](uint8_t key) {
3344 logger.info (" Key pressed: {}" , key);
@@ -41,9 +52,7 @@ extern "C" void app_main(void) {
4152 logger.info (" Rotating display" );
4253 std::lock_guard<std::recursive_mutex> lock (lvgl_mutex);
4354 clear_circles ();
44- rotation = static_cast <lv_display_rotation_t >((static_cast <int >(rotation) + 1 ) % 4 );
45- lv_display_t *disp = lv_display_get_default ();
46- lv_disp_set_rotation (disp, rotation);
55+ rotate_display ();
4756 } else if (key == ' m' ) {
4857 // 'm' key will toggle audio mute
4958 logger.info (" Toggling mute" );
@@ -126,7 +135,7 @@ extern "C" void app_main(void) {
126135 }
127136
128137 // set the background color to black
129- lv_obj_t * bg = lv_obj_create (lv_screen_active ());
138+ bg = lv_obj_create (lv_screen_active ());
130139 lv_obj_set_size (bg, tdeck.lcd_width (), tdeck.lcd_height ());
131140 lv_obj_set_style_bg_color (bg, lv_color_make (0 , 0 , 0 ), 0 );
132141
@@ -147,15 +156,7 @@ extern "C" void app_main(void) {
147156 // center the text in the button
148157 lv_obj_align (label_btn, LV_ALIGN_CENTER , 0 , 0 );
149158 lv_obj_add_event_cb (
150- btn,
151- [](auto event) {
152- std::lock_guard<std::recursive_mutex> lock (lvgl_mutex);
153- clear_circles ();
154- rotation = static_cast <lv_display_rotation_t >((static_cast <int >(rotation) + 1 ) % 4 );
155- lv_display_t *disp = lv_display_get_default ();
156- lv_disp_set_rotation (disp, rotation);
157- },
158- LV_EVENT_PRESSED , nullptr );
159+ btn, [](auto event) { rotate_display (); }, LV_EVENT_PRESSED , nullptr );
159160
160161 // disable scrolling on the screen (so that it doesn't behave weirdly when
161162 // rotated and drawing with your finger)
0 commit comments