diff --git a/esphome/lab-ble-proxy-owon.h b/esphome/lab-ble-proxy-owon.h index e47acea..ad36bca 100644 --- a/esphome/lab-ble-proxy-owon.h +++ b/esphome/lab-ble-proxy-owon.h @@ -362,10 +362,10 @@ class Meter { } void render(esphome::display::Display &it, esphome::display::BaseFont *font, - int display_page = 0, bool atorch_running = false, + esphome::display::BaseFont *value_font, int display_page = 0, + bool atorch_connected = false, float atorch_voltage = NAN, float atorch_current = NAN, float atorch_power = NAN, - float atorch_capacity = NAN, float atorch_energy = NAN, float atorch_temperature = NAN, - const char *atorch_runtime = "--:--:--") { + float atorch_capacity = NAN, float atorch_temperature = NAN) { const Color bg(0, 0, 0); const Color fg(210, 210, 210); // Chosen to map to a neutral dark gray in the RGB332 8-bit display palette. @@ -440,35 +440,32 @@ class Meter { char current_text[24]; char power_text[24]; char capacity_text[24]; - char energy_text[24]; char temperature_text[24]; this->format_metric_(voltage_text, sizeof(voltage_text), atorch_voltage, "V", 2); this->format_metric_(current_text, sizeof(current_text), atorch_current, "A", 3); this->format_metric_(power_text, sizeof(power_text), atorch_power, "W", 2); this->format_metric_(capacity_text, sizeof(capacity_text), atorch_capacity, "Ah", 3); - this->format_metric_(energy_text, sizeof(energy_text), atorch_energy, "Wh", 3); this->format_metric_(temperature_text, sizeof(temperature_text), atorch_temperature, "°C", 1); it.filled_rectangle(0, 0, 320, 30, panel_dim); it.print(10, 7, font, cyan, esphome::display::TextAlign::TOP_LEFT, "ATORCH DL24"); - it.filled_rectangle(230, 6, 80, 18, atorch_running ? green : inactive); - it.print(270, 8, font, bg, esphome::display::TextAlign::TOP_CENTER, atorch_running ? "RUNNING" : "STOPPED"); + if (atorch_connected) { + this->draw_icon_(it, 152, 7, 16, 16, BLE_BMP, blue); + } + it.print(310, 7, font, inactive, esphome::display::TextAlign::TOP_RIGHT, "DC LOAD"); - this->draw_metric_card_(it, font, 10, 42, 145, 70, "VOLTAGE", voltage_text, cyan, panel, border); - this->draw_metric_card_(it, font, 165, 42, 145, 70, "CURRENT", current_text, orange, panel, border); - this->draw_metric_card_(it, font, 10, 122, 145, 70, "POWER", power_text, yellow, panel, border); - this->draw_metric_card_(it, font, 165, 122, 145, 70, "TEMP", temperature_text, magenta, panel, border); + this->draw_metric_card_(it, font, value_font, 10, 42, 145, 76, "VOLTAGE", voltage_text, cyan, panel, border); + this->draw_metric_card_(it, font, value_font, 165, 42, 145, 76, "CURRENT", current_text, orange, panel, border); + this->draw_metric_card_(it, font, value_font, 10, 128, 145, 76, "POWER", power_text, yellow, panel, border); + this->draw_metric_card_(it, font, value_font, 165, 128, 145, 76, "TEMP", temperature_text, magenta, panel, border); - it.filled_rectangle(10, 202, 300, 30, panel_dim); - it.filled_rectangle(10, 202, 300, 1, border); - it.filled_rectangle(10, 231, 300, 1, border); - it.filled_rectangle(10, 202, 1, 30, border); - it.filled_rectangle(309, 202, 1, 30, border); - it.print(24, 209, font, inactive, esphome::display::TextAlign::TOP_LEFT, "CAP"); - it.print(67, 209, font, white, esphome::display::TextAlign::TOP_LEFT, capacity_text); - it.print(143, 209, font, inactive, esphome::display::TextAlign::TOP_LEFT, "ENERGY"); - it.print(206, 209, font, white, esphome::display::TextAlign::TOP_LEFT, energy_text); - it.print(306, 209, font, green, esphome::display::TextAlign::TOP_RIGHT, atorch_runtime); + it.filled_rectangle(10, 212, 300, 22, panel_dim); + it.filled_rectangle(10, 212, 300, 1, border); + it.filled_rectangle(10, 233, 300, 1, border); + it.filled_rectangle(10, 212, 1, 22, border); + it.filled_rectangle(309, 212, 1, 22, border); + it.print(24, 216, font, inactive, esphome::display::TextAlign::TOP_LEFT, "CAPACITY"); + it.print(306, 212, value_font, white, esphome::display::TextAlign::TOP_RIGHT, capacity_text); } } @@ -609,8 +606,9 @@ class Meter { snprintf(buffer, size, format, value, unit); } - void draw_metric_card_(Display &it, esphome::display::BaseFont *font, int x, int y, int w, int h, - const char *title, const char *value, Color accent, Color fill, Color border) { + void draw_metric_card_(Display &it, esphome::display::BaseFont *label_font, esphome::display::BaseFont *value_font, + int x, int y, int w, int h, const char *title, const char *value, + Color accent, Color fill, Color border) { const Color bg(0, 0, 0); const Color fg(235, 235, 235); const Color inactive(90, 100, 110); @@ -619,8 +617,8 @@ class Meter { it.filled_rectangle(x, y + h - 1, w, 1, border); it.filled_rectangle(x, y, 1, h, border); it.filled_rectangle(x + w - 1, y, 1, h, border); - it.print(x + 10, y + 10, font, inactive, esphome::display::TextAlign::TOP_LEFT, title); - it.print(x + w / 2, y + 38, font, fg, esphome::display::TextAlign::CENTER, value); + it.print(x + 10, y + 9, label_font, inactive, esphome::display::TextAlign::TOP_LEFT, title); + it.print(x + w / 2, y + 43, value_font, fg, esphome::display::TextAlign::CENTER, value); it.filled_rectangle(x + 10, y + h - 11, w - 20, 3, bg); it.filled_rectangle(x + 10, y + h - 11, w - 20, 1, accent); } diff --git a/esphome/lab-ble-proxy.yaml b/esphome/lab-ble-proxy.yaml index 2e5ebf3..5833167 100644 --- a/esphome/lab-ble-proxy.yaml +++ b/esphome/lab-ble-proxy.yaml @@ -74,6 +74,10 @@ globals: type: int initial_value: "0" restore_value: no + - id: atorch_connected + type: bool + initial_value: "false" + restore_value: no interval: - interval: 10s @@ -108,6 +112,16 @@ ble_client: - mac_address: ${dl24_mac_address} id: atorch_ble_client + on_connect: + then: + - lambda: |- + id(atorch_connected) = true; + id(lcd).update(); + on_disconnect: + then: + - lambda: |- + id(atorch_connected) = false; + id(lcd).update(); atorch_dl24: - id: atorch0 @@ -217,6 +231,33 @@ font: "Ω", ] + - file: "fonts/Roboto-Medium.ttf" + id: atorch_value_font + size: 22 + glyphs: + [ + " ", + "+", + "-", + ".", + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "A", + "C", + "V", + "W", + "h", + "°", + ] + display: - platform: mipi_spi id: lcd @@ -226,15 +267,14 @@ display: owon_meter.render( it, id(meter_font), + id(atorch_value_font), id(display_page), - id(atorch_running).state, + id(atorch_connected), id(atorch_voltage).has_state() ? id(atorch_voltage).state : NAN, id(atorch_current).has_state() ? id(atorch_current).state : NAN, id(atorch_power).has_state() ? id(atorch_power).state : NAN, id(atorch_capacity).has_state() ? id(atorch_capacity).state : NAN, - id(atorch_energy).has_state() ? id(atorch_energy).state : NAN, - id(atorch_temperature).has_state() ? id(atorch_temperature).state : NAN, - id(atorch_runtime_formatted).has_state() ? id(atorch_runtime_formatted).state.c_str() : "--:--:--" + id(atorch_temperature).has_state() ? id(atorch_temperature).state : NAN ); touchscreen: @@ -330,6 +370,11 @@ binary_sensor: name: "${friendly_name} OWON Low Battery" lambda: |- return owon_meter.low_battery; + - platform: template + name: "${friendly_name} Atorch Connected" + device_class: connectivity + lambda: |- + return id(atorch_connected); sensor: - platform: ble_client