1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Make per-loop display clearing optional (#2626)

Currently, in each loop during DisplayBuffer::update_() the display is
cleared by calling DisplayBuffer::clear().

This prevents more efficient display usages that do not render the
screen in each loop, but only if necessary. This can be helpful, for
example, if images are rendered. This would cause the loop time to be
exceeded frequently.

This change adds a new optional flag "auto_clear" that can be used to
control the clearing behavior. If unset, the DisplayBuffer defaults to
enabled auto clearing, the current behavior and thus backward compatible.

This flag applies to displays that use DisplayBuffer.

Example excerpt:
globals:
  - id: state
    type: bool
    restore_value: no
    initial_value: "false"
  - id: state_processed
    type: bool
    restore_value: no
    initial_value: "false"

switch:
  - platform: template
    name: "State"
    id: state_switch
    lambda: |-
      return id(state);
    turn_on_action:
      - globals.set:
          id: state
          value: "true"
      - globals.set:
          id: state_processed
          value: "false"
    turn_off_action:
      - globals.set:
          id: state
          value: "false"
      - globals.set:
          id: state_processed
          value: "false"

display:
  - platform: ili9341
    # ...
    auto_clear_enabled: false
    lambda: |-
      if (!id(state_processed)) {
        it.fill(COLOR_WHITE);
        if (id(state)) {
          it.image(80, 20, id(image1));
        } else {
          it.image(80, 20, id(image2));
        }
        id(state_processed) = true;
      }

Co-authored-by: Tim Niemueller <timdn@google.com>
This commit is contained in:
Tim Niemueller
2021-11-03 17:56:09 +01:00
committed by GitHub
parent 379c3e98f5
commit 11f1e28139
5 changed files with 43 additions and 1 deletions

View File

@@ -2214,6 +2214,31 @@ display:
row_start: 0
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9341
model: "TFT 2.4"
cs_pin: GPIO5
dc_pin: GPIO4
reset_pin: GPIO22
led_pin:
number: GPIO15
inverted: true
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9341
model: "TFT 2.4"
cs_pin: GPIO5
dc_pin: GPIO4
reset_pin: GPIO22
led_pin:
number: GPIO15
inverted: true
auto_clear_enabled: false
rotation: 90
lambda: |-
if (!id(glob_bool_processed)) {
it.fill(Color::WHITE);
id(glob_bool_processed) = true;
}
tm1651:
id: tm1651_battery
@@ -2393,6 +2418,10 @@ globals:
type: std::string
restore_value: no
# initial_value: ""
- id: glob_bool_processed
type: bool
restore_value: no
initial_value: 'false'
text_sensor:
- platform: mqtt_subscribe