From 26c4b20ac2b45d85d58b9b00ca8dd11ba5624515 Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Tue, 27 Apr 2021 19:31:34 +0300 Subject: [PATCH] [FL-1184] led indication for charging (#425) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- applications/power/power.c | 45 +++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/applications/power/power.c b/applications/power/power.c index 56536719..35a9488c 100644 --- a/applications/power/power.c +++ b/applications/power/power.c @@ -23,8 +23,8 @@ struct Power { View* info_view; View* off_view; - Icon* usb_icon; - ViewPort* usb_view_port; + // Icon* usb_icon; + // ViewPort* usb_view_port; Icon* battery_icon; ViewPort* battery_view_port; @@ -36,11 +36,11 @@ struct Power { MenuItem* menu; }; -void power_draw_usb_callback(Canvas* canvas, void* context) { - furi_assert(context); - Power* power = context; - canvas_draw_icon(canvas, 0, 0, power->usb_icon); -} +// void power_draw_usb_callback(Canvas* canvas, void* context) { +// furi_assert(context); +// Power* power = context; +// canvas_draw_icon(canvas, 0, 0, power->usb_icon); +// } void power_draw_battery_callback(Canvas* canvas, void* context) { furi_assert(context); @@ -133,10 +133,10 @@ Power* power_alloc() { view_dispatcher_add_view( power->view_dispatcher, PowerViewDialog, dialog_get_view(power->dialog)); - power->usb_icon = assets_icons_get(I_USBConnected_15x8); - power->usb_view_port = view_port_alloc(); - view_port_set_width(power->usb_view_port, icon_get_width(power->usb_icon)); - view_port_draw_callback_set(power->usb_view_port, power_draw_usb_callback, power); + // power->usb_icon = assets_icons_get(I_USBConnected_15x8); + // power->usb_view_port = view_port_alloc(); + // view_port_set_width(power->usb_view_port, icon_get_width(power->usb_icon)); + // view_port_draw_callback_set(power->usb_view_port, power_draw_usb_callback, power); power->battery_icon = assets_icons_get(I_Battery_26x8); power->battery_view_port = view_port_alloc(); @@ -151,12 +151,29 @@ void power_free(Power* power) { free(power); } +static void power_charging_indication_handler() { + if(api_hal_power_is_charging()) { + if(api_hal_power_get_pct() == 100) { + api_hal_light_set(LightRed, 0x00); + api_hal_light_set(LightGreen, 0xFF); + } else { + api_hal_light_set(LightGreen, 0x00); + api_hal_light_set(LightRed, 0xFF); + } + } + + if(!api_hal_power_is_charging()) { + api_hal_light_set(LightRed, 0x00); + api_hal_light_set(LightGreen, 0x00); + } +} + int32_t power_task(void* p) { (void)p; Power* power = power_alloc(); Gui* gui = furi_record_open("gui"); - gui_add_view_port(gui, power->usb_view_port, GuiLayerStatusBarLeft); + //gui_add_view_port(gui, power->usb_view_port, GuiLayerStatusBarLeft); gui_add_view_port(gui, power->battery_view_port, GuiLayerStatusBarRight); view_dispatcher_attach_to_gui(power->view_dispatcher, gui, ViewDispatcherTypeFullscreen); @@ -214,8 +231,10 @@ int32_t power_task(void* p) { return true; }); + power_charging_indication_handler(); + view_port_update(power->battery_view_port); - view_port_enabled_set(power->usb_view_port, api_hal_power_is_charging()); + //view_port_enabled_set(power->usb_view_port, api_hal_power_is_charging()); osDelay(1024); }