Skip to content

Commit b4c7cde

Browse files
authored
Merge pull request #857 from Dmitry422/dev
Auto_poweroff_timer moved to power service. Power service have own config file.
2 parents f054d05 + cf50875 commit b4c7cde

File tree

16 files changed

+431
-138
lines changed

16 files changed

+431
-138
lines changed

applications/services/desktop/desktop.c

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
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+
1825
static void desktop_auto_lock_arm(Desktop*);
1926
static void desktop_auto_lock_inhibit(Desktop*);
2027
static void desktop_start_auto_lock_timer(Desktop*);
2128
static 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

2930
static 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-
272233
static 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

applications/services/desktop/desktop_i.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ struct Desktop {
7575

7676
FuriTimer* auto_lock_timer;
7777
FuriTimer* update_clock_timer;
78-
//--- auto_power_off_timer
79-
FuriTimer* auto_poweroff_timer;
80-
//---
8178

8279
AnimationManager* animation_manager;
8380
FuriSemaphore* animation_semaphore;

applications/services/desktop/desktop_settings.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
#define TAG "DesktopSettings"
88

9-
#define DESKTOP_SETTINGS_VER_14 (14)
10-
#define DESKTOP_SETTINGS_VER (15)
9+
#define DESKTOP_SETTINGS_VER_15 (15)
10+
#define DESKTOP_SETTINGS_VER (16)
1111

1212
#define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME)
1313
#define DESKTOP_SETTINGS_MAGIC (0x17)
1414

1515
typedef struct {
1616
uint32_t auto_lock_delay_ms;
17+
uint32_t auto_poweroff_delay_ms;
1718
uint8_t displayBatteryPercentage;
1819
uint8_t dummy_mode;
1920
uint8_t display_clock;
2021
FavoriteApp favorite_apps[FavoriteAppNumber];
2122
FavoriteApp dummy_apps[DummyAppNumber];
22-
} DesktopSettingsV14;
23+
} DesktopSettingsV15;
2324

2425
// Actual size of DesktopSettings v13
2526
//static_assert(sizeof(DesktopSettingsV13) == 1234);
@@ -41,31 +42,31 @@ void desktop_settings_load(DesktopSettings* settings) {
4142
DESKTOP_SETTINGS_MAGIC,
4243
DESKTOP_SETTINGS_VER);
4344

44-
} else if(version == DESKTOP_SETTINGS_VER_14) {
45-
DesktopSettingsV14* settings_v14 = malloc(sizeof(DesktopSettingsV14));
45+
} else if(version == DESKTOP_SETTINGS_VER_15) {
46+
DesktopSettingsV15* settings_v15 = malloc(sizeof(DesktopSettingsV15));
4647

4748
success = saved_struct_load(
4849
DESKTOP_SETTINGS_PATH,
49-
settings_v14,
50-
sizeof(DesktopSettingsV14),
50+
settings_v15,
51+
sizeof(DesktopSettingsV15),
5152
DESKTOP_SETTINGS_MAGIC,
52-
DESKTOP_SETTINGS_VER_14);
53+
DESKTOP_SETTINGS_VER_15);
5354

5455
if(success) {
55-
settings->auto_lock_delay_ms = settings_v14->auto_lock_delay_ms;
56-
settings->auto_poweroff_delay_ms = 0;
57-
settings->displayBatteryPercentage = settings_v14->displayBatteryPercentage;
58-
settings->dummy_mode = settings_v14->dummy_mode;
59-
settings->display_clock = settings_v14->display_clock;
56+
settings->auto_lock_delay_ms = settings_v15->auto_lock_delay_ms;
57+
settings->usb_inhibit_auto_lock = 0;
58+
settings->displayBatteryPercentage = settings_v15->displayBatteryPercentage;
59+
settings->dummy_mode = settings_v15->dummy_mode;
60+
settings->display_clock = settings_v15->display_clock;
6061
memcpy(
6162
settings->favorite_apps,
62-
settings_v14->favorite_apps,
63+
settings_v15->favorite_apps,
6364
sizeof(settings->favorite_apps));
6465
memcpy(
65-
settings->dummy_apps, settings_v14->dummy_apps, sizeof(settings->dummy_apps));
66+
settings->dummy_apps, settings_v15->dummy_apps, sizeof(settings->dummy_apps));
6667
}
6768

68-
free(settings_v14);
69+
free(settings_v15);
6970
}
7071

7172
} while(false);

applications/services/desktop/desktop_settings.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ typedef struct {
3838

3939
typedef struct {
4040
uint32_t auto_lock_delay_ms;
41-
//--- auto_power_off_timer
42-
uint32_t auto_poweroff_delay_ms;
43-
//---
41+
uint8_t usb_inhibit_auto_lock;
4442
uint8_t displayBatteryPercentage;
4543
uint8_t dummy_mode;
4644
uint8_t display_clock;

applications/services/desktop/views/desktop_events.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@ typedef enum {
6262
DesktopGlobalApiUnlock,
6363
DesktopGlobalSaveSettings,
6464
DesktopGlobalReloadSettings,
65-
DesktopGlobalAutoPowerOff,
6665
} DesktopEvent;

0 commit comments

Comments
 (0)