nyx: do communication checks in battery info

If communication with an IC fails, an error will show up.
This commit is contained in:
CTCaer
2025-08-08 15:11:32 +03:00
parent f013c54a23
commit db5cc323f2

View File

@@ -2387,9 +2387,11 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn)
char *txt_buf = (char *)malloc(SZ_16K); char *txt_buf = (char *)malloc(SZ_16K);
int value = 0; int value = 0;
int cap_pct = 0;
// Fuel gauge IC info. // Fuel gauge IC info.
if (!max17050_get_version(NULL))
{
int cap_pct = 0;
max17050_get_property(MAX17050_RepSOC, &cap_pct); max17050_get_property(MAX17050_RepSOC, &cap_pct);
max17050_get_property(MAX17050_RepCap, &value); max17050_get_property(MAX17050_RepCap, &value);
s_printf(txt_buf, "\n%d mAh [%d %%]\n", value, cap_pct >> 8); s_printf(txt_buf, "\n%d mAh [%d %%]\n", value, cap_pct >> 8);
@@ -2427,6 +2429,9 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn)
max17050_get_property(MAX17050_TEMP, &value); max17050_get_property(MAX17050_TEMP, &value);
s_printf(txt_buf + strlen(txt_buf), "%d.%d oC\n\n\n", value / 10, (value >= 0 ? value : (~value + 1)) % 10); s_printf(txt_buf + strlen(txt_buf), "%d.%d oC\n\n\n", value / 10, (value >= 0 ? value : (~value + 1)) % 10);
}
else
strcpy(txt_buf, "\n#FF8000 "SYMBOL_WARNING" Error!#\n\n\n\n\n\n\n\n\n\n\n\n\n");
// Main Pmic IC info. // Main Pmic IC info.
value = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_CID4); value = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_CID4);
@@ -2487,9 +2492,11 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn)
lv_obj_set_size(val2, LV_HOR_RES / 2 / 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); lv_obj_set_size(val2, LV_HOR_RES / 2 / 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5);
lv_obj_t * lb_val2 = lv_label_create(val2, lb_desc); lv_obj_t * lb_val2 = lv_label_create(val2, lb_desc);
int iinlim = 0;
// Charger IC info. // Charger IC info.
int iinlim = 0; if (!bq24193_get_version(NULL))
{
bq24193_get_property(BQ24193_InputCurrentLimit, &iinlim); bq24193_get_property(BQ24193_InputCurrentLimit, &iinlim);
s_printf(txt_buf, "\n%d mA\n", iinlim); s_printf(txt_buf, "\n%d mA\n", iinlim);
@@ -2544,13 +2551,19 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn)
s_printf(txt_buf + strlen(txt_buf), "Unknown (%d)", value); s_printf(txt_buf + strlen(txt_buf), "Unknown (%d)", value);
break; break;
} }
}
else
strcpy(txt_buf, "\n#FF8000 "SYMBOL_WARNING" Error!#\n\n\n\n\n");
strcat(txt_buf, "\n\n\n");
// USB-PD IC info. // USB-PD IC info.
if (!bm92t36_get_version(NULL))
{
bool inserted; bool inserted;
u32 wattage = 0; u32 wattage = 0;
usb_pd_objects_t usb_pd; usb_pd_objects_t usb_pd;
bm92t36_get_sink_info(&inserted, &usb_pd); bm92t36_get_sink_info(&inserted, &usb_pd);
strcat(txt_buf, "\n\n\n");
strcat(txt_buf, inserted ? "Connected" : "Disconnected"); strcat(txt_buf, inserted ? "Connected" : "Disconnected");
// Select 5V is no PD contract. // Select 5V is no PD contract.
@@ -2574,6 +2587,9 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn)
usb_pd.pdos[i].amperage, usb_pd.pdos[i].voltage, usb_pd.pdos[i].amperage, usb_pd.pdos[i].voltage,
selected ? "#" : ""); selected ? "#" : "");
} }
}
else
strcat(txt_buf, "#FF8000 "SYMBOL_WARNING" Error!#");
lv_label_set_text(lb_val2, txt_buf); lv_label_set_text(lb_val2, txt_buf);