mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[hub75] add set_rotation and get_rotation methods (#13921)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
J. Nick Koston
parent
6bc19d2a1a
commit
254690100c
@@ -294,7 +294,7 @@ using display_writer_t = DisplayWriter<Display>;
|
||||
prefix type "\n" \
|
||||
"%s Rotations: %d °\n" \
|
||||
"%s Dimensions: %dpx x %dpx", \
|
||||
prefix, log_display_obj->rotation_, prefix, log_display_obj->get_width(), \
|
||||
prefix, log_display_obj->get_rotation(), prefix, log_display_obj->get_width(), \
|
||||
log_display_obj->get_height()); \
|
||||
}
|
||||
|
||||
@@ -710,7 +710,7 @@ class Display : public PollingComponent {
|
||||
// Internal method to set display auto clearing.
|
||||
void set_auto_clear(bool auto_clear_enabled) { this->auto_clear_enabled_ = auto_clear_enabled; }
|
||||
|
||||
DisplayRotation get_rotation() const { return this->rotation_; }
|
||||
virtual DisplayRotation get_rotation() const { return this->rotation_; }
|
||||
|
||||
/** Get the type of display that the buffer corresponds to. In case of dynamically configurable displays,
|
||||
* returns the type the display is currently configured to.
|
||||
|
||||
@@ -601,10 +601,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
pins_struct = _build_pins_struct(pin_expressions, e_pin_num)
|
||||
hub75_config = _build_config_struct(config, pins_struct, min_refresh)
|
||||
|
||||
# Rotation is handled by the hub75 driver (config_.rotation already set above).
|
||||
# Force rotation to 0 for ESPHome's Display base class to avoid double-rotation.
|
||||
if CONF_ROTATION in config:
|
||||
config[CONF_ROTATION] = 0
|
||||
# The driver rotates the panel itself (config_.rotation above), so the base class must not rotate too
|
||||
config.pop(CONF_ROTATION, None)
|
||||
|
||||
# Create display and register
|
||||
var = cg.new_Pvariable(config[CONF_ID], hub75_config)
|
||||
|
||||
@@ -202,6 +202,46 @@ void HUB75Display::set_brightness(uint8_t brightness) {
|
||||
}
|
||||
}
|
||||
|
||||
static Hub75Rotation to_hub75_rotation(display::DisplayRotation rotation) {
|
||||
switch (rotation) {
|
||||
case display::DisplayRotation::DISPLAY_ROTATION_90_DEGREES:
|
||||
return Hub75Rotation::ROTATE_90;
|
||||
case display::DisplayRotation::DISPLAY_ROTATION_180_DEGREES:
|
||||
return Hub75Rotation::ROTATE_180;
|
||||
case display::DisplayRotation::DISPLAY_ROTATION_270_DEGREES:
|
||||
return Hub75Rotation::ROTATE_270;
|
||||
default:
|
||||
return Hub75Rotation::ROTATE_0;
|
||||
}
|
||||
}
|
||||
|
||||
static display::DisplayRotation to_display_rotation(Hub75Rotation rotation) {
|
||||
switch (rotation) {
|
||||
case Hub75Rotation::ROTATE_90:
|
||||
return display::DisplayRotation::DISPLAY_ROTATION_90_DEGREES;
|
||||
case Hub75Rotation::ROTATE_180:
|
||||
return display::DisplayRotation::DISPLAY_ROTATION_180_DEGREES;
|
||||
case Hub75Rotation::ROTATE_270:
|
||||
return display::DisplayRotation::DISPLAY_ROTATION_270_DEGREES;
|
||||
default:
|
||||
return display::DisplayRotation::DISPLAY_ROTATION_0_DEGREES;
|
||||
}
|
||||
}
|
||||
|
||||
// Before setup() creates the driver the configuration holds the rotation, afterwards the driver does
|
||||
void HUB75Display::set_rotation(display::DisplayRotation rotation) {
|
||||
const Hub75Rotation hub75_rotation = to_hub75_rotation(rotation);
|
||||
if (this->driver_ == nullptr) {
|
||||
this->config_.rotation = hub75_rotation;
|
||||
return;
|
||||
}
|
||||
this->driver_->set_rotation(hub75_rotation);
|
||||
}
|
||||
|
||||
display::DisplayRotation HUB75Display::get_rotation() const {
|
||||
return to_display_rotation(this->driver_ == nullptr ? this->config_.rotation : this->driver_->get_rotation());
|
||||
}
|
||||
|
||||
} // namespace esphome::hub75
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,9 @@ class HUB75Display final : public display::Display {
|
||||
// Brightness control (runtime mutable)
|
||||
void set_brightness(uint8_t brightness);
|
||||
|
||||
void set_rotation(display::DisplayRotation rotation) override;
|
||||
display::DisplayRotation get_rotation() const override;
|
||||
|
||||
protected:
|
||||
// Display internal methods
|
||||
int get_width_internal() override { return this->driver_ != nullptr ? this->driver_->get_width() : 0; }
|
||||
@@ -43,7 +46,7 @@ class HUB75Display final : public display::Display {
|
||||
|
||||
// Member variables
|
||||
Hub75Driver *driver_{nullptr};
|
||||
Hub75Config config_; // Immutable configuration
|
||||
Hub75Config config_; // Fixed after setup(); only the rotation can change before the driver exists
|
||||
|
||||
// Runtime state (mutable)
|
||||
uint8_t brightness_{128};
|
||||
|
||||
@@ -37,3 +37,10 @@ display:
|
||||
}
|
||||
|
||||
<<: !include common.yaml
|
||||
|
||||
script:
|
||||
- id: rotate_hub75
|
||||
then:
|
||||
- lambda: |-
|
||||
id(my_hub75).set_rotation(display::DISPLAY_ROTATION_180_DEGREES);
|
||||
ESP_LOGD("test", "rotation now %d", static_cast<int>(id(my_hub75).get_rotation()));
|
||||
|
||||
Reference in New Issue
Block a user