8static constexpr const char *
const TAG =
"epaper_spi.6c";
9static constexpr unsigned char GRAY_THRESHOLD = 50;
23static uint8_t color_to_hex(
Color color) {
27 unsigned char max_rgb = std::max({color.
r, color.
g, color.
b});
28 unsigned char min_rgb = std::min({color.
r, color.
g, color.
b});
30 if ((max_rgb - min_rgb) < GRAY_THRESHOLD) {
33 if ((
static_cast<int>(color.
r) + color.
g + color.
b) > 382) {
41 bool r_on = (color.
r > 128);
42 bool g_on = (color.
g > 128);
43 bool b_on = (color.
b > 128);
45 if (r_on && g_on && !b_on) {
48 if (r_on && !g_on && !b_on) {
51 if (!r_on && g_on && !b_on) {
54 if (!r_on && !g_on && b_on) {
58 if (!r_on && g_on && b_on) {
77 ESP_LOGV(TAG,
"Power on");
82 ESP_LOGV(TAG,
"Power off");
88 ESP_LOGV(TAG,
"Refresh");
94 ESP_LOGV(TAG,
"Deep sleep");
100 auto pixel_color = color_to_hex(color);
103 this->
buffer_.
fill(pixel_color + (pixel_color << 4));
114 auto pixel_bits = color_to_hex(color);
116 uint32_t byte_position = pixel_position / 2;
117 auto original = this->
buffer_[byte_position];
118 if ((pixel_position & 1) != 0) {
119 this->
buffer_[byte_position] = (original & 0xF0) | pixel_bits;
121 this->
buffer_[byte_position] = (original & 0x0F) | (pixel_bits << 4);
133 uint8_t bytes_to_send[MAX_TRANSFER_SIZE];
137 if (buf_idx ==
sizeof bytes_to_send) {
141 ESP_LOGV(TAG,
"Wrote %d bytes at %ums", buf_idx, (
unsigned)
millis());
144 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)
bool rotate_coordinates_(int &x, int &y)
Check and rotate coordinates based on the transform flags.
split_buffer::SplitBuffer buffer_
size_t current_data_index_
int get_width_internal() override
void fill(Color color) override
void refresh_screen(bool partial) override
bool transfer_data() override
void power_off() override
void deep_sleep() override
void draw_pixel_at(int x, int y, Color color) 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.