[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>
@ -206,10 +206,12 @@ int32_t power_task(void* p) {
|
|||||||
model->current_gauge = api_hal_power_get_battery_current(ApiHalPowerICFuelGauge);
|
model->current_gauge = api_hal_power_get_battery_current(ApiHalPowerICFuelGauge);
|
||||||
model->voltage_charger = api_hal_power_get_battery_voltage(ApiHalPowerICCharger);
|
model->voltage_charger = api_hal_power_get_battery_voltage(ApiHalPowerICCharger);
|
||||||
model->voltage_gauge = api_hal_power_get_battery_voltage(ApiHalPowerICFuelGauge);
|
model->voltage_gauge = api_hal_power_get_battery_voltage(ApiHalPowerICFuelGauge);
|
||||||
|
model->voltage_vbus = api_hal_power_get_usb_voltage();
|
||||||
model->temperature_charger =
|
model->temperature_charger =
|
||||||
api_hal_power_get_battery_temperature(ApiHalPowerICCharger);
|
api_hal_power_get_battery_temperature(ApiHalPowerICCharger);
|
||||||
model->temperature_gauge =
|
model->temperature_gauge =
|
||||||
api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge);
|
api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,43 +1,104 @@
|
|||||||
#include "power_views.h"
|
#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) {
|
void power_info_draw_callback(Canvas* canvas, void* context) {
|
||||||
PowerInfoModel* data = context;
|
PowerInfoModel* data = context;
|
||||||
|
|
||||||
canvas_clear(canvas);
|
canvas_clear(canvas);
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
canvas_set_font(canvas, FontPrimary);
|
draw_battery(canvas, data, 0, 5);
|
||||||
canvas_draw_str(canvas, 2, 10, "Power state:");
|
|
||||||
|
|
||||||
char buffer[64];
|
char batt_level[10];
|
||||||
canvas_set_font(canvas, FontSecondary);
|
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(
|
snprintf(
|
||||||
buffer,
|
voltage,
|
||||||
64,
|
sizeof(voltage),
|
||||||
"Current: %ld/%ldmA",
|
"%ld.%01ld V",
|
||||||
(int32_t)(data->current_gauge * 1000),
|
(uint32_t)data->voltage_gauge,
|
||||||
(int32_t)(data->current_charger * 1000));
|
(uint32_t)(data->voltage_gauge * 10) % 10);
|
||||||
canvas_draw_str(canvas, 5, 22, buffer);
|
snprintf(health, sizeof(health), "%d%s", data->health, "%");
|
||||||
snprintf(
|
|
||||||
buffer,
|
draw_stat(canvas, 8, 42, I_Battery_16x16, batt_level);
|
||||||
64,
|
draw_stat(canvas, 40, 42, I_Temperature_16x16, temperature);
|
||||||
"Voltage: %ld/%ldmV",
|
draw_stat(canvas, 72, 42, I_Voltage_16x16, voltage);
|
||||||
(uint32_t)(data->voltage_gauge * 1000),
|
draw_stat(canvas, 104, 42, I_Health_16x16, health);
|
||||||
(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);
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ typedef struct {
|
|||||||
|
|
||||||
float voltage_charger;
|
float voltage_charger;
|
||||||
float voltage_gauge;
|
float voltage_gauge;
|
||||||
|
float voltage_vbus;
|
||||||
|
|
||||||
uint32_t capacity_remaining;
|
uint32_t capacity_remaining;
|
||||||
uint32_t capacity_full;
|
uint32_t capacity_full;
|
||||||
|
BIN
assets/icons/Power/BatteryBody_52x28.png
Normal file
After Width: | Height: | Size: 327 B |
BIN
assets/icons/Power/Battery_16x16.png
Normal file
After Width: | Height: | Size: 281 B |
BIN
assets/icons/Power/FaceCharging_29x14.png
Normal file
After Width: | Height: | Size: 308 B |
BIN
assets/icons/Power/FaceConfused_29x14.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
assets/icons/Power/FaceNopower_29x14.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
assets/icons/Power/FaceNormal_29x14.png
Normal file
After Width: | Height: | Size: 295 B |
BIN
assets/icons/Power/Health_16x16.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
assets/icons/Power/Temperature_16x16.png
Normal file
After Width: | Height: | Size: 283 B |
BIN
assets/icons/Power/Voltage_16x16.png
Normal file
After Width: | Height: | Size: 294 B |
@ -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) {
|
void api_hal_power_dump_state(string_t buffer) {
|
||||||
BatteryStatus battery_status;
|
BatteryStatus battery_status;
|
||||||
OperationStatus operation_status;
|
OperationStatus operation_status;
|
||||||
|
@ -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) {
|
void api_hal_power_dump_state(string_t buffer) {
|
||||||
BatteryStatus battery_status;
|
BatteryStatus battery_status;
|
||||||
OperationStatus operation_status;
|
OperationStatus operation_status;
|
||||||
|