[FL-2957] Unified Info API, App Error, Data Xchange (#1998)
* Update protobuf definitions * Add Property subsystem entry point function * Key-based system info and power info function stubs * Remove unneeded functions * Working power info * Working system info * Replace #defines with string literals * Remove unneeded field * Simplify system info formatting * Refactor output callback handling * Handle the last info element correctly * Optimise power info, rename methods * Add comments * Add power debug * Remove unneeded definitions * Rename some files and functions * Update protobuf definitions * Implement App GetError and DataExchange APIs * Send GetErrorReply with correct command_id * Add RPC debug app stub * Add more scenes * Add warning, increase stack size * Add receive data exchange scene * Improve data exchange * Add notifications * Update application requirements * Bump format version for property-based infos * Correctly reset error text * RCP: sync protobuf repo to latest release tag Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -422,76 +422,6 @@ float furi_hal_power_get_usb_voltage() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void furi_hal_power_dump_state() {
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
|
||||
if(bq27220_get_battery_status(&furi_hal_i2c_handle_power, &battery_status) == BQ27220_ERROR ||
|
||||
bq27220_get_operation_status(&furi_hal_i2c_handle_power, &operation_status) ==
|
||||
BQ27220_ERROR) {
|
||||
printf("Failed to get bq27220 status. Communication error.\r\n");
|
||||
} else {
|
||||
// Operation status register
|
||||
printf(
|
||||
"bq27220: CALMD: %d, SEC: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n",
|
||||
operation_status.CALMD,
|
||||
operation_status.SEC,
|
||||
operation_status.EDV2,
|
||||
operation_status.VDQ,
|
||||
operation_status.INITCOMP,
|
||||
operation_status.SMTH,
|
||||
operation_status.BTPINT,
|
||||
operation_status.CFGUPDATE);
|
||||
// Battery status register, part 1
|
||||
printf(
|
||||
"bq27220: CHGINH: %d, FC: %d, OTD: %d, OTC: %d, SLEEP: %d, OCVFAIL: %d, OCVCOMP: %d, FD: %d\r\n",
|
||||
battery_status.CHGINH,
|
||||
battery_status.FC,
|
||||
battery_status.OTD,
|
||||
battery_status.OTC,
|
||||
battery_status.SLEEP,
|
||||
battery_status.OCVFAIL,
|
||||
battery_status.OCVCOMP,
|
||||
battery_status.FD);
|
||||
// Battery status register, part 2
|
||||
printf(
|
||||
"bq27220: DSG: %d, SYSDWN: %d, TDA: %d, BATTPRES: %d, AUTH_GD: %d, OCVGD: %d, TCA: %d, RSVD: %d\r\n",
|
||||
battery_status.DSG,
|
||||
battery_status.SYSDWN,
|
||||
battery_status.TDA,
|
||||
battery_status.BATTPRES,
|
||||
battery_status.AUTH_GD,
|
||||
battery_status.OCVGD,
|
||||
battery_status.TCA,
|
||||
battery_status.RSVD);
|
||||
// Voltage and current info
|
||||
printf(
|
||||
"bq27220: Full capacity: %dmAh, Design capacity: %dmAh, Remaining capacity: %dmAh, State of Charge: %d%%, State of health: %d%%\r\n",
|
||||
bq27220_get_full_charge_capacity(&furi_hal_i2c_handle_power),
|
||||
bq27220_get_design_capacity(&furi_hal_i2c_handle_power),
|
||||
bq27220_get_remaining_capacity(&furi_hal_i2c_handle_power),
|
||||
bq27220_get_state_of_charge(&furi_hal_i2c_handle_power),
|
||||
bq27220_get_state_of_health(&furi_hal_i2c_handle_power));
|
||||
printf(
|
||||
"bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n",
|
||||
bq27220_get_voltage(&furi_hal_i2c_handle_power),
|
||||
bq27220_get_current(&furi_hal_i2c_handle_power),
|
||||
(int)furi_hal_power_get_battery_temperature_internal(FuriHalPowerICFuelGauge));
|
||||
}
|
||||
|
||||
printf(
|
||||
"bq25896: VBUS: %d, VSYS: %d, VBAT: %d, Current: %d, NTC: %ldm%%\r\n",
|
||||
bq25896_get_vbus_voltage(&furi_hal_i2c_handle_power),
|
||||
bq25896_get_vsys_voltage(&furi_hal_i2c_handle_power),
|
||||
bq25896_get_vbat_voltage(&furi_hal_i2c_handle_power),
|
||||
bq25896_get_vbat_current(&furi_hal_i2c_handle_power),
|
||||
bq25896_get_ntc_mpct(&furi_hal_i2c_handle_power));
|
||||
|
||||
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
|
||||
void furi_hal_power_enable_external_3_3v() {
|
||||
furi_hal_gpio_write(&periph_power, 1);
|
||||
}
|
||||
@@ -526,57 +456,227 @@ void furi_hal_power_suppress_charge_exit() {
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_power_info_get(FuriHalPowerInfoCallback out, void* context) {
|
||||
void furi_hal_power_info_get(PropertyValueCallback out, char sep, void* context) {
|
||||
furi_assert(out);
|
||||
|
||||
FuriString* value;
|
||||
value = furi_string_alloc();
|
||||
FuriString* value = furi_string_alloc();
|
||||
FuriString* key = furi_string_alloc();
|
||||
|
||||
// Power Info version
|
||||
out("power_info_major", "1", false, context);
|
||||
out("power_info_minor", "0", false, context);
|
||||
PropertyValueContext property_context = {
|
||||
.key = key, .value = value, .out = out, .sep = sep, .last = false, .context = context};
|
||||
|
||||
if(sep == '.') {
|
||||
property_value_out(&property_context, NULL, 2, "format", "major", "2");
|
||||
property_value_out(&property_context, NULL, 2, "format", "minor", "0");
|
||||
} else {
|
||||
property_value_out(&property_context, NULL, 3, "power", "info", "major", "1");
|
||||
property_value_out(&property_context, NULL, 3, "power", "info", "minor", "0");
|
||||
}
|
||||
|
||||
uint8_t charge = furi_hal_power_get_pct();
|
||||
property_value_out(&property_context, "%u", 2, "charge", "level", charge);
|
||||
|
||||
furi_string_printf(value, "%u", charge);
|
||||
out("charge_level", furi_string_get_cstr(value), false, context);
|
||||
|
||||
const char* charge_state;
|
||||
if(furi_hal_power_is_charging()) {
|
||||
if(charge < 100) {
|
||||
furi_string_printf(value, "charging");
|
||||
charge_state = "charging";
|
||||
} else {
|
||||
furi_string_printf(value, "charged");
|
||||
charge_state = "charged";
|
||||
}
|
||||
} else {
|
||||
furi_string_printf(value, "discharging");
|
||||
charge_state = "discharging";
|
||||
}
|
||||
out("charge_state", furi_string_get_cstr(value), false, context);
|
||||
|
||||
property_value_out(&property_context, NULL, 2, "charge", "state", charge_state);
|
||||
uint16_t voltage =
|
||||
(uint16_t)(furi_hal_power_get_battery_voltage(FuriHalPowerICFuelGauge) * 1000.f);
|
||||
furi_string_printf(value, "%u", voltage);
|
||||
out("battery_voltage", furi_string_get_cstr(value), false, context);
|
||||
|
||||
property_value_out(&property_context, "%u", 2, "battery", "voltage", voltage);
|
||||
int16_t current =
|
||||
(int16_t)(furi_hal_power_get_battery_current(FuriHalPowerICFuelGauge) * 1000.f);
|
||||
furi_string_printf(value, "%d", current);
|
||||
out("battery_current", furi_string_get_cstr(value), false, context);
|
||||
|
||||
property_value_out(&property_context, "%d", 2, "battery", "current", current);
|
||||
int16_t temperature = (int16_t)furi_hal_power_get_battery_temperature(FuriHalPowerICFuelGauge);
|
||||
furi_string_printf(value, "%d", temperature);
|
||||
out("gauge_temp", furi_string_get_cstr(value), false, context);
|
||||
|
||||
furi_string_printf(value, "%u", furi_hal_power_get_bat_health_pct());
|
||||
out("battery_health", furi_string_get_cstr(value), false, context);
|
||||
|
||||
furi_string_printf(value, "%lu", furi_hal_power_get_battery_remaining_capacity());
|
||||
out("capacity_remain", furi_string_get_cstr(value), false, context);
|
||||
|
||||
furi_string_printf(value, "%lu", furi_hal_power_get_battery_full_capacity());
|
||||
out("capacity_full", furi_string_get_cstr(value), false, context);
|
||||
|
||||
furi_string_printf(value, "%lu", furi_hal_power_get_battery_design_capacity());
|
||||
out("capacity_design", furi_string_get_cstr(value), true, context);
|
||||
property_value_out(&property_context, "%d", 2, "battery", "temp", temperature);
|
||||
property_value_out(
|
||||
&property_context, "%u", 2, "battery", "health", furi_hal_power_get_bat_health_pct());
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%lu",
|
||||
2,
|
||||
"capacity",
|
||||
"remain",
|
||||
furi_hal_power_get_battery_remaining_capacity());
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%lu",
|
||||
2,
|
||||
"capacity",
|
||||
"full",
|
||||
furi_hal_power_get_battery_full_capacity());
|
||||
property_context.last = true;
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%lu",
|
||||
2,
|
||||
"capacity",
|
||||
"design",
|
||||
furi_hal_power_get_battery_design_capacity());
|
||||
|
||||
furi_string_free(key);
|
||||
furi_string_free(value);
|
||||
}
|
||||
|
||||
void furi_hal_power_debug_get(PropertyValueCallback out, void* context) {
|
||||
furi_assert(out);
|
||||
|
||||
FuriString* value = furi_string_alloc();
|
||||
FuriString* key = furi_string_alloc();
|
||||
|
||||
PropertyValueContext property_context = {
|
||||
.key = key, .value = value, .out = out, .sep = '.', .last = false, .context = context};
|
||||
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
|
||||
// Power Debug version
|
||||
property_value_out(&property_context, NULL, 2, "format", "major", "1");
|
||||
property_value_out(&property_context, NULL, 2, "format", "minor", "0");
|
||||
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"charger",
|
||||
"vbus",
|
||||
bq25896_get_vbus_voltage(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"charger",
|
||||
"vsys",
|
||||
bq25896_get_vsys_voltage(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"charger",
|
||||
"vbat",
|
||||
bq25896_get_vbat_voltage(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"charger",
|
||||
"current",
|
||||
bq25896_get_vbat_current(&furi_hal_i2c_handle_power));
|
||||
|
||||
const uint32_t ntc_mpct = bq25896_get_ntc_mpct(&furi_hal_i2c_handle_power);
|
||||
|
||||
if(bq27220_get_battery_status(&furi_hal_i2c_handle_power, &battery_status) != BQ27220_ERROR &&
|
||||
bq27220_get_operation_status(&furi_hal_i2c_handle_power, &operation_status) !=
|
||||
BQ27220_ERROR) {
|
||||
property_value_out(&property_context, "%lu", 2, "charger", "ntc", ntc_mpct);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "calmd", operation_status.CALMD);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "sec", operation_status.SEC);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "edv2", operation_status.EDV2);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "vdq", operation_status.VDQ);
|
||||
property_value_out(
|
||||
&property_context, "%d", 2, "gauge", "initcomp", operation_status.INITCOMP);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "smth", operation_status.SMTH);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "btpint", operation_status.BTPINT);
|
||||
property_value_out(
|
||||
&property_context, "%d", 2, "gauge", "cfgupdate", operation_status.CFGUPDATE);
|
||||
|
||||
// Battery status register, part 1
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "chginh", battery_status.CHGINH);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "fc", battery_status.FC);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "otd", battery_status.OTD);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "otc", battery_status.OTC);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "sleep", battery_status.SLEEP);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "ocvfail", battery_status.OCVFAIL);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "ocvcomp", battery_status.OCVCOMP);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "fd", battery_status.FD);
|
||||
|
||||
// Battery status register, part 2
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "dsg", battery_status.DSG);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "sysdwn", battery_status.SYSDWN);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "tda", battery_status.TDA);
|
||||
property_value_out(
|
||||
&property_context, "%d", 2, "gauge", "battpres", battery_status.BATTPRES);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "authgd", battery_status.AUTH_GD);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "ocvgd", battery_status.OCVGD);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "tca", battery_status.TCA);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "rsvd", battery_status.RSVD);
|
||||
|
||||
// Voltage and current info
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
3,
|
||||
"gauge",
|
||||
"capacity",
|
||||
"full",
|
||||
bq27220_get_full_charge_capacity(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
3,
|
||||
"gauge",
|
||||
"capacity",
|
||||
"design",
|
||||
bq27220_get_design_capacity(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
3,
|
||||
"gauge",
|
||||
"capacity",
|
||||
"remain",
|
||||
bq27220_get_remaining_capacity(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
3,
|
||||
"gauge",
|
||||
"state",
|
||||
"charge",
|
||||
bq27220_get_state_of_charge(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
3,
|
||||
"gauge",
|
||||
"state",
|
||||
"health",
|
||||
bq27220_get_state_of_health(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"gauge",
|
||||
"voltage",
|
||||
bq27220_get_voltage(&furi_hal_i2c_handle_power));
|
||||
property_value_out(
|
||||
&property_context,
|
||||
"%d",
|
||||
2,
|
||||
"gauge",
|
||||
"current",
|
||||
bq27220_get_current(&furi_hal_i2c_handle_power));
|
||||
|
||||
property_context.last = true;
|
||||
const int battery_temp =
|
||||
(int)furi_hal_power_get_battery_temperature_internal(FuriHalPowerICFuelGauge);
|
||||
property_value_out(&property_context, "%d", 2, "gauge", "temperature", battery_temp);
|
||||
} else {
|
||||
property_context.last = true;
|
||||
property_value_out(&property_context, "%lu", 2, "charger", "ntc", ntc_mpct);
|
||||
}
|
||||
|
||||
furi_string_free(key);
|
||||
furi_string_free(value);
|
||||
|
||||
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
|
Reference in New Issue
Block a user