1313#include "scenes/desktop_scene.h"
1414#include "scenes/desktop_scene_locked.h"
1515
16+ #include "furi_hal_power.h"
17+
1618#define TAG "Desktop"
1719
20+ // dublicate constants from desktop_setting_scene_start.c
21+ #define USB_INHIBIT_AUTOLOCK_OFF 0
22+ #define USB_INHIBIT_AUTOLOCK_ON 1
23+ #define USB_INHIBIT_AUTOLOCK_RPC 2
24+
1825static void desktop_auto_lock_arm (Desktop * );
1926static void desktop_auto_lock_inhibit (Desktop * );
2027static void desktop_start_auto_lock_timer (Desktop * );
2128static void desktop_apply_settings (Desktop * );
22- //--- auto_power_off_timer
23- #include <power/power_service/power.h>
24- static void desktop_start_auto_poweroff_timer (Desktop * );
25- static void desktop_auto_poweroff_arm (Desktop * );
26- static void desktop_auto_poweroff_inhibit (Desktop * );
27- //---
2829
2930static void desktop_loader_callback (const void * message , void * context ) {
3031 furi_assert (context );
@@ -137,30 +138,28 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
137138 }
138139
139140 desktop_auto_lock_inhibit (desktop );
140- //--- auto_power_off_timer
141- desktop_auto_poweroff_inhibit (desktop );
142- //--
141+
143142 desktop -> app_running = true;
144143
145144 furi_semaphore_release (desktop -> animation_semaphore );
146145
147146 } else if (event == DesktopGlobalAfterAppFinished ) {
148147 animation_manager_load_and_continue_animation (desktop -> animation_manager );
149148 desktop_auto_lock_arm (desktop );
150- //--- auto_power_off_timer
151- desktop_auto_poweroff_arm (desktop );
152- //---
153149 desktop -> app_running = false;
154150
155151 } else if (event == DesktopGlobalAutoLock ) {
156152 if (!desktop -> app_running && !desktop -> locked ) {
153+ // if usb_inhibit_autolock enabled and device charging or device charged but still connected to USB then break desktop locking.
154+ if ((desktop -> settings .usb_inhibit_auto_lock == USB_INHIBIT_AUTOLOCK_ON ) && ((furi_hal_power_is_charging ()) || (furi_hal_power_is_charging_done ()))){
155+ return (0 );
156+ }
157+ // if usb_inhibit_autolock set to RPC and we have F0 connected to phone or PC app then break desktop locking.
158+ if (desktop -> settings .usb_inhibit_auto_lock == USB_INHIBIT_AUTOLOCK_RPC ){
159+ return (0 );
160+ }
157161 desktop_lock (desktop );
158162 }
159- } else if (event == DesktopGlobalAutoPowerOff ) {
160- if (!desktop -> app_running ) {
161- Power * power = furi_record_open (RECORD_POWER );
162- power_off (power );
163- }
164163 } else if (event == DesktopGlobalSaveSettings ) {
165164 desktop_settings_save (& desktop -> settings );
166165 desktop_apply_settings (desktop );
@@ -195,9 +194,6 @@ static void desktop_input_event_callback(const void* value, void* context) {
195194 Desktop * desktop = context ;
196195 if (event -> type == InputTypePress ) {
197196 desktop_start_auto_lock_timer (desktop );
198- //--- auto_power_off_timer
199- desktop_start_auto_poweroff_timer (desktop );
200- //---
201197 }
202198}
203199
@@ -234,41 +230,6 @@ static void desktop_auto_lock_inhibit(Desktop* desktop) {
234230 }
235231}
236232
237- //--- auto_power_off_timer
238- static void desktop_auto_poweroff_timer_callback (void * context ) {
239- furi_assert (context );
240- Desktop * desktop = context ;
241- view_dispatcher_send_custom_event (desktop -> view_dispatcher , DesktopGlobalAutoPowerOff );
242- }
243-
244- static void desktop_start_auto_poweroff_timer (Desktop * desktop ) {
245- furi_timer_start (
246- desktop -> auto_poweroff_timer , furi_ms_to_ticks (desktop -> settings .auto_poweroff_delay_ms ));
247- }
248-
249- static void desktop_stop_auto_poweroff_timer (Desktop * desktop ) {
250- furi_timer_stop (desktop -> auto_poweroff_timer );
251- }
252-
253- static void desktop_auto_poweroff_arm (Desktop * desktop ) {
254- if (desktop -> settings .auto_poweroff_delay_ms ) {
255- if (!desktop -> input_events_subscription ) {
256- desktop -> input_events_subscription = furi_pubsub_subscribe (
257- desktop -> input_events_pubsub , desktop_input_event_callback , desktop );
258- }
259- desktop_start_auto_poweroff_timer (desktop );
260- }
261- }
262-
263- static void desktop_auto_poweroff_inhibit (Desktop * desktop ) {
264- desktop_stop_auto_poweroff_timer (desktop );
265- if (desktop -> input_events_subscription ) {
266- furi_pubsub_unsubscribe (desktop -> input_events_pubsub , desktop -> input_events_subscription );
267- desktop -> input_events_subscription = NULL ;
268- }
269- }
270- //---
271-
272233static void desktop_clock_timer_callback (void * context ) {
273234 furi_assert (context );
274235 Desktop * desktop = context ;
@@ -294,9 +255,6 @@ static void desktop_apply_settings(Desktop* desktop) {
294255
295256 if (!desktop -> app_running && !desktop -> locked ) {
296257 desktop_auto_lock_arm (desktop );
297- //--- auto_power_off_timer
298- desktop_auto_poweroff_arm (desktop );
299- //---
300258 }
301259
302260 desktop -> in_transition = false;
@@ -432,10 +390,6 @@ static Desktop* desktop_alloc(void) {
432390
433391 desktop -> auto_lock_timer =
434392 furi_timer_alloc (desktop_auto_lock_timer_callback , FuriTimerTypeOnce , desktop );
435- //--- auto_power_off_timer
436- desktop -> auto_poweroff_timer =
437- furi_timer_alloc (desktop_auto_poweroff_timer_callback , FuriTimerTypeOnce , desktop );
438- //---
439393
440394 desktop -> status_pubsub = furi_pubsub_alloc ();
441395
0 commit comments