Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions components/t-deck/example/main/t_deck_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ extern "C" void app_main(void) {
espp::TDeck &tdeck = espp::TDeck::get();
tdeck.set_log_level(espp::Logger::Verbosity::INFO);

lv_obj_t *bg = nullptr;

static auto rotation = LV_DISPLAY_ROTATION_0;
static auto rotate_display = [&]() {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = lv_display_get_default();
lv_disp_set_rotation(disp, rotation);
// update the size of the screen
lv_obj_set_size(bg, tdeck.rotated_display_width(), tdeck.rotated_display_height());
};

auto keypress_callback = [&](uint8_t key) {
logger.info("Key pressed: {}", key);
Expand All @@ -41,9 +52,7 @@ extern "C" void app_main(void) {
logger.info("Rotating display");
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = lv_display_get_default();
lv_disp_set_rotation(disp, rotation);
rotate_display();
} else if (key == 'm') {
// 'm' key will toggle audio mute
logger.info("Toggling mute");
Expand Down Expand Up @@ -126,7 +135,7 @@ extern "C" void app_main(void) {
}

// set the background color to black
lv_obj_t *bg = lv_obj_create(lv_screen_active());
bg = lv_obj_create(lv_screen_active());
lv_obj_set_size(bg, tdeck.lcd_width(), tdeck.lcd_height());
lv_obj_set_style_bg_color(bg, lv_color_make(0, 0, 0), 0);

Expand All @@ -147,15 +156,7 @@ extern "C" void app_main(void) {
// center the text in the button
lv_obj_align(label_btn, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(
btn,
[](auto event) {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = lv_display_get_default();
lv_disp_set_rotation(disp, rotation);
},
LV_EVENT_PRESSED, nullptr);
btn, [](auto event) { rotate_display(); }, LV_EVENT_PRESSED, nullptr);

// disable scrolling on the screen (so that it doesn't behave weirdly when
// rotated and drawing with your finger)
Expand Down
16 changes: 16 additions & 0 deletions components/t-deck/include/t-deck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ class TDeck : public BaseComponent {
/// \return The GPIO pin for the LCD data/command signal
static constexpr auto get_lcd_dc_gpio() { return lcd_dc_io; }

/// Get the display width in pixels
/// \return The display width in pixels
static constexpr size_t display_width() { return lcd_width_; }

/// Get the display height in pixels
/// \return The display height in pixels
static constexpr size_t display_height() { return lcd_height_; }

/// Get the display width in pixels, according to the current orientation
/// \return The display width in pixels, according to the current orientation
size_t rotated_display_width() const;

/// Get the display height in pixels, according to the current orientation
/// \return The display height in pixels, according to the current orientation
size_t rotated_display_height() const;

/// Get a shared pointer to the display
/// \return A shared pointer to the display
std::shared_ptr<Display<Pixel>> display() const;
Expand Down
30 changes: 30 additions & 0 deletions components/t-deck/src/t-deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,33 @@ float TDeck::brightness() const {
}
return 0.0f;
}

size_t TDeck::rotated_display_width() const {
auto rotation = lv_display_get_rotation(lv_display_get_default());
switch (rotation) {
// swap
case LV_DISPLAY_ROTATION_90:
case LV_DISPLAY_ROTATION_270:
return lcd_height_;
// as configured
case LV_DISPLAY_ROTATION_0:
case LV_DISPLAY_ROTATION_180:
default:
return lcd_width_;
}
}

size_t TDeck::rotated_display_height() const {
auto rotation = lv_display_get_rotation(lv_display_get_default());
switch (rotation) {
// swap
case LV_DISPLAY_ROTATION_90:
case LV_DISPLAY_ROTATION_270:
return lcd_width_;
// as configured
case LV_DISPLAY_ROTATION_0:
case LV_DISPLAY_ROTATION_180:
default:
return lcd_height_;
}
}