mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 09:06:52 +01:00
935 lines
30 KiB
YAML
935 lines
30 KiB
YAML
# Hardware: M5Stack Core2 (AXP192) on the Faces Bottom II (600 mAh battery) with the QWERTY keyboard face
|
|
# Pinout:
|
|
# GPIO2 M-Bus (Core G15 position) -> faces_leds (light esp32_rmt_led_strip), Faces base SK6812 x10;
|
|
# also the Core2 speaker DOUT (NS4168), so no speaker while the LEDs are used
|
|
# GPIO5 -> display_tft (display mipi_spi cs_pin)
|
|
# GPIO15 -> display_tft (display mipi_spi dc_pin)
|
|
# GPIO18 -> spi_bus (spi clk_pin)
|
|
# GPIO19 M-Bus (modded NSS, stock G33) -> lora (sx127x cs_pin), LoRa868 module (Ra-01H, SX1276)
|
|
# GPIO21 -> i2c_main (i2c sda), M-Bus SDA
|
|
# GPIO22 -> i2c_main (i2c scl), M-Bus SCL
|
|
# GPIO23 -> spi_bus (spi mosi_pin)
|
|
# GPIO26 M-Bus, Port B -> lora (sx127x rst_pin)
|
|
# GPIO27 M-Bus (modded DIO1) -> LoRa868 DIO1, unused (sx127x has no dio1)
|
|
# GPIO35 M-Bus (modded DIO0, stock G36) -> lora (sx127x dio0_pin)
|
|
# GPIO38 -> spi_bus (spi miso_pin)
|
|
# GPIO39 -> touch_lcd (touchscreen ft63x6 interrupt_pin)
|
|
# AXP192 GPIO4 -> LCD reset (on_boot)
|
|
# Grove (free):
|
|
# Port A red (Core2) I2C GPIO32 SDA, GPIO33 SCL
|
|
# Port B black (base) GPIO GPIO26 out/DAC, GPIO36 in/ADC (input only); GPIO26 taken by the LoRa868 RST
|
|
# Port C blue (base) UART GPIO13 RX, GPIO14 TX -> i2c_port_c (i2c scl GPIO13, sda GPIO14)
|
|
# Touch buttons (below the LCD, raw y 240-280): A prev page, B keyboard page, C next page
|
|
# I2C:
|
|
# 0x08 keyboard (m5stack_keyboard), Faces QWERTY
|
|
# 0x34 pmu_axp (axp192)
|
|
# 0x38 touch_lcd (touchscreen ft63x6)
|
|
# 0x51 rtc_time (time bm8563)
|
|
# MPU6886 IMU (0x68) is cut off while the Faces base is attached
|
|
# I2C Port C:
|
|
# 0x3C oled (display ssd1306_i2c), Unit OLED SH1107
|
|
# 0x3E unit_lcd (display m5stack_st7789v2), Unit LCD, firmware 0.3
|
|
# 0x33 thermal (mlx90640), MLX90640 32x24 thermal camera
|
|
# 0x5F cardkb (m5stack_keyboard), CardKB (unplugged for now, its warning at boot is expected)
|
|
substitutions:
|
|
device: m5core2
|
|
name: M5Core2
|
|
area: DEV
|
|
comment: Core2 + Faces keyboard
|
|
|
|
esphome:
|
|
name: mcu-${device}
|
|
friendly_name: ${name}
|
|
area: ${area}
|
|
comment: ${comment}
|
|
on_boot:
|
|
# After the I2C bus, before the display: LCD power (LDO2), backlight (DC3), M-Bus 5V boost (EXTEN)
|
|
# for the Faces base, then the LCD reset pulse on AXP GPIO4 (open drain), as M5Core2's AXP192::begin
|
|
- priority: 900
|
|
then:
|
|
- lambda: |-
|
|
auto *axp = id(pmu_axp);
|
|
axp->writeRegister(0x27, (3300 - 700) / 25); // DC3 (LCD backlight) 3.3 V
|
|
axp->writeRegister(0x28, (axp->readRegister(0x28) & 0x0F) | 0xF0); // LDO2 3.3 V
|
|
axp->writeRegister(0x12, axp->readRegister(0x12) | 0x46); // EXTEN, LDO2, DC3
|
|
axp->writeRegister(0x95, (axp->readRegister(0x95) & 0x72) | 0x84); // GPIO4 output
|
|
axp->writeRegister(0x96, axp->readRegister(0x96) & ~0x02);
|
|
delay(100);
|
|
axp->writeRegister(0x96, axp->readRegister(0x96) | 0x02);
|
|
delay(100);
|
|
- priority: -100
|
|
then:
|
|
# the m5stack component sets these in the AXP2101 layout: 4.1 V, 360 mA, end at 10 %
|
|
- lambda: id(pmu_axp)->writeRegister(0x33, 0x83);
|
|
# The SH1107 once stuck showing noise (even after a power cycle) with ESPHome's init alone;
|
|
# M5GFX's settings that ESPHome lacks or sets otherwise brought it back, kept as insurance:
|
|
# end read-modify-write, POR clock, SH1107 precharge, VCOMH, DC-DC, RAM content, on
|
|
- lambda: |-
|
|
for (uint8_t c : {0xEE, 0xD5, 0x50, 0xD9, 0x20, 0xDB, 0x35, 0xAD, 0x8B, 0xA4, 0xAF})
|
|
id(oled).write_byte(0x00, c);
|
|
- bm8563.read_time:
|
|
- lvgl.page.show: {id: status_page, lvgl_id: lvgl_main}
|
|
|
|
esp32:
|
|
variant: esp32
|
|
flash_size: 16MB
|
|
framework:
|
|
type: esp-idf
|
|
advanced:
|
|
flash_chip: generic
|
|
minimum_chip_revision: 3.0
|
|
sram1_as_iram: true
|
|
|
|
psram:
|
|
mode: quad
|
|
speed: 80MHz
|
|
|
|
packages:
|
|
common: !include common/common.yaml
|
|
ipv6_only: !include common/ipv6_only.yaml
|
|
status_led: !include
|
|
file: common/status_led.yaml
|
|
vars:
|
|
light_id: faces_leds
|
|
|
|
external_components:
|
|
- source: github://m5stack/esphome-yaml
|
|
components: [axp192]
|
|
refresh: 1h
|
|
- source: github://randybb/esphome-components
|
|
components: [m5stack_keyboard, m5stack_st7789v2, meshtastic]
|
|
refresh: 0s
|
|
# MLX90640, camera entity in HA (its heatmap page at /thermal needs web_server_base only)
|
|
- source: github://randybb/esphome-mlx-90640@optional-web-server
|
|
components: [mlx90640]
|
|
|
|
# MLX90640 on Port C; settings changed at runtime are saved on the device
|
|
mlx90640:
|
|
id: thermal
|
|
i2c_id: i2c_port_c
|
|
refresh_rate: 4Hz
|
|
update_interval: 10s
|
|
min_temperature:
|
|
name: Thermal Min
|
|
max_temperature:
|
|
name: Thermal Max
|
|
mean_temperature:
|
|
name: Thermal Mean
|
|
center_temperature:
|
|
name: Thermal Center
|
|
ambient_temperature:
|
|
name: Thermal Sensor Die
|
|
frame_rate:
|
|
name: Thermal Frame Rate
|
|
i2c_errors:
|
|
name: Thermal I2C Errors
|
|
camera:
|
|
name: Thermal Camera
|
|
resolution: 320x240
|
|
|
|
api:
|
|
# status page until Home Assistant connects (log viewers don't subscribe to states)
|
|
on_client_connected:
|
|
- delay: 2s
|
|
- if:
|
|
condition:
|
|
api.connected:
|
|
state_subscription_only: true
|
|
then:
|
|
- lvgl.page.show: {id: main_page, lvgl_id: lvgl_main}
|
|
on_client_disconnected:
|
|
- if:
|
|
condition:
|
|
not:
|
|
api.connected:
|
|
state_subscription_only: true
|
|
then:
|
|
- lvgl.page.show: {id: status_page, lvgl_id: lvgl_main}
|
|
|
|
i2c:
|
|
- id: i2c_main
|
|
sda: 21
|
|
scl: 22
|
|
scan: true
|
|
# Port C (blue) used as a second I2C bus, Grove yellow = SCL, white = SDA
|
|
- id: i2c_port_c
|
|
sda: 14
|
|
scl: 13
|
|
frequency: 400kHz
|
|
scan: true
|
|
|
|
spi:
|
|
id: spi_bus
|
|
clk_pin: 18
|
|
mosi_pin: 23
|
|
miso_pin: 38
|
|
|
|
# LoRa868 module on Meshtastic EU LongFast, RSSI/SNR of every packet (relays included)
|
|
sx127x:
|
|
id: lora
|
|
spi_id: spi_bus
|
|
cs_pin: GPIO19
|
|
rst_pin: GPIO26
|
|
dio0_pin: GPIO35 # modded, stock G36
|
|
modulation: LORA
|
|
frequency: 869525000 # Meshtastic EU_868 LongFast, slot 0
|
|
bandwidth: 250_0kHz
|
|
spreading_factor: 11
|
|
coding_rate: CR_4_5
|
|
preamble_size: 16
|
|
sync_value: 0x2B # Meshtastic
|
|
crc_enable: true
|
|
pa_pin: BOOST
|
|
pa_power: 14
|
|
on_packet:
|
|
- lambda: |-
|
|
id(lora_count) += 1;
|
|
id(lora_rssi).publish_state(rssi);
|
|
id(lora_snr).publish_state(snr);
|
|
- lvgl.label.update:
|
|
id: lora_stats
|
|
text: !lambda |-
|
|
return str_sprintf("%.0f dBm\n%.1f dB\n%u", id(lora_rssi).state, id(lora_snr).state, id(lora_count));
|
|
|
|
# Typed lines go to the LongFast channel, received texts to the LoRa page
|
|
meshtastic:
|
|
id: mesh
|
|
long_name: randy_m5c2
|
|
short_name: M5C2
|
|
on_message:
|
|
- text_sensor.template.publish:
|
|
id: lora_packet
|
|
state: !lambda 'return from_name + ": " + text;'
|
|
- lvgl.label.update:
|
|
id: lora_last
|
|
text: !lambda 'return from_name + ": " + text;'
|
|
# Example, off: randy_home's Meshtastic integration already gives HA every node. Without such
|
|
# a node this sends each node update to HA, an automation with device_tracker.see maps them.
|
|
# on_node:
|
|
# - homeassistant.event:
|
|
# event: esphome.meshtastic_node
|
|
# data:
|
|
# node: !lambda return node.id();
|
|
# long_name: !lambda return node.long_name;
|
|
# hops: !lambda 'return node.hops < 0 ? std::string() : to_string(node.hops);'
|
|
# rssi: !lambda return meshtastic::num(node.rssi, 0);
|
|
# latitude: !lambda return meshtastic::num(node.latitude, 7);
|
|
# longitude: !lambda return meshtastic::num(node.longitude, 7);
|
|
# altitude: !lambda return meshtastic::num(node.altitude, 0);
|
|
# battery_level: !lambda return meshtastic::num(node.battery_level, 0);
|
|
# voltage: !lambda return meshtastic::num(node.voltage, 2);
|
|
# temperature: !lambda return meshtastic::num(node.temperature, 1);
|
|
|
|
globals:
|
|
- id: lora_count
|
|
type: uint32_t
|
|
initial_value: "0"
|
|
|
|
axp192:
|
|
id: pmu_axp
|
|
i2c_id: i2c_main
|
|
|
|
m5stack_keyboard:
|
|
- id: keyboard
|
|
i2c_id: i2c_main
|
|
- id: cardkb
|
|
i2c_id: i2c_port_c
|
|
address: 0x5F
|
|
|
|
display:
|
|
- platform: mipi_spi
|
|
id: display_tft
|
|
model: M5CORE2
|
|
spi_id: spi_bus
|
|
auto_clear_enabled: false
|
|
update_interval: never
|
|
- platform: ssd1306_i2c
|
|
id: oled
|
|
i2c_id: i2c_port_c
|
|
model: "SH1107 128x64"
|
|
address: 0x3C
|
|
rotation: 90
|
|
offset_x: 32 # the 64 visible columns sit in the middle of the SH1107 RAM
|
|
update_interval: 1s
|
|
lambda: |-
|
|
auto now = id(ha_time).now();
|
|
it.strftime(it.get_width() / 2, 0, id(font_title), TextAlign::TOP_CENTER, "%H:%M:%S", now);
|
|
it.printf(0, it.get_height(), id(font_status), TextAlign::BOTTOM_LEFT, "%.2f V %.0f%%", id(battery_voltage).state,
|
|
id(battery_level).state);
|
|
- platform: m5stack_st7789v2
|
|
id: unit_lcd
|
|
i2c_id: i2c_port_c
|
|
brightness: 60%
|
|
update_interval: 10s # only reconnects a lost unit, LVGL flushes drive the transfer
|
|
auto_clear_enabled: false
|
|
|
|
touchscreen:
|
|
- platform: ft63x6
|
|
id: touch_lcd
|
|
display: display_tft
|
|
i2c_id: i2c_main
|
|
interrupt_pin: 39
|
|
|
|
light:
|
|
- platform: esp32_rmt_led_strip
|
|
id: faces_leds
|
|
name: LED Strip
|
|
pin: GPIO2
|
|
num_leds: 10
|
|
chipset: SK6812
|
|
channel_colors: GRB
|
|
restore_mode: ALWAYS_OFF
|
|
effects:
|
|
- addressable_rainbow:
|
|
- addressable_scan:
|
|
|
|
binary_sensor:
|
|
- platform: template
|
|
id: battery_charging
|
|
name: Battery Charging
|
|
device_class: battery_charging
|
|
# the three touch buttons lie below the 240 px of the LCD, only in raw coordinates
|
|
- platform: touchscreen
|
|
id: button_a
|
|
use_raw: true
|
|
x_min: 0
|
|
x_max: 106
|
|
y_min: 240
|
|
y_max: 300
|
|
on_press:
|
|
- lvgl.page.previous: {lvgl_id: lvgl_main}
|
|
- platform: touchscreen
|
|
id: button_b
|
|
use_raw: true
|
|
x_min: 107
|
|
x_max: 213
|
|
y_min: 240
|
|
y_max: 300
|
|
on_press:
|
|
- lvgl.page.show: {id: main_page, lvgl_id: lvgl_main}
|
|
- platform: touchscreen
|
|
id: button_c
|
|
use_raw: true
|
|
x_min: 214
|
|
x_max: 320
|
|
y_min: 240
|
|
y_max: 300
|
|
on_press:
|
|
- lvgl.page.next: {lvgl_id: lvgl_main}
|
|
|
|
# AXP192 ADCs read directly, the m5stack component decodes them as an AXP2101
|
|
sensor:
|
|
- platform: template
|
|
id: battery_voltage
|
|
name: Battery Voltage
|
|
unit_of_measurement: V
|
|
device_class: voltage
|
|
accuracy_decimals: 2
|
|
- platform: template
|
|
id: battery_level
|
|
name: Battery Level
|
|
unit_of_measurement: "%"
|
|
device_class: battery
|
|
accuracy_decimals: 0
|
|
- platform: template
|
|
id: battery_current
|
|
name: Battery Current # + charging, - discharging
|
|
unit_of_measurement: mA
|
|
device_class: current
|
|
accuracy_decimals: 0
|
|
- platform: template
|
|
id: vbus_voltage
|
|
internal: true
|
|
- platform: template
|
|
id: vbus_current
|
|
internal: true
|
|
- platform: template
|
|
id: acin_voltage
|
|
internal: true
|
|
- platform: template
|
|
id: acin_current
|
|
internal: true
|
|
- platform: template
|
|
id: aps_voltage
|
|
internal: true
|
|
- platform: template
|
|
id: pmu_temperature
|
|
name: PMU Temperature
|
|
unit_of_measurement: °C
|
|
device_class: temperature
|
|
accuracy_decimals: 1
|
|
- platform: template
|
|
id: lora_rssi
|
|
name: LoRa RSSI
|
|
unit_of_measurement: dBm
|
|
device_class: signal_strength
|
|
accuracy_decimals: 0
|
|
- platform: template
|
|
id: lora_snr
|
|
name: LoRa SNR
|
|
unit_of_measurement: dB
|
|
accuracy_decimals: 1
|
|
|
|
# RTC holds the time until Home Assistant connects, HA's time is written back on every sync
|
|
time:
|
|
- platform: bm8563
|
|
id: rtc_time
|
|
i2c_id: i2c_main
|
|
update_interval: never
|
|
- id: !extend ha_time
|
|
on_time_sync:
|
|
- bm8563.write_time:
|
|
|
|
# Typed line in the text area, Enter (CR LF) sends it, Backspace deletes
|
|
key_collector:
|
|
- id: line_collector
|
|
source_id: keyboard
|
|
end_keys: "\r\n"
|
|
back_keys: "\b"
|
|
min_length: 1 # the LF after CR is an empty line
|
|
max_length: 64
|
|
on_progress: &line_progress
|
|
- lvgl.textarea.update:
|
|
id: input_text
|
|
text: !lambda return x;
|
|
on_result: &line_result
|
|
- logger.log:
|
|
format: "Line: %s"
|
|
args: [x.c_str()]
|
|
- lvgl.label.update:
|
|
id: last_line
|
|
text: !lambda return x;
|
|
- lvgl.label.update:
|
|
id: unit_last_line
|
|
text: !lambda return x;
|
|
- lvgl.textarea.update:
|
|
id: input_text
|
|
text: ""
|
|
- text_sensor.template.publish:
|
|
id: keyboard_line
|
|
state: !lambda return x;
|
|
- meshtastic.send_text: !lambda return x;
|
|
- id: cardkb_collector
|
|
source_id: cardkb
|
|
end_keys: "\r\n"
|
|
back_keys: "\b"
|
|
min_length: 1
|
|
max_length: 64
|
|
on_progress: *line_progress
|
|
on_result: *line_result
|
|
|
|
select:
|
|
- platform: mlx90640
|
|
refresh_rate:
|
|
name: Thermal Refresh Rate
|
|
palette:
|
|
name: Thermal Palette
|
|
|
|
number:
|
|
- platform: mlx90640
|
|
emissivity:
|
|
name: Thermal Emissivity
|
|
range_min:
|
|
name: Thermal Range Min
|
|
range_max:
|
|
name: Thermal Range Max
|
|
|
|
switch:
|
|
- platform: mlx90640
|
|
auto_range:
|
|
name: Thermal Auto Range
|
|
mirror:
|
|
name: Thermal Mirror
|
|
- platform: template
|
|
name: Unit LCD Invert
|
|
icon: mdi:invert-colors
|
|
optimistic: true
|
|
restore_mode: RESTORE_DEFAULT_OFF
|
|
entity_category: config
|
|
on_turn_on:
|
|
- lambda: id(unit_lcd).set_invert(true);
|
|
on_turn_off:
|
|
- lambda: id(unit_lcd).set_invert(false);
|
|
- platform: template
|
|
name: Unit LCD Sleep
|
|
icon: mdi:sleep
|
|
optimistic: true
|
|
restore_mode: ALWAYS_OFF
|
|
on_turn_on:
|
|
- lambda: id(unit_lcd).set_sleep(true);
|
|
on_turn_off:
|
|
- lambda: id(unit_lcd).set_sleep(false);
|
|
|
|
text_sensor:
|
|
- platform: template
|
|
id: keyboard_line
|
|
name: Keyboard Line
|
|
- platform: template
|
|
id: lora_packet
|
|
name: Meshtastic Message
|
|
|
|
script:
|
|
# same as mcu-lvgl
|
|
- id: update_status
|
|
then:
|
|
- lambda: |-
|
|
// same colors as the other status screens: ok green, waiting orange, details gray
|
|
static const uint32_t OK = 0x4DD966, WAIT = 0xFFB300;
|
|
auto set = [](lv_obj_t *label, const std::string &text, uint32_t color) {
|
|
lv_label_set_text(label, text.c_str());
|
|
lv_obj_set_style_text_color(label, lv_color_hex(color), LV_PART_MAIN);
|
|
};
|
|
|
|
const bool wifi_ok = wifi::global_wifi_component->is_connected();
|
|
set(id(status_wifi),
|
|
wifi_ok ? str_sprintf("WiFi: connected (%d dBm)", wifi::global_wifi_component->wifi_rssi())
|
|
: std::string("WiFi: connecting..."),
|
|
wifi_ok ? OK : WAIT);
|
|
|
|
// IPv6 first (skip link-local), then IPv4
|
|
std::string ips;
|
|
if (wifi_ok) {
|
|
char buf[network::IP_ADDRESS_BUFFER_SIZE];
|
|
for (bool v6 : {true, false}) {
|
|
for (auto &ip : wifi::global_wifi_component->get_ip_addresses()) {
|
|
if (!ip.is_set() || ip.is_ip6() != v6)
|
|
continue;
|
|
ip.str_to(buf);
|
|
if (v6 && strncmp(buf, "fe80", 4) == 0)
|
|
continue;
|
|
if (!ips.empty())
|
|
ips += "\n";
|
|
ips += buf;
|
|
}
|
|
}
|
|
}
|
|
lv_label_set_text(id(status_ips), ips.c_str());
|
|
if (ips.empty())
|
|
lv_obj_add_flag(id(status_ips), LV_OBJ_FLAG_HIDDEN);
|
|
else
|
|
lv_obj_remove_flag(id(status_ips), LV_OBJ_FLAG_HIDDEN);
|
|
|
|
const bool api_ok = api::global_api_server->is_connected();
|
|
set(id(status_ha), api_ok ? "Home Assistant: connected" : "Home Assistant: waiting...",
|
|
api_ok ? OK : WAIT);
|
|
|
|
const uint32_t up = millis() / 1000;
|
|
lv_label_set_text(id(status_footer),
|
|
str_sprintf("ESPHome %s · up %ud %02u:%02u:%02u", ESPHOME_VERSION, up / 86400,
|
|
(up / 3600) % 24, (up / 60) % 60, up % 60).c_str());
|
|
- id: update_axp
|
|
then:
|
|
- lvgl.label.update:
|
|
id: axp_values
|
|
text: !lambda |-
|
|
return str_sprintf("%.2f V %.0f %%\n%+.0f mA%s\n%.2f V %.0f mA\n%.2f V %.0f mA\n%.2f V\n%.1f °C",
|
|
id(battery_voltage).state, id(battery_level).state, id(battery_current).state,
|
|
id(battery_charging).state ? " charging" : "",
|
|
id(vbus_voltage).state, id(vbus_current).state,
|
|
id(acin_voltage).state, id(acin_current).state,
|
|
id(aps_voltage).state, id(pmu_temperature).state);
|
|
|
|
interval:
|
|
- interval: 5s
|
|
then:
|
|
- lambda: |-
|
|
auto *a = id(pmu_axp);
|
|
auto r = [a](uint8_t reg) { return a->readRegister(reg) & 0xFF; };
|
|
auto adc12 = [&](uint8_t h) { return (r(h) << 4) | (r(h + 1) & 0x0F); };
|
|
auto adc13 = [&](uint8_t h) { return (r(h) << 5) | (r(h + 1) & 0x1F); };
|
|
const float bat = adc12(0x78) * 1.1f / 1000;
|
|
id(battery_voltage).publish_state(bat);
|
|
// ponytail: linear 3.3-4.1 V, a discharge curve if the percentage matters
|
|
id(battery_level).publish_state(clamp((bat - 3.3f) / 0.8f * 100, 0.0f, 100.0f));
|
|
id(battery_current).publish_state(adc13(0x7A) * 0.5f - adc13(0x7C) * 0.5f);
|
|
id(vbus_voltage).publish_state(adc12(0x5A) * 1.7f / 1000);
|
|
id(vbus_current).publish_state(adc12(0x5C) * 0.375f);
|
|
id(acin_voltage).publish_state(adc12(0x56) * 1.7f / 1000);
|
|
id(acin_current).publish_state(adc12(0x58) * 0.625f);
|
|
id(aps_voltage).publish_state(adc12(0x7E) * 1.4f / 1000);
|
|
id(pmu_temperature).publish_state(adc12(0x5E) * 0.1f - 144.7f);
|
|
id(battery_charging).publish_state(r(0x01) & 0x40);
|
|
# thermal page: the newest MLX90640 frame, 32x24 upscaled bilinear x8 with the iron palette
|
|
- interval: 125ms
|
|
then:
|
|
- if:
|
|
condition:
|
|
lvgl.page.is_showing: thermal_page
|
|
then:
|
|
- lambda: |-
|
|
static float px[32 * 24];
|
|
static uint32_t shown = 0;
|
|
static uint16_t palette[256];
|
|
static bool palette_ready = false;
|
|
if (!id(thermal).has_frame() || id(thermal).get_frame_count() == shown)
|
|
return;
|
|
shown = id(thermal).get_frame_count();
|
|
id(thermal).copy_display_frame(px);
|
|
if (!palette_ready) {
|
|
// iron: black, navy, magenta, orange, yellow, white
|
|
const float stop[][4] = {{0, 0, 0, 0}, {0.2f, 32, 0, 140}, {0.45f, 204, 0, 119},
|
|
{0.7f, 255, 140, 0}, {0.85f, 255, 215, 0}, {1, 255, 255, 255}};
|
|
for (int i = 0; i < 256; i++) {
|
|
const float t = i / 255.0f;
|
|
int k = 0;
|
|
while (k < 4 && t > stop[k + 1][0])
|
|
k++;
|
|
const float f = (t - stop[k][0]) / (stop[k + 1][0] - stop[k][0]);
|
|
auto mix = [&](int c) { return uint8_t(stop[k][c] + f * (stop[k + 1][c] - stop[k][c])); };
|
|
palette[i] = lv_color_to_u16(lv_color_make(mix(1), mix(2), mix(3)));
|
|
}
|
|
palette_ready = true;
|
|
}
|
|
float lo = px[0], hi = px[0];
|
|
for (float v : px) {
|
|
lo = std::min(lo, v);
|
|
hi = std::max(hi, v);
|
|
}
|
|
const float center = (px[11 * 32 + 15] + px[11 * 32 + 16] + px[12 * 32 + 15] + px[12 * 32 + 16]) / 4;
|
|
float a = lo, b = hi;
|
|
if (b - a < 2) { // flat scenes would show noise
|
|
a = (lo + hi) / 2 - 1;
|
|
b = a + 2;
|
|
}
|
|
const float k = 255 / (b - a);
|
|
lv_obj_t *canvas = id(thermal_canvas);
|
|
lv_draw_buf_t *buf = lv_canvas_get_draw_buf(canvas);
|
|
for (int y = 0; y < 192; y++) {
|
|
const float sy = std::clamp((y + 0.5f) / 8 - 0.5f, 0.0f, 23.0f);
|
|
const int y0 = int(sy), y1 = std::min(y0 + 1, 23);
|
|
const float fy = sy - y0;
|
|
auto *row = reinterpret_cast<uint16_t *>(buf->data + y * buf->header.stride);
|
|
for (int x = 0; x < 256; x++) {
|
|
const float sx = std::clamp((x + 0.5f) / 8 - 0.5f, 0.0f, 31.0f);
|
|
const int x0 = int(sx), x1 = std::min(x0 + 1, 31);
|
|
const float fx = sx - x0;
|
|
const float top = px[y0 * 32 + x0] + fx * (px[y0 * 32 + x1] - px[y0 * 32 + x0]);
|
|
const float bottom = px[y1 * 32 + x0] + fx * (px[y1 * 32 + x1] - px[y1 * 32 + x0]);
|
|
row[x] = palette[std::clamp(int((top + fy * (bottom - top) - a) * k), 0, 255)];
|
|
}
|
|
}
|
|
// crosshair on the center spot
|
|
const uint16_t white = lv_color_to_u16(lv_color_white());
|
|
for (int d = -6; d <= 6; d++) {
|
|
if (d > -2 && d < 2)
|
|
continue;
|
|
reinterpret_cast<uint16_t *>(buf->data + 96 * buf->header.stride)[128 + d] = white;
|
|
reinterpret_cast<uint16_t *>(buf->data + (96 + d) * buf->header.stride)[128] = white;
|
|
}
|
|
lv_obj_invalidate(canvas);
|
|
lv_label_set_text(id(thermal_max), str_sprintf("%.1f°", hi).c_str());
|
|
lv_label_set_text(id(thermal_center), str_sprintf("%.1f°", center).c_str());
|
|
lv_label_set_text(id(thermal_min), str_sprintf("%.1f°", lo).c_str());
|
|
- interval: 1s
|
|
then:
|
|
- lvgl.label.update:
|
|
id: unit_time
|
|
text: !lambda |-
|
|
auto now = id(ha_time).now();
|
|
return now.is_valid() ? now.strftime("%H:%M") : std::string("--:--");
|
|
- lvgl.bar.update:
|
|
id: unit_battery_bar
|
|
value: !lambda return id(battery_level).state;
|
|
- lvgl.label.update:
|
|
id: unit_battery
|
|
text: !lambda |-
|
|
return str_sprintf("%.2f V %.0f %%%s", id(battery_voltage).state, id(battery_level).state,
|
|
id(battery_charging).state ? " charging" : "");
|
|
- if:
|
|
condition:
|
|
lvgl.page.is_showing: status_page
|
|
then:
|
|
- script.execute: update_status
|
|
- if:
|
|
condition:
|
|
lvgl.page.is_showing: axp_page
|
|
then:
|
|
- script.execute: update_axp
|
|
|
|
image:
|
|
- platform: file
|
|
file: assets/images/made-for-esphome-white-on-black.svg
|
|
id: esphome_logo
|
|
resize: 280x83
|
|
type: RGB565
|
|
transparency: alpha_channel
|
|
|
|
font:
|
|
- file: "gfonts://Roboto"
|
|
id: font_title
|
|
size: 24
|
|
- file: "gfonts://Roboto"
|
|
id: font_status
|
|
size: 16
|
|
glyphs: "·°"
|
|
glyphsets: [GF_Latin_Kernel]
|
|
|
|
lvgl:
|
|
- id: lvgl_main
|
|
displays: display_tft
|
|
touchscreens: touch_lcd
|
|
buffer_size: 25%
|
|
log_level: WARN
|
|
bg_color: 0x000000
|
|
text_color: 0xFFFFFF
|
|
pages:
|
|
# 1: keyboard demo
|
|
- id: main_page
|
|
widgets:
|
|
- label:
|
|
align: TOP_MID
|
|
y: 6
|
|
text_font: font_title
|
|
text: ${name}
|
|
- textarea:
|
|
id: input_text
|
|
align: TOP_MID
|
|
y: 40
|
|
width: 300
|
|
height: 70
|
|
text_font: font_status
|
|
placeholder_text: Type on the keyboard...
|
|
- label:
|
|
align: TOP_LEFT
|
|
x: 10
|
|
y: 122
|
|
text_font: font_status
|
|
text: "Last line:"
|
|
- label:
|
|
id: last_line
|
|
align: TOP_LEFT
|
|
x: 90
|
|
y: 122
|
|
width: 220
|
|
long_mode: DOT
|
|
text_font: font_status
|
|
text: "-"
|
|
- slider:
|
|
id: demo_slider
|
|
align: BOTTOM_LEFT
|
|
x: 20
|
|
y: -40
|
|
width: 170
|
|
on_value:
|
|
- lvgl.arc.update:
|
|
id: demo_arc
|
|
value: !lambda return x;
|
|
- arc:
|
|
id: demo_arc
|
|
align: BOTTOM_RIGHT
|
|
x: -15
|
|
y: -15
|
|
width: 100
|
|
height: 100
|
|
adjustable: false
|
|
|
|
# 2: AXP192 diagnostics
|
|
- id: axp_page
|
|
on_load:
|
|
- script.execute: update_axp
|
|
widgets:
|
|
- label:
|
|
align: TOP_MID
|
|
y: 6
|
|
text_font: font_title
|
|
text: AXP192
|
|
- label:
|
|
x: 16
|
|
y: 44
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: "Battery\nCurrent\nUSB (VBUS)\nM-Bus 5V (ACIN)\nAPS\nTemperature"
|
|
- label:
|
|
id: axp_values
|
|
x: 170
|
|
y: 44
|
|
text_font: font_status
|
|
text: ""
|
|
|
|
# 3: LoRa, last received Meshtastic packet
|
|
- id: lora_page
|
|
widgets:
|
|
- label:
|
|
align: TOP_MID
|
|
y: 6
|
|
text_font: font_title
|
|
text: Meshtastic LongFast
|
|
- label:
|
|
x: 16
|
|
y: 44
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: "RSSI\nSNR\nPackets"
|
|
- label:
|
|
id: lora_stats
|
|
x: 170
|
|
y: 44
|
|
text_font: font_status
|
|
text: "-\n-\n0"
|
|
- label:
|
|
x: 16
|
|
y: 120
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: "Last message:"
|
|
- label:
|
|
id: lora_last
|
|
x: 16
|
|
y: 142
|
|
width: 288
|
|
long_mode: WRAP
|
|
text_font: font_status
|
|
text: "-"
|
|
|
|
# 4: MLX90640 thermal image, drawn by the 125 ms interval
|
|
- id: thermal_page
|
|
widgets:
|
|
- canvas:
|
|
id: thermal_canvas
|
|
x: 0
|
|
y: 24
|
|
width: 256
|
|
height: 192
|
|
- label:
|
|
x: 262
|
|
y: 24
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: Max
|
|
- label:
|
|
id: thermal_max
|
|
x: 262
|
|
y: 44
|
|
text_font: font_status
|
|
text_color: 0xFF6040
|
|
text: "-"
|
|
- label:
|
|
x: 262
|
|
y: 98
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: "Center"
|
|
- label:
|
|
id: thermal_center
|
|
x: 262
|
|
y: 118
|
|
text_font: font_status
|
|
text: "-"
|
|
- label:
|
|
x: 262
|
|
y: 172
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: Min
|
|
- label:
|
|
id: thermal_min
|
|
x: 262
|
|
y: 192
|
|
text_font: font_status
|
|
text_color: 0x40A0FF
|
|
text: "-"
|
|
- label:
|
|
align: TOP_MID
|
|
x: -32
|
|
y: 2
|
|
text_font: font_status
|
|
text: MLX90640
|
|
|
|
# 5: status (shown until Home Assistant connects)
|
|
- id: status_page
|
|
on_load:
|
|
- script.execute: update_status
|
|
widgets:
|
|
- image:
|
|
src: esphome_logo
|
|
align: TOP_MID
|
|
y: 8
|
|
- label:
|
|
align: TOP_MID
|
|
y: 96
|
|
text_font: font_title
|
|
text: "${name}"
|
|
- obj:
|
|
x: 16
|
|
y: 132
|
|
width: 288
|
|
height: SIZE_CONTENT
|
|
bg_opa: TRANSP
|
|
border_width: 0
|
|
pad_all: 0
|
|
scrollbar_mode: "OFF"
|
|
layout:
|
|
type: flex
|
|
flex_flow: column
|
|
pad_row: 4
|
|
widgets:
|
|
- label:
|
|
id: status_wifi
|
|
text_font: font_status
|
|
text: ""
|
|
- label:
|
|
id: status_ips
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
pad_left: 20
|
|
text: ""
|
|
- label:
|
|
id: status_ha
|
|
text_font: font_status
|
|
text: ""
|
|
- label:
|
|
id: status_footer
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: ""
|
|
|
|
# Unit LCD on Port C, rotated by LVGL (the display can't rotate under LVGL)
|
|
- id: lvgl_unit
|
|
displays: unit_lcd
|
|
rotation: 90
|
|
buffer_size: 100%
|
|
bg_color: 0x101830
|
|
text_color: 0xFFFFFF
|
|
widgets:
|
|
- label:
|
|
x: 6
|
|
y: 4
|
|
text_font: font_title
|
|
text_color: 0xFFB300
|
|
text: ${name}
|
|
- label:
|
|
id: unit_time
|
|
align: TOP_RIGHT
|
|
x: -6
|
|
y: 4
|
|
text_font: font_title
|
|
text: "--:--"
|
|
- label:
|
|
x: 6
|
|
y: 44
|
|
text_font: font_status
|
|
text_color: 0x8C8C8C
|
|
text: "Last line:"
|
|
- label:
|
|
id: unit_last_line
|
|
x: 6
|
|
y: 64
|
|
width: 228
|
|
long_mode: DOT
|
|
text_font: font_status
|
|
text: "-"
|
|
- bar:
|
|
id: unit_battery_bar
|
|
x: 6
|
|
y: 94
|
|
width: 228
|
|
height: 10
|
|
min_value: 0
|
|
max_value: 100
|
|
- label:
|
|
id: unit_battery
|
|
x: 6
|
|
y: 110
|
|
text_font: font_status
|
|
text: ""
|