Add flip X and Y on inkplate6 component (#7904)

Co-authored-by: Antoine Weill--Duflos <antoine@haply.co>
Co-authored-by: David Sichau <sichau@inf.ethz.ch>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: David Sichau <DavidSichau@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Leicas 2025-05-29 01:10:06 -04:00 committed by GitHub
parent 7ac5746e0d
commit 455624105b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View File

@ -6,9 +6,12 @@ from esphome.const import (
CONF_FULL_UPDATE_EVERY, CONF_FULL_UPDATE_EVERY,
CONF_ID, CONF_ID,
CONF_LAMBDA, CONF_LAMBDA,
CONF_MIRROR_X,
CONF_MIRROR_Y,
CONF_MODEL, CONF_MODEL,
CONF_OE_PIN, CONF_OE_PIN,
CONF_PAGES, CONF_PAGES,
CONF_TRANSFORM,
CONF_WAKEUP_PIN, CONF_WAKEUP_PIN,
) )
@ -36,7 +39,6 @@ CONF_SPH_PIN = "sph_pin"
CONF_SPV_PIN = "spv_pin" CONF_SPV_PIN = "spv_pin"
CONF_VCOM_PIN = "vcom_pin" CONF_VCOM_PIN = "vcom_pin"
inkplate6_ns = cg.esphome_ns.namespace("inkplate6") inkplate6_ns = cg.esphome_ns.namespace("inkplate6")
Inkplate6 = inkplate6_ns.class_( Inkplate6 = inkplate6_ns.class_(
"Inkplate6", "Inkplate6",
@ -62,6 +64,12 @@ CONFIG_SCHEMA = cv.All(
{ {
cv.GenerateID(): cv.declare_id(Inkplate6), cv.GenerateID(): cv.declare_id(Inkplate6),
cv.Optional(CONF_GREYSCALE, default=False): cv.boolean, cv.Optional(CONF_GREYSCALE, default=False): cv.boolean,
cv.Optional(CONF_TRANSFORM): cv.Schema(
{
cv.Optional(CONF_MIRROR_X, default=False): cv.boolean,
cv.Optional(CONF_MIRROR_Y, default=False): cv.boolean,
}
),
cv.Optional(CONF_PARTIAL_UPDATING, default=True): cv.boolean, cv.Optional(CONF_PARTIAL_UPDATING, default=True): cv.boolean,
cv.Optional(CONF_FULL_UPDATE_EVERY, default=10): cv.uint32_t, cv.Optional(CONF_FULL_UPDATE_EVERY, default=10): cv.uint32_t,
cv.Optional(CONF_MODEL, default="inkplate_6"): cv.enum( cv.Optional(CONF_MODEL, default="inkplate_6"): cv.enum(
@ -126,6 +134,9 @@ async def to_code(config):
cg.add(var.set_writer(lambda_)) cg.add(var.set_writer(lambda_))
cg.add(var.set_greyscale(config[CONF_GREYSCALE])) cg.add(var.set_greyscale(config[CONF_GREYSCALE]))
if transform := config.get(CONF_TRANSFORM):
cg.add(var.set_mirror_x(transform[CONF_MIRROR_X]))
cg.add(var.set_mirror_y(transform[CONF_MIRROR_Y]))
cg.add(var.set_partial_updating(config[CONF_PARTIAL_UPDATING])) cg.add(var.set_partial_updating(config[CONF_PARTIAL_UPDATING]))
cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY])) cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))

View File

@ -1,7 +1,7 @@
#include "inkplate.h" #include "inkplate.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h" #include "esphome/core/application.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32_FRAMEWORK_ARDUINO #ifdef USE_ESP32_FRAMEWORK_ARDUINO
@ -156,6 +156,12 @@ void HOT Inkplate6::draw_absolute_pixel_internal(int x, int y, Color color) {
if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0) if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0)
return; return;
if (this->mirror_y_)
y = this->get_height_internal() - y - 1;
if (this->mirror_x_)
x = this->get_width_internal() - x - 1;
if (this->greyscale_) { if (this->greyscale_) {
int x1 = x / 2; int x1 = x / 2;
int x_sub = x % 2; int x_sub = x % 2;

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "esphome/components/display/display_buffer.h"
#include "esphome/components/i2c/i2c.h"
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/components/i2c/i2c.h"
#include "esphome/components/display/display_buffer.h"
#ifdef USE_ESP32_FRAMEWORK_ARDUINO #ifdef USE_ESP32_FRAMEWORK_ARDUINO
@ -92,6 +92,9 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
if (this->is_ready()) if (this->is_ready())
this->initialize_(); this->initialize_();
} }
void set_mirror_y(bool mirror_y) { this->mirror_y_ = mirror_y; }
void set_mirror_x(bool mirror_x) { this->mirror_x_ = mirror_x; }
void set_partial_updating(bool partial_updating) { this->partial_updating_ = partial_updating; } void set_partial_updating(bool partial_updating) { this->partial_updating_ = partial_updating; }
void set_full_update_every(uint32_t full_update_every) { this->full_update_every_ = full_update_every; } void set_full_update_every(uint32_t full_update_every) { this->full_update_every_ = full_update_every; }
@ -221,6 +224,8 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
bool block_partial_{true}; bool block_partial_{true};
bool greyscale_; bool greyscale_;
bool mirror_y_{false};
bool mirror_x_{false};
bool partial_updating_; bool partial_updating_;
InkplateModel model_; InkplateModel model_;