From b85cc7f78837b0aad83048d1390068817d2ecd72 Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Fri, 19 Mar 2021 22:37:52 +0300 Subject: [PATCH] [FL-904] Power info UI (#382) * New power screen UI * API HAL Power: add VBUS voltage to API Co-authored-by: Aleksandr Kutuzov --- applications/power/power.c | 2 + applications/power/power_views.c | 127 +++++++++++++++----- applications/power/power_views.h | 1 + assets/icons/Power/BatteryBody_52x28.png | Bin 0 -> 327 bytes assets/icons/Power/Battery_16x16.png | Bin 0 -> 281 bytes assets/icons/Power/FaceCharging_29x14.png | Bin 0 -> 308 bytes assets/icons/Power/FaceConfused_29x14.png | Bin 0 -> 317 bytes assets/icons/Power/FaceNopower_29x14.png | Bin 0 -> 302 bytes assets/icons/Power/FaceNormal_29x14.png | Bin 0 -> 295 bytes assets/icons/Power/Health_16x16.png | Bin 0 -> 282 bytes assets/icons/Power/Temperature_16x16.png | Bin 0 -> 283 bytes assets/icons/Power/Voltage_16x16.png | Bin 0 -> 294 bytes firmware/targets/f4/api-hal/api-hal-power.c | 4 + firmware/targets/f5/api-hal/api-hal-power.c | 4 + 14 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 assets/icons/Power/BatteryBody_52x28.png create mode 100644 assets/icons/Power/Battery_16x16.png create mode 100644 assets/icons/Power/FaceCharging_29x14.png create mode 100644 assets/icons/Power/FaceConfused_29x14.png create mode 100644 assets/icons/Power/FaceNopower_29x14.png create mode 100644 assets/icons/Power/FaceNormal_29x14.png create mode 100644 assets/icons/Power/Health_16x16.png create mode 100644 assets/icons/Power/Temperature_16x16.png create mode 100644 assets/icons/Power/Voltage_16x16.png diff --git a/applications/power/power.c b/applications/power/power.c index 4480f6b1..e8b58049 100644 --- a/applications/power/power.c +++ b/applications/power/power.c @@ -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; }); diff --git a/applications/power/power_views.c b/applications/power/power_views.c index f48fa454..382abaee 100644 --- a/applications/power/power_views.c +++ b/applications/power/power_views.c @@ -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); } diff --git a/applications/power/power_views.h b/applications/power/power_views.h index db2ac308..044f7308 100644 --- a/applications/power/power_views.h +++ b/applications/power/power_views.h @@ -14,6 +14,7 @@ typedef struct { float voltage_charger; float voltage_gauge; + float voltage_vbus; uint32_t capacity_remaining; uint32_t capacity_full; diff --git a/assets/icons/Power/BatteryBody_52x28.png b/assets/icons/Power/BatteryBody_52x28.png new file mode 100644 index 0000000000000000000000000000000000000000..1fe56834610cb41c959a49f8fc0984829f8e20e0 GIT binary patch literal 327 zcmeAS@N?(olHy`uVBq!ia0vp^CO|C12qYNT{w$OQQY`6?zK#qG8~eHcB(ehe3dtTp zz6=aiY77hwEes65fItZejeiaPg*{{Si_^q49 z(b-ZJ2{c-@#5JNMC9x#cD!C{XNHG{07#Zps80#8Zgcw*@85>y{8)_RESQ!{B-o0}o eiiX_$l+3hB+!`)DW7Gv|VDNPHb6Mw<&;$UHx?2bU literal 0 HcmV?d00001 diff --git a/assets/icons/Power/Battery_16x16.png b/assets/icons/Power/Battery_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..49af3c2259a086ca262876e062c1ef2cdc99c285 GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZEE?e4qb@eTvkfNuHV+hCfRdP`(kYX@0Ff!CNFxEA+2r;m*GB&g_G0`?Kure?Z hC{)ow(U6;;l9^VCTSKDGoC!b;44$rjF6*2UngG10Ol|-G literal 0 HcmV?d00001 diff --git a/assets/icons/Power/FaceCharging_29x14.png b/assets/icons/Power/FaceCharging_29x14.png new file mode 100644 index 0000000000000000000000000000000000000000..106ededbf9d37edd55bf106e4beb8be91b163950 GIT binary patch literal 308 zcmeAS@N?(olHy`uVBq!ia0vp^vOvto2qYMOuhNNn{1`6_P!I zd>I(3)EF2VS{N990fib~Fff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9f$?sa@Dd=8 zy~NYkmHjER5QmD8^?DX&ppcEHi(?4K_2eJF|NrM}oB#iRv_Z|k|LdC`{`_xmFTwZc zzapdJ1(kdM|Nm}&`2YWZhe!Wv6+YJ4Pxuk=pP6A|jKLX&Vi_Z#IjSYD5hW>!C8<`) zMX5lF!N|bKP}jg%*U%!wz{1Md*vi;a+rYrez@UEGoD(P-a`RI%(<*Um;5)5S0@T3Z M>FVdQ&MBb@0ME-_z5oCK literal 0 HcmV?d00001 diff --git a/assets/icons/Power/FaceConfused_29x14.png b/assets/icons/Power/FaceConfused_29x14.png new file mode 100644 index 0000000000000000000000000000000000000000..dcd2e3c6736144ddc292178f4d7fae7fcc962f30 GIT binary patch literal 317 zcmeAS@N?(olHy`uVBq!ia0vp^vOvto2qYMOuhNNn{1`6_P!I zd>I(3)EF2VS{N990fib~Fff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9f$?sa@Dd=8 zy~NYkmHjER5QmDqt6arCppdJli(?4K_2eJl|I4!3*zvvWJ#Sn4_SZTR|Nj5~&+H}hfL)09jl-hRdP`(kYX@0Ff!CNFxEA+2r;m*GB&X?G|)CMure_4`hHX%MMG|WN@iLm WZVlF}Y8L}FFnGH9xvXNn{1`6_P!I zd>I(3)EF2VS{N990fib~Fff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9f$?sa@Dd=8 zy~NYkmHjER5QmC(%Bmi2ppcoTi(?4K_2eJ_|NrN2v;SZ3)G7bJ{!c>2pa1R63xEE% z=VRNT(^8SZuX64@yAbamgGKx0mADzU|I)V!JIr|=Xo6~qYeY#(Vo9o1a#1RfVlXl= zGSoFN)-|*UF|e>QHnB1>&^9ozGB98gKV6NYAvZrIGp!Q0hGMVc<3J4zp00i_>zopr E04(EH4gdfE literal 0 HcmV?d00001 diff --git a/assets/icons/Power/FaceNormal_29x14.png b/assets/icons/Power/FaceNormal_29x14.png new file mode 100644 index 0000000000000000000000000000000000000000..52d78c08698f3cb1c70d1b39d44f950664c1b6c6 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^vOvto2qYMOuhNNn{1`6_P!I zd>I(3)EF2VS{N990fib~Fff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9f$?sa@Dd=8 zy~NYkmHjER5QhrG39(Xdppd?&i(?4K_2eJ_|NrN2JN*B@r@@wg{}&&;@Z&!}yAb0v z2JJ?H_um%_+<)D8r2oG?!(RbCK3(x2*+8wTC9V-ADTyViR>?)FK#IZ0z{pV7z*yJN yBE-PL%GlJ(#8lhBz{nC}Q!>*kacelY!8{JAfx*+&&t;ucLK6VES60IS literal 0 HcmV?d00001 diff --git a/assets/icons/Power/Health_16x16.png b/assets/icons/Power/Health_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..af343c520587f373d41b35cdf8c9b50345fc0286 GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZEE?e4$;h+E8 zGgR!7ntpGea5+%5YKdz^NlIc#s#S7PDv)9@GB7gKH89pSv!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZEE?e4jS1oakC`m~yNwrEYN(E93Mg~TPx(3F&h87_P7FNcFRz_yp1_o9J j29Aw3O(+_2^HVa@DsgKtxYJ?>)WG2B>gTe~DWM4fXX{Nq literal 0 HcmV?d00001 diff --git a/assets/icons/Power/Voltage_16x16.png b/assets/icons/Power/Voltage_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..94e79687295fe8af81fa8984083c9ed9c40627ae GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx?BpA#)4xIr~Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZEE?e4Vure^!HUN?acl*3zP&DM`r(~v8;?}U{@}~zt4Gf;HelF{r5}E)Ni&owM literal 0 HcmV?d00001 diff --git a/firmware/targets/f4/api-hal/api-hal-power.c b/firmware/targets/f4/api-hal/api-hal-power.c index 5d682cc5..44222246 100644 --- a/firmware/targets/f4/api-hal/api-hal-power.c +++ b/firmware/targets/f4/api-hal/api-hal-power.c @@ -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; diff --git a/firmware/targets/f5/api-hal/api-hal-power.c b/firmware/targets/f5/api-hal/api-hal-power.c index 12f79fa4..d5c46a49 100644 --- a/firmware/targets/f5/api-hal/api-hal-power.c +++ b/firmware/targets/f5/api-hal/api-hal-power.c @@ -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;