[FL-904] Power info UI (#382)

* New power screen UI
* API HAL Power: add VBUS voltage to API

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
its your bedtime 2021-03-19 22:37:52 +03:00 committed by GitHub
parent 4ae5bd3d75
commit b85cc7f788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 105 additions and 33 deletions

View file

@ -206,10 +206,12 @@ int32_t power_task(void* p) {
model->current_gauge = api_hal_power_get_battery_current(ApiHalPowerICFuelGauge);
model->voltage_charger = api_hal_power_get_battery_voltage(ApiHalPowerICCharger);
model->voltage_gauge = api_hal_power_get_battery_voltage(ApiHalPowerICFuelGauge);
model->voltage_vbus = api_hal_power_get_usb_voltage();
model->temperature_charger =
api_hal_power_get_battery_temperature(ApiHalPowerICCharger);
model->temperature_gauge =
api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge);
return true;
});

View file

@ -1,43 +1,104 @@
#include "power_views.h"
static void draw_stat(Canvas* canvas, int x, int y, IconName icon, char* val) {
canvas_draw_frame(canvas, x - 7, y + 7, 30, 13);
canvas_draw_icon_name(canvas, x, y, icon);
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x - 4, y + 16, 24, 6);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, x + 8, y + 22, AlignCenter, AlignBottom, val);
};
static void draw_battery(Canvas* canvas, PowerInfoModel* data, int x, int y) {
char emote[20];
char header[20];
char value[20];
int32_t drain_current = -data->current_gauge * 1000;
uint32_t charge_current = data->current_gauge * 1000;
// battery
canvas_draw_icon_name(canvas, x, y, I_BatteryBody_52x28);
if(charge_current > 0) {
canvas_draw_icon_name(canvas, x + 16, y + 7, I_FaceCharging_29x14);
} else if(drain_current > 100) {
canvas_draw_icon_name(canvas, x + 16, y + 7, I_FaceConfused_29x14);
} else if(data->charge < 10) {
canvas_draw_icon_name(canvas, x + 16, y + 7, I_FaceNopower_29x14);
} else {
canvas_draw_icon_name(canvas, x + 16, y + 7, I_FaceNormal_29x14);
}
//bubble
canvas_draw_frame(canvas, 57, 0, 71, 39);
canvas_draw_line(canvas, 53, 23, 57, 19);
canvas_draw_line(canvas, 53, 23, 57, 27);
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, 57, 0, 2, 2);
canvas_draw_box(canvas, 57, 37, 2, 2);
canvas_draw_box(canvas, 126, 0, 2, 2);
canvas_draw_box(canvas, 126, 37, 2, 2);
canvas_draw_line(canvas, 57, 20, 57, 26);
canvas_set_color(canvas, ColorBlack);
canvas_draw_dot(canvas, 58, 1);
canvas_draw_dot(canvas, 58, 37);
canvas_draw_dot(canvas, 126, 1);
canvas_draw_dot(canvas, 126, 37);
// text
if(charge_current > 0) {
snprintf(emote, sizeof(emote), "%s", "Yummy!");
snprintf(header, sizeof(header), "%s", "Charging at");
snprintf(
value,
sizeof(value),
"%ld.%ldV %ldmA",
(uint32_t)(data->voltage_vbus),
(uint32_t)(data->voltage_vbus * 10) % 10,
charge_current);
} else if(drain_current > 0) {
snprintf(emote, sizeof(emote), "%s", drain_current > 100 ? "Oh no!" : "Om-nom-nom!");
snprintf(header, sizeof(header), "%s", "Consumption is");
snprintf(
value, sizeof(value), "%ld %s", drain_current, drain_current > 100 ? "mA!" : "mA");
} else if(charge_current != 0 || drain_current != 0) {
snprintf(header, 20, "%s", "...");
memset(value, 0, sizeof(value));
memset(emote, 0, sizeof(emote));
} else {
snprintf(header, sizeof(header), "%s", "Charged!");
memset(value, 0, sizeof(value));
memset(emote, 0, sizeof(emote));
}
canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote);
canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header);
canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value);
};
void power_info_draw_callback(Canvas* canvas, void* context) {
PowerInfoModel* data = context;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 10, "Power state:");
draw_battery(canvas, data, 0, 5);
char buffer[64];
canvas_set_font(canvas, FontSecondary);
char batt_level[10];
char temperature[10];
char voltage[10];
char health[10];
snprintf(batt_level, sizeof(batt_level), "%ld%s", (uint32_t)data->charge, "%");
snprintf(temperature, sizeof(temperature), "%ld %s", (uint32_t)data->temperature_gauge, "C");
snprintf(
buffer,
64,
"Current: %ld/%ldmA",
(int32_t)(data->current_gauge * 1000),
(int32_t)(data->current_charger * 1000));
canvas_draw_str(canvas, 5, 22, buffer);
snprintf(
buffer,
64,
"Voltage: %ld/%ldmV",
(uint32_t)(data->voltage_gauge * 1000),
(uint32_t)(data->voltage_charger * 1000));
canvas_draw_str(canvas, 5, 32, buffer);
snprintf(
buffer,
64,
"Charge: %ld%% Health: %ld%%",
(uint32_t)(data->charge),
(uint32_t)(data->health));
canvas_draw_str(canvas, 5, 42, buffer);
snprintf(buffer, 64, "Capacity: %ld of %ldmAh", data->capacity_remaining, data->capacity_full);
canvas_draw_str(canvas, 5, 52, buffer);
snprintf(
buffer,
64,
"Temperature: %ld/%ldC",
(uint32_t)(data->temperature_gauge),
(uint32_t)(data->temperature_charger));
canvas_draw_str(canvas, 5, 62, buffer);
voltage,
sizeof(voltage),
"%ld.%01ld V",
(uint32_t)data->voltage_gauge,
(uint32_t)(data->voltage_gauge * 10) % 10);
snprintf(health, sizeof(health), "%d%s", data->health, "%");
draw_stat(canvas, 8, 42, I_Battery_16x16, batt_level);
draw_stat(canvas, 40, 42, I_Temperature_16x16, temperature);
draw_stat(canvas, 72, 42, I_Voltage_16x16, voltage);
draw_stat(canvas, 104, 42, I_Health_16x16, health);
}

View file

@ -14,6 +14,7 @@ typedef struct {
float voltage_charger;
float voltage_gauge;
float voltage_vbus;
uint32_t capacity_remaining;
uint32_t capacity_full;

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

View file

@ -162,6 +162,10 @@ float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
}
float api_hal_power_get_usb_voltage(){
return (float)bq25896_get_vbus_voltage() / 1000.0f;
}
void api_hal_power_dump_state(string_t buffer) {
BatteryStatus battery_status;
OperationStatus operation_status;

View file

@ -163,6 +163,10 @@ float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
}
float api_hal_power_get_usb_voltage(){
return (float)bq25896_get_vbus_voltage() / 1000.0f;;
}
void api_hal_power_dump_state(string_t buffer) {
BatteryStatus battery_status;
OperationStatus operation_status;