Skip to content

Commit fbcf39a

Browse files
authored
Merge pull request #860 from Dmitry422/dev
Auto_power_off and Auto_lock improvements
2 parents 633f5d7 + e809e3d commit fbcf39a

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

applications/services/desktop/desktop.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
#define TAG "Desktop"
1919

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-
2520
static void desktop_auto_lock_arm(Desktop*);
2621
static void desktop_auto_lock_inhibit(Desktop*);
2722
static void desktop_start_auto_lock_timer(Desktop*);
@@ -150,15 +145,11 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
150145

151146
} else if(event == DesktopGlobalAutoLock) {
152147
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) &&
155-
((furi_hal_power_is_charging()) || (furi_hal_power_is_charging_done()))) {
156-
return (0);
157-
}
158-
// if usb_inhibit_autolock set to RPC and we have F0 connected to phone or PC app then break desktop locking.
159-
if(desktop->settings.usb_inhibit_auto_lock == USB_INHIBIT_AUTOLOCK_RPC) {
148+
// Disable AutoLock if usb_inhibit_autolock option enabled and device have active USB session.
149+
if((desktop->settings.usb_inhibit_auto_lock) && (furi_hal_usb_is_locked())) {
160150
return (0);
161151
}
152+
162153
desktop_lock(desktop);
163154
}
164155
} else if(event == DesktopGlobalSaveSettings) {

applications/services/power/power_service/power.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,12 @@ static void power_auto_poweroff_timer_callback(void* context) {
441441
furi_assert(context);
442442
Power* power = context;
443443

444-
//poweroff if not charging now or if connected to charger and charging done
445-
if(((!furi_hal_power_is_charging())) || (furi_hal_power_is_charging_done())) {
446-
power_off(power);
447-
} else {
448-
//else we dont poweroff device and restart timer
444+
//Dont poweroff device if charger connected
445+
if (furi_hal_power_is_charging()) {
449446
FURI_LOG_D(TAG, "We dont auto_power_off until battery is charging");
450447
power_start_auto_poweroff_timer(power);
448+
} else {
449+
power_off(power);
451450
}
452451
}
453452

applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,14 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
4545
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
4646
{0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000};
4747

48-
#define USB_INHIBIT_AUTO_LOCK_DELAY_COUNT 3
49-
#define USB_INHIBIT_AUTOLOCK_OFF 0
50-
#define USB_INHIBIT_AUTOLOCK_ON 1
51-
#define USB_INHIBIT_AUTOLOCK_RPC 2
48+
#define USB_INHIBIT_AUTO_LOCK_DELAY_COUNT 2
5249

5350
const char* const usb_inhibit_auto_lock_delay_text[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {
5451
"OFF",
5552
"ON",
56-
"RPC",
5753
};
5854

59-
const uint32_t usb_inhibit_auto_lock_delay_value[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {
60-
USB_INHIBIT_AUTOLOCK_OFF,
61-
USB_INHIBIT_AUTOLOCK_ON,
62-
USB_INHIBIT_AUTOLOCK_RPC,
63-
};
55+
const uint32_t usb_inhibit_auto_lock_delay_value[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {0,1};
6456

6557
#define CLOCK_ENABLE_COUNT 2
6658
const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = {
@@ -144,7 +136,7 @@ void desktop_settings_scene_start_on_enter(void* context) {
144136
// USB connection Inhibit autolock OFF|ON|with opened RPC session
145137
item = variable_item_list_add(
146138
variable_item_list,
147-
"USB disarm Auto Lock",
139+
"Auto Lock disarm by active USB session",
148140
USB_INHIBIT_AUTO_LOCK_DELAY_COUNT,
149141
desktop_settings_scene_start_usb_inhibit_auto_lock_delay_changed,
150142
app);

0 commit comments

Comments
 (0)