2020-10-29 10:11:16 +03:00
|
|
|
#include "power.h"
|
2021-04-19 19:26:25 +03:00
|
|
|
#include "power_cli.h"
|
2021-01-08 07:42:48 +03:00
|
|
|
#include "power_views.h"
|
2020-10-29 10:11:16 +03:00
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
#include <furi.h>
|
2021-08-08 21:03:25 +03:00
|
|
|
#include <furi-hal.h>
|
2020-11-11 09:31:35 +03:00
|
|
|
|
|
|
|
#include <menu/menu.h>
|
|
|
|
#include <menu/menu_item.h>
|
2021-01-08 07:42:48 +03:00
|
|
|
|
2020-10-29 10:11:16 +03:00
|
|
|
#include <gui/gui.h>
|
2021-07-07 11:57:49 +03:00
|
|
|
#include <gui/icon_animation.h>
|
2021-01-29 16:52:16 +03:00
|
|
|
#include <gui/view_port.h>
|
2021-01-08 07:42:48 +03:00
|
|
|
#include <gui/view.h>
|
|
|
|
#include <gui/view_dispatcher.h>
|
2021-01-20 19:51:01 +03:00
|
|
|
#include <gui/modules/dialog.h>
|
2020-10-29 10:11:16 +03:00
|
|
|
#include <assets_icons.h>
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
#include <stm32wbxx.h>
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
#include <notification/notification-messages.h>
|
2021-09-10 00:11:32 +03:00
|
|
|
#include <applications/bt/bt_service/bt.h>
|
2021-05-24 16:44:14 +03:00
|
|
|
|
2021-04-19 19:26:25 +03:00
|
|
|
#define POWER_OFF_TIMEOUT 30
|
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
typedef enum {
|
|
|
|
PowerStateNotCharging,
|
|
|
|
PowerStateCharging,
|
|
|
|
PowerStateCharged,
|
|
|
|
} PowerState;
|
|
|
|
|
2020-10-29 10:11:16 +03:00
|
|
|
struct Power {
|
2021-01-08 07:42:48 +03:00
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
|
View* info_view;
|
2021-04-19 19:26:25 +03:00
|
|
|
View* off_view;
|
2021-04-30 07:51:48 +03:00
|
|
|
View* disconnect_view;
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2021-01-29 16:52:16 +03:00
|
|
|
ViewPort* battery_view_port;
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2021-01-20 19:51:01 +03:00
|
|
|
Dialog* dialog;
|
|
|
|
|
2020-11-11 09:31:35 +03:00
|
|
|
ValueMutex* menu_vm;
|
2020-11-16 13:16:34 +03:00
|
|
|
Cli* cli;
|
2021-09-10 00:11:32 +03:00
|
|
|
Bt* bt;
|
2020-11-11 09:31:35 +03:00
|
|
|
MenuItem* menu;
|
2021-05-24 16:44:14 +03:00
|
|
|
|
|
|
|
PowerState state;
|
2020-10-29 10:11:16 +03:00
|
|
|
};
|
|
|
|
|
2020-12-14 13:50:32 +03:00
|
|
|
void power_draw_battery_callback(Canvas* canvas, void* context) {
|
2021-03-31 21:05:00 +03:00
|
|
|
furi_assert(context);
|
2020-10-29 10:11:16 +03:00
|
|
|
Power* power = context;
|
2021-07-07 11:57:49 +03:00
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Battery_26x8);
|
2021-01-08 07:42:48 +03:00
|
|
|
with_view_model(
|
|
|
|
power->info_view, (PowerInfoModel * model) {
|
2021-03-25 20:48:58 +03:00
|
|
|
canvas_draw_box(canvas, 2, 2, (float)model->charge / 100 * 20, 4);
|
2021-02-10 12:06:29 +03:00
|
|
|
return false;
|
2021-01-08 07:42:48 +03:00
|
|
|
});
|
2020-10-29 10:11:16 +03:00
|
|
|
}
|
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
uint32_t power_info_back_callback(void* context) {
|
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
void power_menu_off_callback(void* context) {
|
2021-04-30 07:51:48 +03:00
|
|
|
Power* power = context;
|
|
|
|
power_off(power);
|
2020-11-11 09:31:35 +03:00
|
|
|
}
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2021-01-20 19:51:01 +03:00
|
|
|
void power_menu_reset_dialog_result(DialogResult result, void* context) {
|
2021-04-30 07:51:48 +03:00
|
|
|
Power* power = context;
|
2021-01-20 19:51:01 +03:00
|
|
|
if(result == DialogResultLeft) {
|
2021-07-02 01:53:20 +03:00
|
|
|
power_reboot(power, PowerBootModeDfu);
|
2021-01-20 19:51:01 +03:00
|
|
|
} else if(result == DialogResultRight) {
|
2021-07-02 01:53:20 +03:00
|
|
|
power_reboot(power, PowerBootModeNormal);
|
2021-05-21 12:33:30 +03:00
|
|
|
} else if(result == DialogResultBack) {
|
|
|
|
view_dispatcher_switch_to_view(power->view_dispatcher, VIEW_NONE);
|
2021-01-20 19:51:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
void power_menu_reset_callback(void* context) {
|
2021-01-20 19:51:01 +03:00
|
|
|
Power* power = context;
|
|
|
|
dialog_set_result_callback(power->dialog, power_menu_reset_dialog_result);
|
2021-05-21 12:33:30 +03:00
|
|
|
dialog_set_header_text(power->dialog, "Reboot type");
|
2021-01-20 19:51:01 +03:00
|
|
|
dialog_set_text(power->dialog, "Reboot where?");
|
|
|
|
dialog_set_left_button_text(power->dialog, "DFU");
|
|
|
|
dialog_set_right_button_text(power->dialog, "OS");
|
|
|
|
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewDialog);
|
2020-11-11 09:31:35 +03:00
|
|
|
}
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
void power_menu_enable_otg_callback(void* context) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_enable_otg();
|
2020-10-29 10:11:16 +03:00
|
|
|
}
|
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
void power_menu_disable_otg_callback(void* context) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_disable_otg();
|
2020-12-18 21:03:28 +03:00
|
|
|
}
|
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
void power_menu_info_callback(void* context) {
|
2020-12-18 21:03:28 +03:00
|
|
|
Power* power = context;
|
2021-01-08 07:42:48 +03:00
|
|
|
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewInfo);
|
2020-12-18 21:03:28 +03:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:11:16 +03:00
|
|
|
Power* power_alloc() {
|
|
|
|
Power* power = furi_alloc(sizeof(Power));
|
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
power->state = PowerStateNotCharging;
|
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
power->menu_vm = furi_record_open("menu");
|
2020-11-11 09:31:35 +03:00
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
power->cli = furi_record_open("cli");
|
2021-04-30 07:51:48 +03:00
|
|
|
power_cli_init(power->cli, power);
|
2020-11-16 13:16:34 +03:00
|
|
|
|
2021-09-10 00:11:32 +03:00
|
|
|
power->bt = furi_record_open("bt");
|
|
|
|
|
2021-07-07 11:57:49 +03:00
|
|
|
power->menu = menu_item_alloc_menu("Power", icon_animation_alloc(&A_Power_14));
|
2020-11-11 09:31:35 +03:00
|
|
|
menu_item_subitem_add(
|
2021-01-08 07:42:48 +03:00
|
|
|
power->menu, menu_item_alloc_function("Off", NULL, power_menu_off_callback, power));
|
|
|
|
menu_item_subitem_add(
|
2021-05-21 12:33:30 +03:00
|
|
|
power->menu, menu_item_alloc_function("Reboot", NULL, power_menu_reset_callback, power));
|
2020-11-11 09:31:35 +03:00
|
|
|
menu_item_subitem_add(
|
|
|
|
power->menu,
|
2021-01-08 07:42:48 +03:00
|
|
|
menu_item_alloc_function("Enable OTG", NULL, power_menu_enable_otg_callback, power));
|
2020-11-11 09:31:35 +03:00
|
|
|
menu_item_subitem_add(
|
|
|
|
power->menu,
|
2021-01-08 07:42:48 +03:00
|
|
|
menu_item_alloc_function("Disable OTG", NULL, power_menu_disable_otg_callback, power));
|
2020-12-18 21:03:28 +03:00
|
|
|
menu_item_subitem_add(
|
2021-01-08 07:42:48 +03:00
|
|
|
power->menu, menu_item_alloc_function("Info", NULL, power_menu_info_callback, power));
|
|
|
|
|
|
|
|
power->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
power->info_view = view_alloc();
|
|
|
|
view_allocate_model(power->info_view, ViewModelTypeLockFree, sizeof(PowerInfoModel));
|
|
|
|
view_set_draw_callback(power->info_view, power_info_draw_callback);
|
|
|
|
view_set_previous_callback(power->info_view, power_info_back_callback);
|
|
|
|
view_dispatcher_add_view(power->view_dispatcher, PowerViewInfo, power->info_view);
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2021-04-19 19:26:25 +03:00
|
|
|
power->off_view = view_alloc();
|
|
|
|
view_allocate_model(power->off_view, ViewModelTypeLockFree, sizeof(PowerOffModel));
|
|
|
|
view_set_draw_callback(power->off_view, power_off_draw_callback);
|
|
|
|
view_dispatcher_add_view(power->view_dispatcher, PowerViewOff, power->off_view);
|
|
|
|
|
2021-04-30 07:51:48 +03:00
|
|
|
power->disconnect_view = view_alloc();
|
|
|
|
view_set_draw_callback(power->disconnect_view, power_disconnect_draw_callback);
|
|
|
|
view_dispatcher_add_view(power->view_dispatcher, PowerViewDisconnect, power->disconnect_view);
|
|
|
|
|
2021-01-20 19:51:01 +03:00
|
|
|
power->dialog = dialog_alloc();
|
|
|
|
dialog_set_context(power->dialog, power);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
power->view_dispatcher, PowerViewDialog, dialog_get_view(power->dialog));
|
|
|
|
|
2021-01-29 16:52:16 +03:00
|
|
|
power->battery_view_port = view_port_alloc();
|
2021-03-25 20:48:58 +03:00
|
|
|
|
2021-07-07 11:57:49 +03:00
|
|
|
view_port_set_width(power->battery_view_port, icon_get_width(&I_Battery_26x8));
|
2021-01-29 16:52:16 +03:00
|
|
|
view_port_draw_callback_set(power->battery_view_port, power_draw_battery_callback, power);
|
2020-10-29 10:11:16 +03:00
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_free(Power* power) {
|
2021-03-31 21:05:00 +03:00
|
|
|
furi_assert(power);
|
2020-10-29 10:11:16 +03:00
|
|
|
free(power);
|
|
|
|
}
|
|
|
|
|
2021-04-30 07:51:48 +03:00
|
|
|
void power_off(Power* power) {
|
|
|
|
furi_assert(power);
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_off();
|
2021-04-30 07:51:48 +03:00
|
|
|
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewDisconnect);
|
|
|
|
}
|
|
|
|
|
2021-07-02 01:53:20 +03:00
|
|
|
void power_reboot(Power* power, PowerBootMode mode) {
|
2021-04-30 07:51:48 +03:00
|
|
|
if(mode == PowerBootModeNormal) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_boot_set_mode(FuriHalBootModeNormal);
|
2021-04-30 07:51:48 +03:00
|
|
|
} else if(mode == PowerBootModeDfu) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_boot_set_mode(FuriHalBootModeDFU);
|
2021-04-30 07:51:48 +03:00
|
|
|
}
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_reset();
|
2021-04-30 07:51:48 +03:00
|
|
|
}
|
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
static void power_charging_indication_handler(Power* power, NotificationApp* notifications) {
|
2021-08-08 21:03:25 +03:00
|
|
|
if(furi_hal_power_is_charging()) {
|
|
|
|
if(furi_hal_power_get_pct() == 100) {
|
2021-05-24 16:44:14 +03:00
|
|
|
if(power->state != PowerStateCharged) {
|
|
|
|
notification_internal_message(notifications, &sequence_charged);
|
|
|
|
power->state = PowerStateCharged;
|
|
|
|
}
|
2021-04-27 19:31:34 +03:00
|
|
|
} else {
|
2021-05-24 16:44:14 +03:00
|
|
|
if(power->state != PowerStateCharging) {
|
|
|
|
notification_internal_message(notifications, &sequence_charging);
|
|
|
|
power->state = PowerStateCharging;
|
|
|
|
}
|
2021-04-27 19:31:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
if(!furi_hal_power_is_charging()) {
|
2021-05-24 16:44:14 +03:00
|
|
|
if(power->state != PowerStateNotCharging) {
|
|
|
|
notification_internal_message(notifications, &sequence_not_charging);
|
|
|
|
power->state = PowerStateNotCharging;
|
|
|
|
}
|
2021-04-27 19:31:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-07 19:54:42 +03:00
|
|
|
int32_t power_srv(void* p) {
|
2020-10-29 10:11:16 +03:00
|
|
|
(void)p;
|
|
|
|
Power* power = power_alloc();
|
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
NotificationApp* notifications = furi_record_open("notification");
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
Gui* gui = furi_record_open("gui");
|
2021-01-29 16:52:16 +03:00
|
|
|
gui_add_view_port(gui, power->battery_view_port, GuiLayerStatusBarRight);
|
2021-01-08 07:42:48 +03:00
|
|
|
view_dispatcher_attach_to_gui(power->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
|
2020-10-29 10:11:16 +03:00
|
|
|
|
2020-11-11 09:31:35 +03:00
|
|
|
with_value_mutex(
|
|
|
|
power->menu_vm, (Menu * menu) { menu_item_add(menu, power->menu); });
|
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
furi_record_create("power", power);
|
2021-09-10 00:11:32 +03:00
|
|
|
uint8_t battery_level = 0;
|
|
|
|
uint8_t battery_level_prev = 0;
|
2020-10-29 10:11:16 +03:00
|
|
|
while(1) {
|
2021-04-19 19:26:25 +03:00
|
|
|
bool battery_low = false;
|
|
|
|
|
2021-01-08 07:42:48 +03:00
|
|
|
with_view_model(
|
|
|
|
power->info_view, (PowerInfoModel * model) {
|
2021-08-08 21:03:25 +03:00
|
|
|
model->charge = furi_hal_power_get_pct();
|
2021-09-10 00:11:32 +03:00
|
|
|
battery_level = model->charge;
|
2021-08-08 21:03:25 +03:00
|
|
|
model->health = furi_hal_power_get_bat_health_pct();
|
|
|
|
model->capacity_remaining = furi_hal_power_get_battery_remaining_capacity();
|
|
|
|
model->capacity_full = furi_hal_power_get_battery_full_capacity();
|
|
|
|
model->current_charger = furi_hal_power_get_battery_current(FuriHalPowerICCharger);
|
|
|
|
model->current_gauge = furi_hal_power_get_battery_current(FuriHalPowerICFuelGauge);
|
|
|
|
model->voltage_charger = furi_hal_power_get_battery_voltage(FuriHalPowerICCharger);
|
|
|
|
model->voltage_gauge = furi_hal_power_get_battery_voltage(FuriHalPowerICFuelGauge);
|
|
|
|
model->voltage_vbus = furi_hal_power_get_usb_voltage();
|
2021-01-08 07:42:48 +03:00
|
|
|
model->temperature_charger =
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_get_battery_temperature(FuriHalPowerICCharger);
|
2021-01-08 07:42:48 +03:00
|
|
|
model->temperature_gauge =
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_get_battery_temperature(FuriHalPowerICFuelGauge);
|
2021-03-19 22:37:52 +03:00
|
|
|
|
2021-05-18 17:59:16 +03:00
|
|
|
if(model->charge == 0 && model->voltage_vbus < 4.0f) {
|
2021-04-19 19:26:25 +03:00
|
|
|
battery_low = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
with_view_model(
|
|
|
|
power->off_view, (PowerOffModel * model) {
|
|
|
|
if(battery_low) {
|
|
|
|
if(model->poweroff_tick == 0) {
|
|
|
|
model->poweroff_tick =
|
|
|
|
osKernelGetTickCount() + osKernelGetTickFreq() * POWER_OFF_TIMEOUT;
|
|
|
|
} else {
|
|
|
|
if(osKernelGetTickCount() > model->poweroff_tick) {
|
2021-04-30 07:51:48 +03:00
|
|
|
power_off(power);
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
model->poweroff_tick = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(model->battery_low != battery_low) {
|
|
|
|
model->battery_low = battery_low;
|
|
|
|
view_dispatcher_switch_to_view(
|
|
|
|
power->view_dispatcher, battery_low ? PowerViewOff : VIEW_NONE);
|
|
|
|
}
|
2021-02-10 12:06:29 +03:00
|
|
|
return true;
|
2021-01-08 07:42:48 +03:00
|
|
|
});
|
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
power_charging_indication_handler(power, notifications);
|
2021-04-27 19:31:34 +03:00
|
|
|
|
2021-09-10 00:11:32 +03:00
|
|
|
if(battery_level_prev != battery_level) {
|
|
|
|
battery_level_prev = battery_level;
|
|
|
|
bt_update_battery_level(power->bt, battery_level);
|
|
|
|
}
|
|
|
|
|
2021-01-29 16:52:16 +03:00
|
|
|
view_port_update(power->battery_view_port);
|
2021-04-19 19:26:25 +03:00
|
|
|
|
2021-02-10 12:06:29 +03:00
|
|
|
osDelay(1024);
|
2020-10-29 10:11:16 +03:00
|
|
|
}
|
2021-02-12 20:24:34 +03:00
|
|
|
|
|
|
|
return 0;
|
2020-10-29 10:11:16 +03:00
|
|
|
}
|