V1.5: 电能底数首次同步补足1.00kWh(平台过滤0值);OLED联网界面R0改网络+运行时间(天:时:分),未联网首行显示断网

This commit is contained in:
helei 2026-08-15 06:55:15 +08:00
parent d51dbb8ce3
commit 0cf47b6d57
2 changed files with 27 additions and 17 deletions

View File

@ -107,6 +107,17 @@ static void hlw8032_parse(const uint8_t *f)
if (!s_synced) {
s_synced = 1;
log_info("> 电能: HLW8032 在线, 功率参数=%lu", (unsigned long)s_power_par);
/* 电能底数:平台会过滤 0 值,首次(累计不足 1 度)把底数补足 1.00 kWh 并落盘。
* */
{
uint64_t one_kwh = (uint64_t)(3.6e12 /
((double)s_power_par * HLW_U_COEF * HLW_I_COEF));
if (s_total_pulses < one_kwh) {
s_total_pulses = one_kwh;
hlw8032_save();
log_info("> 电能: 底数已初始化为 1.00 kWh");
}
}
}
s_last_frame_tick = HAL_GetTick();
}

View File

@ -210,40 +210,39 @@ static void oled_home_refresh(uint32_t up_ms)
if (g_net_mqtt_ready) {
/*---- 已联网界面 ----*/
/* R0: 网络 + 运行时间(天:时:分) */
uint32_t mins = up_ms / 60000u;
const char *nt = (NET_GetActiveBackend() == NET_BACKEND_WIFI) ? "WiFi" : "4G";
snprintf(buf, sizeof(buf), "%s %02u:%02u:%02u", nt,
(unsigned)(mins / 1440u),
(unsigned)((mins % 1440u) / 60u),
(unsigned)(mins % 60u));
oled_locate(0, 0); oled_xoff(xoff); oled_print_line(buf);
/* R1/R2: 电能参数 */
if (hlw8032_online()) {
snprintf(buf, sizeof(buf), "%.1fV %.2fA",
(double)hlw8032_get_voltage_v(), (double)hlw8032_get_current_a());
oled_locate(0, 0); oled_xoff(xoff); oled_print_line(buf);
oled_locate(1, 0); oled_xoff(xoff); oled_print_line(buf);
snprintf(buf, sizeof(buf), "%.1fW %.2fkWh",
(double)hlw8032_get_power_w(), (double)hlw8032_get_energy_kwh());
oled_locate(1, 0); oled_xoff(xoff); oled_print_line(buf);
oled_locate(2, 0); oled_xoff(xoff); oled_print_line(buf);
} else {
oled_locate(0, 0); oled_xoff(xoff); oled_print_line("计量芯片离线");
oled_locate(1, 0); oled_xoff(xoff); oled_print_line("");
oled_locate(1, 0); oled_xoff(xoff); oled_print_line("计量芯片离线");
oled_locate(2, 0); oled_xoff(xoff); oled_print_line("");
}
/* R3: 开关状态 */
snprintf(buf, sizeof(buf), "开关:%s%s%s%s",
MqttInfoStr.Relay_State[1] ? "" : "",
MqttInfoStr.Relay_State[2] ? "" : "",
MqttInfoStr.Relay_State[3] ? "" : "",
MqttInfoStr.Relay_State[4] ? "" : "");
oled_locate(2, 0); oled_xoff(xoff); oled_print_line(buf);
/* 网络 + 运行时间:满 1 天显示 "1天02时",否则 "27:35" */
uint32_t mins = up_ms / 60000u;
const char *nt = (NET_GetActiveBackend() == NET_BACKEND_WIFI) ? "WiFi" : "4G";
if (mins >= 1440u) {
snprintf(buf, sizeof(buf), "%s已连接%u天%02u时", nt,
(unsigned)(mins / 1440u), (unsigned)((mins % 1440u) / 60u));
} else {
snprintf(buf, sizeof(buf), "%s已连接%02u:%02u", nt,
(unsigned)(mins / 60u), (unsigned)(mins % 60u));
}
oled_locate(3, 0); oled_xoff(xoff); oled_print_line(buf);
} else {
/*---- 未联网界面:联网进度 ----*/
net_ui_phase_t ph = g_net_ui_phase;
oled_locate(0, 0); oled_xoff(xoff); oled_print_line("");
oled_locate(0, 0); oled_xoff(xoff); oled_print_line("断网");
if (ph == NET_UI_WIFI_FIXED || ph == NET_UI_WIFI_SMART ||
NET_GetActiveBackend() == NET_BACKEND_WIFI) {