Power: info (#272)
This commit is contained in:
parent
dde163fa61
commit
153d32bf15
@ -17,10 +17,16 @@ struct Power {
|
||||
Icon* battery_icon;
|
||||
Widget* battery_widget;
|
||||
|
||||
Widget* widget;
|
||||
|
||||
ValueMutex* menu_vm;
|
||||
Cli* cli;
|
||||
MenuItem* menu;
|
||||
|
||||
float current;
|
||||
float voltage;
|
||||
float temperature;
|
||||
|
||||
uint8_t charge;
|
||||
};
|
||||
|
||||
@ -50,6 +56,39 @@ void power_disable_otg_callback(void* context) {
|
||||
api_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
void power_info_callback(void* context) {
|
||||
Power* power = context;
|
||||
widget_enabled_set(power->widget, true);
|
||||
}
|
||||
|
||||
void power_draw_callback(Canvas* canvas, void* context) {
|
||||
Power* power = context;
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 10, "Power state:");
|
||||
|
||||
char buffer[64];
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
snprintf(buffer, 64, "Current: %ldmA", (int32_t)(power->current * 1000));
|
||||
canvas_draw_str(canvas, 5, 22, buffer);
|
||||
snprintf(buffer, 64, "Voltage: %ldmV", (uint32_t)(power->voltage * 1000));
|
||||
canvas_draw_str(canvas, 5, 32, buffer);
|
||||
snprintf(buffer, 64, "Charge: %ld%%", (uint32_t)(power->charge));
|
||||
canvas_draw_str(canvas, 5, 42, buffer);
|
||||
snprintf(buffer, 64, "Temperature: %ldC", (uint32_t)(power->temperature));
|
||||
canvas_draw_str(canvas, 5, 52, buffer);
|
||||
}
|
||||
|
||||
void power_input_callback(InputEvent* event, void* context) {
|
||||
Power* power = context;
|
||||
|
||||
if(!event->state) return;
|
||||
|
||||
widget_enabled_set(power->widget, false);
|
||||
}
|
||||
|
||||
Power* power_alloc() {
|
||||
Power* power = furi_alloc(sizeof(Power));
|
||||
|
||||
@ -67,12 +106,19 @@ Power* power_alloc() {
|
||||
menu_item_subitem_add(
|
||||
power->menu,
|
||||
menu_item_alloc_function("Disable OTG", NULL, power_disable_otg_callback, power));
|
||||
menu_item_subitem_add(
|
||||
power->menu, menu_item_alloc_function("Info", NULL, power_info_callback, power));
|
||||
|
||||
power->usb_icon = assets_icons_get(I_USBConnected_15x8);
|
||||
power->usb_widget = widget_alloc();
|
||||
widget_set_width(power->usb_widget, icon_get_width(power->usb_icon));
|
||||
widget_draw_callback_set(power->usb_widget, power_draw_usb_callback, power);
|
||||
|
||||
power->widget = widget_alloc();
|
||||
widget_draw_callback_set(power->widget, power_draw_callback, power);
|
||||
widget_input_callback_set(power->widget, power_input_callback, power);
|
||||
widget_enabled_set(power->widget, false);
|
||||
|
||||
power->battery_icon = assets_icons_get(I_Battery_19x8);
|
||||
power->battery_widget = widget_alloc();
|
||||
widget_set_width(power->battery_widget, icon_get_width(power->battery_icon));
|
||||
@ -135,6 +181,7 @@ void power_task(void* p) {
|
||||
}
|
||||
|
||||
Gui* gui = furi_open("gui");
|
||||
gui_add_widget(gui, power->widget, GuiLayerFullscreen);
|
||||
gui_add_widget(gui, power->usb_widget, GuiLayerStatusBarLeft);
|
||||
gui_add_widget(gui, power->battery_widget, GuiLayerStatusBarRight);
|
||||
|
||||
@ -152,6 +199,10 @@ void power_task(void* p) {
|
||||
|
||||
while(1) {
|
||||
power->charge = api_hal_power_get_pct();
|
||||
power->current = api_hal_power_get_battery_current();
|
||||
power->voltage = api_hal_power_get_battery_voltage();
|
||||
power->temperature = api_hal_power_get_battery_temperature();
|
||||
widget_update(power->widget);
|
||||
widget_enabled_set(power->usb_widget, api_hal_power_is_charging());
|
||||
osDelay(1000);
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ float api_hal_power_get_battery_voltage();
|
||||
/* Get battery current in A */
|
||||
float api_hal_power_get_battery_current();
|
||||
|
||||
/* Get temperature in C */
|
||||
float api_hal_power_get_battery_temperature();
|
||||
|
||||
/* Get power system component state */
|
||||
void api_hal_power_dump_state(string_t buffer);
|
||||
|
||||
|
@ -42,6 +42,10 @@ float api_hal_power_get_battery_current() {
|
||||
return (float)bq27220_get_current() / 1000.0f;
|
||||
}
|
||||
|
||||
float api_hal_power_get_battery_temperature() {
|
||||
return ((float)bq27220_get_temperature() - 2731.0f) / 10.0f;
|
||||
}
|
||||
|
||||
void api_hal_power_dump_state(string_t buffer) {
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
@ -77,7 +81,7 @@ void api_hal_power_dump_state(string_t buffer) {
|
||||
);
|
||||
string_cat_printf(buffer,
|
||||
"bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n",
|
||||
bq27220_get_voltage(), bq27220_get_current(), (bq27220_get_temperature() - 2731)/10
|
||||
bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature()
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user