mirror of
https://github.com/esphome/esphome.git
synced 2025-11-20 08:46:01 +00:00
[lvgl] Fix rotation with unusual width (#11680)
This commit is contained in:
@@ -11,4 +11,5 @@ CONF_DRAW_ROUNDING = "draw_rounding"
|
|||||||
CONF_ON_RECEIVE = "on_receive"
|
CONF_ON_RECEIVE = "on_receive"
|
||||||
CONF_ON_STATE_CHANGE = "on_state_change"
|
CONF_ON_STATE_CHANGE = "on_state_change"
|
||||||
CONF_REQUEST_HEADERS = "request_headers"
|
CONF_REQUEST_HEADERS = "request_headers"
|
||||||
|
CONF_ROWS = "rows"
|
||||||
CONF_USE_PSRAM = "use_psram"
|
CONF_USE_PSRAM = "use_psram"
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ bool LvPageType::is_showing() const { return this->parent_->get_current_page() =
|
|||||||
void LvglComponent::draw_buffer_(const lv_area_t *area, lv_color_t *ptr) {
|
void LvglComponent::draw_buffer_(const lv_area_t *area, lv_color_t *ptr) {
|
||||||
auto width = lv_area_get_width(area);
|
auto width = lv_area_get_width(area);
|
||||||
auto height = lv_area_get_height(area);
|
auto height = lv_area_get_height(area);
|
||||||
|
auto height_rounded = (height + this->draw_rounding - 1) / this->draw_rounding * this->draw_rounding;
|
||||||
auto x1 = area->x1;
|
auto x1 = area->x1;
|
||||||
auto y1 = area->y1;
|
auto y1 = area->y1;
|
||||||
lv_color_t *dst = this->rotate_buf_;
|
lv_color_t *dst = this->rotate_buf_;
|
||||||
@@ -178,13 +179,13 @@ void LvglComponent::draw_buffer_(const lv_area_t *area, lv_color_t *ptr) {
|
|||||||
case display::DISPLAY_ROTATION_90_DEGREES:
|
case display::DISPLAY_ROTATION_90_DEGREES:
|
||||||
for (lv_coord_t x = height; x-- != 0;) {
|
for (lv_coord_t x = height; x-- != 0;) {
|
||||||
for (lv_coord_t y = 0; y != width; y++) {
|
for (lv_coord_t y = 0; y != width; y++) {
|
||||||
dst[y * height + x] = *ptr++;
|
dst[y * height_rounded + x] = *ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y1 = x1;
|
y1 = x1;
|
||||||
x1 = this->disp_drv_.ver_res - area->y1 - height;
|
x1 = this->disp_drv_.ver_res - area->y1 - height;
|
||||||
width = height;
|
height = width;
|
||||||
height = lv_area_get_width(area);
|
width = height_rounded;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case display::DISPLAY_ROTATION_180_DEGREES:
|
case display::DISPLAY_ROTATION_180_DEGREES:
|
||||||
@@ -200,13 +201,13 @@ void LvglComponent::draw_buffer_(const lv_area_t *area, lv_color_t *ptr) {
|
|||||||
case display::DISPLAY_ROTATION_270_DEGREES:
|
case display::DISPLAY_ROTATION_270_DEGREES:
|
||||||
for (lv_coord_t x = 0; x != height; x++) {
|
for (lv_coord_t x = 0; x != height; x++) {
|
||||||
for (lv_coord_t y = width; y-- != 0;) {
|
for (lv_coord_t y = width; y-- != 0;) {
|
||||||
dst[y * height + x] = *ptr++;
|
dst[y * height_rounded + x] = *ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x1 = y1;
|
x1 = y1;
|
||||||
y1 = this->disp_drv_.hor_res - area->x1 - width;
|
y1 = this->disp_drv_.hor_res - area->x1 - width;
|
||||||
width = height;
|
height = width;
|
||||||
height = lv_area_get_width(area);
|
width = height_rounded;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -443,8 +444,10 @@ LvglComponent::LvglComponent(std::vector<display::Display *> displays, float buf
|
|||||||
|
|
||||||
void LvglComponent::setup() {
|
void LvglComponent::setup() {
|
||||||
auto *display = this->displays_[0];
|
auto *display = this->displays_[0];
|
||||||
auto width = display->get_width();
|
auto rounding = this->draw_rounding;
|
||||||
auto height = display->get_height();
|
// cater for displays with dimensions that don't divide by the required rounding
|
||||||
|
auto width = (display->get_width() + rounding - 1) / rounding * rounding;
|
||||||
|
auto height = (display->get_height() + rounding - 1) / rounding * rounding;
|
||||||
auto frac = this->buffer_frac_;
|
auto frac = this->buffer_frac_;
|
||||||
if (frac == 0)
|
if (frac == 0)
|
||||||
frac = 1;
|
frac = 1;
|
||||||
@@ -469,9 +472,8 @@ void LvglComponent::setup() {
|
|||||||
}
|
}
|
||||||
this->buffer_frac_ = frac;
|
this->buffer_frac_ = frac;
|
||||||
lv_disp_draw_buf_init(&this->draw_buf_, buffer, nullptr, buffer_pixels);
|
lv_disp_draw_buf_init(&this->draw_buf_, buffer, nullptr, buffer_pixels);
|
||||||
this->disp_drv_.hor_res = width;
|
this->disp_drv_.hor_res = display->get_width();
|
||||||
this->disp_drv_.ver_res = height;
|
this->disp_drv_.ver_res = display->get_height();
|
||||||
// this->setup_driver_(display->get_width(), display->get_height());
|
|
||||||
lv_disp_drv_update(this->disp_, &this->disp_drv_);
|
lv_disp_drv_update(this->disp_, &this->disp_drv_);
|
||||||
this->rotation = display->get_rotation();
|
this->rotation = display->get_rotation();
|
||||||
if (this->rotation != display::DISPLAY_ROTATION_0_DEGREES) {
|
if (this->rotation != display::DISPLAY_ROTATION_0_DEGREES) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from esphome import automation
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
from esphome.components.const import CONF_ROWS
|
||||||
from esphome.components.key_provider import KeyProvider
|
from esphome.components.key_provider import KeyProvider
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_ITEMS, CONF_ROWS, CONF_TEXT, CONF_WIDTH
|
from esphome.const import CONF_ID, CONF_ITEMS, CONF_TEXT, CONF_WIDTH
|
||||||
from esphome.cpp_generator import MockObj
|
from esphome.cpp_generator import MockObj
|
||||||
|
|
||||||
from ..automation import action_to_code
|
from ..automation import action_to_code
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from esphome import automation, pins
|
from esphome import automation, pins
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.components import key_provider
|
from esphome.components import key_provider
|
||||||
|
from esphome.components.const import CONF_ROWS
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_ON_KEY, CONF_PIN, CONF_ROWS, CONF_TRIGGER_ID
|
from esphome.const import CONF_ID, CONF_ON_KEY, CONF_PIN, CONF_TRIGGER_ID
|
||||||
|
|
||||||
CODEOWNERS = ["@ssieb"]
|
CODEOWNERS = ["@ssieb"]
|
||||||
|
|
||||||
|
|||||||
@@ -838,7 +838,6 @@ CONF_RMT_CHANNEL = "rmt_channel"
|
|||||||
CONF_RMT_SYMBOLS = "rmt_symbols"
|
CONF_RMT_SYMBOLS = "rmt_symbols"
|
||||||
CONF_ROTATION = "rotation"
|
CONF_ROTATION = "rotation"
|
||||||
CONF_ROW = "row"
|
CONF_ROW = "row"
|
||||||
CONF_ROWS = "rows"
|
|
||||||
CONF_RS_PIN = "rs_pin"
|
CONF_RS_PIN = "rs_pin"
|
||||||
CONF_RTD_NOMINAL_RESISTANCE = "rtd_nominal_resistance"
|
CONF_RTD_NOMINAL_RESISTANCE = "rtd_nominal_resistance"
|
||||||
CONF_RTD_WIRES = "rtd_wires"
|
CONF_RTD_WIRES = "rtd_wires"
|
||||||
|
|||||||
Reference in New Issue
Block a user