Implemented rough 1st iteration of dc-load value screen.
This commit is contained in:
+120
-46
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* ESPHome helper for OWON B35T/B35T+ BLE meter on M5Stack Core 1.
|
||||
* ESPHome helper for OWON B35T/B35T+ BLE meter on M5Stack Core 2.
|
||||
* Parser is based on the standalone Arduino sketch by Reaper7
|
||||
* (Beerware license, Revision 42) and Dean Cording's owonb35 notes.
|
||||
*/
|
||||
@@ -361,7 +361,11 @@ class Meter {
|
||||
if (this->selected_button < 6) this->selected_button++;
|
||||
}
|
||||
|
||||
void render(Display &it, esphome::display::BaseFont *font) {
|
||||
void render(esphome::display::Display &it, esphome::display::BaseFont *font,
|
||||
int display_page = 0, bool atorch_running = 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 = "--:--:--") {
|
||||
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.
|
||||
@@ -374,54 +378,98 @@ class Meter {
|
||||
const Color green(0, 220, 0);
|
||||
const Color orange(255, 165, 0);
|
||||
|
||||
it.fill(bg);
|
||||
bool status_active = this->connected && this->has_reading;
|
||||
this->draw_icon_(it, 12, 8, 16, 16, ACCU_BMP, status_active ? (this->low_battery ? red : green) : inactive);
|
||||
this->draw_icon_(it, 46, 8, 16, 16, BLE_BMP, this->connected ? blue : inactive);
|
||||
this->label_(it, font, 86, 8, "AUTO", status_active && this->auto_range() ? fg : inactive);
|
||||
this->label_(it, font, 138, 8, "MAX", status_active && this->max_mode() ? red : inactive);
|
||||
this->label_(it, font, 178, 8, "MIN", status_active && this->min_mode() ? green : inactive);
|
||||
this->label_(it, font, 218, 8, "HOLD", status_active && this->hold() ? blue : inactive);
|
||||
this->label_(it, font, 270, 8, "REL", status_active && this->relative() ? Color(128, 128, 0) : inactive);
|
||||
if (display_page == 0) {
|
||||
// --- PAGE 1: OWON Multimeter ---
|
||||
it.fill(bg);
|
||||
bool status_active = this->connected && this->has_reading;
|
||||
this->draw_icon_(it, 12, 8, 16, 16, ACCU_BMP, status_active ? (this->low_battery ? red : green) : inactive);
|
||||
this->draw_icon_(it, 46, 8, 16, 16, BLE_BMP, this->connected ? blue : inactive);
|
||||
this->label_(it, font, 86, 8, "AUTO", status_active && this->auto_range() ? fg : inactive);
|
||||
this->label_(it, font, 138, 8, "MAX", status_active && this->max_mode() ? red : inactive);
|
||||
this->label_(it, font, 178, 8, "MIN", status_active && this->min_mode() ? green : inactive);
|
||||
this->label_(it, font, 218, 8, "HOLD", status_active && this->hold() ? blue : inactive);
|
||||
this->label_(it, font, 270, 8, "REL", status_active && this->relative() ? Color(128, 128, 0) : inactive);
|
||||
|
||||
this->label_(it, font, 8, 66, "DC", status_active && this->dc() ? cyan : inactive);
|
||||
this->label_(it, font, 8, 102, "AC", status_active && this->ac() ? magenta : inactive);
|
||||
this->label_(it, font, 8, 66, "DC", status_active && this->dc() ? cyan : inactive);
|
||||
this->label_(it, font, 8, 102, "AC", status_active && this->ac() ? magenta : inactive);
|
||||
|
||||
if (!this->connected) {
|
||||
this->draw_digits_(it, "----", false, inactive);
|
||||
it.print(160, 148, font, inactive, esphome::display::TextAlign::CENTER, "scan/connect");
|
||||
} else if (!this->has_reading) {
|
||||
this->draw_digits_(it, "8888", false, inactive);
|
||||
it.print(160, 148, font, inactive, esphome::display::TextAlign::CENTER, "waiting");
|
||||
} else if (this->overload) {
|
||||
this->draw_digits_(it, " OL ", false, fg);
|
||||
if (!this->connected) {
|
||||
this->draw_digits_(it, "----", false, inactive);
|
||||
it.print(160, 148, font, inactive, esphome::display::TextAlign::CENTER, "scan/connect");
|
||||
} else if (!this->has_reading) {
|
||||
this->draw_digits_(it, "8888", false, inactive);
|
||||
it.print(160, 148, font, inactive, esphome::display::TextAlign::CENTER, "waiting");
|
||||
} else if (this->overload) {
|
||||
this->draw_digits_(it, " OL ", false, fg);
|
||||
} else {
|
||||
char d[5];
|
||||
d[0] = this->digit_char_(REGDIG1);
|
||||
d[1] = this->digit_char_(REGDIG2);
|
||||
d[2] = this->digit_char_(REGDIG3);
|
||||
d[3] = this->digit_char_(REGDIG4);
|
||||
d[4] = 0;
|
||||
this->draw_digits_(it, d, this->negative(), fg);
|
||||
this->draw_decimal_points_(it, fg);
|
||||
}
|
||||
|
||||
if (status_active) {
|
||||
std::string unit_line = std::string(this->scale()) + this->unit();
|
||||
it.print(270, 140, font, yellow, esphome::display::TextAlign::CENTER, unit_line.c_str());
|
||||
}
|
||||
|
||||
bool bargraph_active = status_active && !this->overload;
|
||||
this->draw_bargraph_(it, bargraph_active ? this->digits_from_buffer_() : 0, bargraph_active);
|
||||
this->draw_icon_(it, 300, 148, 16, 16, DIODE_BMP, status_active && this->diode() ? magenta : inactive);
|
||||
this->draw_icon_(it, 300, 174, 16, 16, BUZZ_BMP, status_active && this->continuity() ? orange : inactive);
|
||||
|
||||
it.filled_rectangle(34, 212, 40, 24, this->write_available ? fg : inactive);
|
||||
it.filled_rectangle(108, 212, 100, 24, this->write_available ? fg : inactive);
|
||||
it.filled_rectangle(242, 212, 40, 24, this->write_available ? fg : inactive);
|
||||
it.print(54, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, "<");
|
||||
it.print(158, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, this->selected_button_name());
|
||||
it.print(262, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, ">");
|
||||
} else {
|
||||
char d[5];
|
||||
d[0] = this->digit_char_(REGDIG1);
|
||||
d[1] = this->digit_char_(REGDIG2);
|
||||
d[2] = this->digit_char_(REGDIG3);
|
||||
d[3] = this->digit_char_(REGDIG4);
|
||||
d[4] = 0;
|
||||
this->draw_digits_(it, d, this->negative(), fg);
|
||||
this->draw_decimal_points_(it, fg);
|
||||
// --- PAGE 2: Atorch DL24 DC load ---
|
||||
it.fill(bg);
|
||||
const Color panel(18, 24, 32);
|
||||
const Color panel_dim(10, 14, 20);
|
||||
const Color border(55, 70, 86);
|
||||
const Color white(245, 245, 245);
|
||||
|
||||
char voltage_text[24];
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (status_active) {
|
||||
std::string unit_line = std::string(this->scale()) + this->unit();
|
||||
it.print(270, 140, font, yellow, esphome::display::TextAlign::CENTER, unit_line.c_str());
|
||||
}
|
||||
|
||||
bool bargraph_active = status_active && !this->overload;
|
||||
this->draw_bargraph_(it, bargraph_active ? this->digits_from_buffer_() : 0, bargraph_active);
|
||||
this->draw_icon_(it, 300, 148, 16, 16, DIODE_BMP, status_active && this->diode() ? magenta : inactive);
|
||||
this->draw_icon_(it, 300, 174, 16, 16, BUZZ_BMP, status_active && this->continuity() ? orange : inactive);
|
||||
|
||||
it.filled_rectangle(34, 212, 40, 24, this->write_available ? fg : inactive);
|
||||
it.filled_rectangle(108, 212, 100, 24, this->write_available ? fg : inactive);
|
||||
it.filled_rectangle(242, 212, 40, 24, this->write_available ? fg : inactive);
|
||||
it.print(54, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, "<");
|
||||
it.print(158, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, this->selected_button_name());
|
||||
it.print(262, 216, font, bg, esphome::display::TextAlign::TOP_CENTER, ">");
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -551,6 +599,32 @@ class Meter {
|
||||
return (c >= '0' && c <= '9') ? static_cast<char>(c) : ' ';
|
||||
}
|
||||
|
||||
void format_metric_(char *buffer, size_t size, float value, const char *unit, uint8_t decimals) const {
|
||||
if (!std::isfinite(value)) {
|
||||
snprintf(buffer, size, "-- %s", unit);
|
||||
return;
|
||||
}
|
||||
char format[12];
|
||||
snprintf(format, sizeof(format), "%%.%uf %%s", decimals);
|
||||
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) {
|
||||
const Color bg(0, 0, 0);
|
||||
const Color fg(235, 235, 235);
|
||||
const Color inactive(90, 100, 110);
|
||||
it.filled_rectangle(x, y, w, h, fill);
|
||||
it.filled_rectangle(x, y, w, 2, accent);
|
||||
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.filled_rectangle(x + 10, y + h - 11, w - 20, 3, bg);
|
||||
it.filled_rectangle(x + 10, y + h - 11, w - 20, 1, accent);
|
||||
}
|
||||
|
||||
void label_(Display &it, esphome::display::BaseFont *font, int x, int y, const char *text, Color color) {
|
||||
it.print(x, y, font, color, esphome::display::TextAlign::TOP_LEFT, text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user