From b3da35e35fc7e8cec4290b4322fc4a243ad02f6e Mon Sep 17 00:00:00 2001 From: radu Date: Thu, 3 Dec 2026 17:03:21 +0700 Subject: [PATCH] screen --- services/screen.yaml | 210 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 services/screen.yaml diff --git a/services/screen.yaml b/services/screen.yaml new file mode 100644 index 0000000..32eabfa --- /dev/null +++ b/services/screen.yaml @@ -0,0 +1,210 @@ +# Round 412x412 screen on the Waveshare ESP32-S3-Touch-LCD-1.46(B). +# Use together with board/ws146.yaml and services/voice.yaml. +# +# Shows the voice assistant state (coloured ring + status text) and the last +# command / reply. Adds a "Screen" switch that turns the backlight on and off. +# +# The voice_assistant triggers below are APPENDED to the ones in +# services/voice.yaml (ESPHome concatenates lists when merging packages). +# Each trigger must use the same form as in voice.yaml: a plain action list, +# except on_tts_start, which uses "then:" there. + +globals: + # 0 ready, 1 listening, 2 thinking, 3 speaking, 4 error, 5 offline + - id: screen_state + type: int + restore_value: no + initial_value: "5" + +# ---------------------------------------------------------------- hardware -- +i2c: + - id: i2c_bus + sda: GPIO11 + scl: GPIO10 + +pca9554: + - id: io_expander # TCA9554PWR; EXIO2 drives the LCD reset + address: 0x20 + +spi: + - id: display_qspi + type: quad + clk_pin: GPIO40 + data_pins: [GPIO46, GPIO45, GPIO42, GPIO41] + +display: + - platform: mipi_spi + id: screen + model: WAVESHARE-ESP32-S3-TOUCH-LCD-1.46 + spi_id: display_qspi + auto_clear_enabled: false + update_interval: never + +output: + - platform: ledc + id: backlight_pwm + pin: GPIO5 + +light: + - platform: monochromatic + id: backlight + name: Screen Backlight + internal: true + output: backlight_pwm + restore_mode: ALWAYS_OFF # the Screen switch sets it at boot + default_transition_length: 300ms + +switch: + - platform: template + name: Screen + id: screen_switch + icon: mdi:monitor + optimistic: true + restore_mode: RESTORE_DEFAULT_ON + on_turn_on: + - lvgl.resume: + - light.turn_on: backlight + on_turn_off: + - light.turn_off: backlight + - lvgl.pause: + + - id: !extend stop_listen + on_turn_on: + - script.execute: screen_refresh + on_turn_off: + - script.execute: screen_refresh + +# ---------------------------------------------------------------------- UI -- +lvgl: + displays: [screen] + buffer_size: 25% + bg_color: 0x000000 + default_font: montserrat_24 + pages: + - id: main_page + bg_color: 0x000000 + scrollable: false + widgets: + - obj: + id: status_ring + align: CENTER + width: 396 + height: 396 + radius: 198 + bg_opa: TRANSP + border_width: 14 + border_color: 0x555555 + scrollable: false + - label: + id: status_label + align: CENTER + y: -40 + text_font: montserrat_48 + text_color: 0x555555 + text_align: CENTER + text: "Offline" + - label: + id: transcript_label + align: CENTER + y: 60 + width: 290 + long_mode: WRAP + text_align: CENTER + text_color: 0xBBBBBB + text: "" + +script: + # Redraw ring + status text from screen_state and the Stop Listen switch. + - id: screen_refresh + mode: queued + then: + - lvgl.label.update: + id: status_label + text: !lambda |- + if (id(screen_state) == 5) return "Offline"; + if (id(screen_state) == 4) return "Error"; + if (id(stop_listen).state) return "Muted"; + switch (id(screen_state)) { + case 1: return "Listening"; + case 2: return "Thinking"; + case 3: return "Speaking"; + default: return "Ready"; + } + text_color: !lambda |- + if (id(screen_state) >= 4) return lv_color_hex(0xE53935); + if (id(stop_listen).state) return lv_color_hex(0x555555); + switch (id(screen_state)) { + case 1: return lv_color_hex(0x1E88E5); + case 2: return lv_color_hex(0x00BCD4); + case 3: return lv_color_hex(0xFFFFFF); + default: return lv_color_hex(0x2E7D32); + } + - lvgl.obj.update: + id: status_ring + border_color: !lambda |- + if (id(screen_state) >= 4) return lv_color_hex(0xE53935); + if (id(stop_listen).state) return lv_color_hex(0x333333); + switch (id(screen_state)) { + case 1: return lv_color_hex(0x1E88E5); + case 2: return lv_color_hex(0x00BCD4); + case 3: return lv_color_hex(0xFFFFFF); + default: return lv_color_hex(0x1B5E20); + } + + - id: screen_set_transcript + mode: queued + parameters: + text: string + then: + - lvgl.label.update: + id: transcript_label + text: !lambda return text; + - script.execute: screen_clear_transcript + + # Clear the command/reply text a while after the last update. + - id: screen_clear_transcript + mode: restart + then: + - delay: 20s + - lvgl.label.update: + id: transcript_label + text: "" + +# ------------------------------------------- hooks into services/voice.yaml -- +voice_assistant: + on_listening: + - lambda: id(screen_state) = 1; + - script.execute: screen_refresh + - script.execute: + id: screen_set_transcript + text: "" + on_stt_vad_end: + - lambda: id(screen_state) = 2; + - script.execute: screen_refresh + on_stt_end: + - lambda: id(screen_state) = 2; + - script.execute: screen_refresh + - script.execute: + id: screen_set_transcript + text: !lambda 'return "\"" + x + "\"";' + on_tts_start: + then: + - lambda: id(screen_state) = 3; + - script.execute: screen_refresh + - script.execute: + id: screen_set_transcript + text: !lambda return x; + on_end: + - lambda: id(screen_state) = 0; + - script.execute: screen_refresh + on_error: + - lambda: |- + if (message.find("duplicate_wake_up_detected") == std::string::npos) + id(screen_state) = 4; + - script.execute: screen_refresh + on_client_connected: + - lambda: id(screen_state) = 0; + - script.execute: screen_refresh + on_client_disconnected: + - lambda: id(screen_state) = 5; + - script.execute: screen_refresh \ No newline at end of file