8static constexpr const char *
const TAG =
"epaper_spi.6c";
9static constexpr size_t MAX_TRANSFER_SIZE = 128;
10static constexpr unsigned char GRAY_THRESHOLD = 50;
24static uint8_t color_to_hex(
Color color) {
28 unsigned char max_rgb = std::max({color.
r, color.
g, color.
b});
29 unsigned char min_rgb = std::min({color.
r, color.
g, color.
b});
31 if ((max_rgb - min_rgb) < GRAY_THRESHOLD) {
34 if ((
static_cast<int>(color.
r) + color.
g + color.
b) > 382) {
42 bool r_on = (color.
r > 128);
43 bool g_on = (color.
g > 128);
44 bool b_on = (color.
b > 128);
46 if (r_on && g_on && !b_on) {
49 if (r_on && !g_on && !b_on) {
52 if (!r_on && g_on && !b_on) {
55 if (!r_on && !g_on && b_on) {
59 if (!r_on && g_on && b_on) {
78 ESP_LOGD(TAG,
"Power on");
83 ESP_LOGD(TAG,
"Power off");
89 ESP_LOGD(TAG,
"Refresh");
95 ESP_LOGD(TAG,
"Deep sleep");
101 auto pixel_color = color_to_hex(color);
104 this->
buffer_.
fill(pixel_color + (pixel_color << 4));
116 auto pixel_bits = color_to_hex(color);
118 uint32_t byte_position = pixel_position / 2;
119 auto original = this->
buffer_[byte_position];
120 if ((pixel_position & 1) != 0) {
121 this->
buffer_[byte_position] = (original & 0xF0) | pixel_bits;
123 this->
buffer_[byte_position] = (original & 0x0F) | (pixel_bits << 4);
131#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
134 ESP_LOGV(TAG,
"Start sending data at %ums", (
unsigned)
millis());
139 uint8_t bytes_to_send[MAX_TRANSFER_SIZE];
143 if (buf_idx ==
sizeof bytes_to_send) {
147 ESP_LOGV(TAG,
"Wrote %d bytes at %ums", buf_idx, (
unsigned)
millis());
150 if (
millis() - start_time > MAX_TRANSFER_TIME) {
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void command(uint8_t value)
split_buffer::SplitBuffer buffer_
virtual int get_width_controller()
uint32_t transfer_start_time_
size_t current_data_index_
void fill(Color color) override
void draw_absolute_pixel_internal(int x, int y, Color color) override
bool transfer_data() override
void power_off() override
void deep_sleep() override
void refresh_screen() override
void write_array(const uint8_t *data, size_t length)
void fill(uint8_t value) const
Fill the entire buffer with a single byte value.
const Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.