Skip to content

Commit cf50875

Browse files
committed
*POWER*
- serice: renamed function and variable - settings: add test value 5 sec for auto_power_off timer *DESKTOP* - settings|service add USB_inhibit for desktop_auto_lock (dont autolock desktop with different condition) PS. RPC condition now working now.
1 parent ec75de0 commit cf50875

File tree

9 files changed

+86
-22
lines changed

9 files changed

+86
-22
lines changed

applications/services/desktop/desktop.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
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*);
@@ -143,6 +150,14 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
143150

144151
} else if(event == DesktopGlobalAutoLock) {
145152
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+
}
146161
desktop_lock(desktop);
147162
}
148163
} else if(event == DesktopGlobalSaveSettings) {

applications/services/desktop/desktop_settings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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;
@@ -53,6 +54,7 @@ void desktop_settings_load(DesktopSettings* settings) {
5354

5455
if(success) {
5556
settings->auto_lock_delay_ms = settings_v15->auto_lock_delay_ms;
57+
settings->usb_inhibit_auto_lock = 0;
5658
settings->displayBatteryPercentage = settings_v15->displayBatteryPercentage;
5759
settings->dummy_mode = settings_v15->dummy_mode;
5860
settings->display_clock = settings_v15->display_clock;

applications/services/desktop/desktop_settings.h

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

3939
typedef struct {
4040
uint32_t auto_lock_delay_ms;
41+
uint8_t usb_inhibit_auto_lock;
4142
uint8_t displayBatteryPercentage;
4243
uint8_t dummy_mode;
4344
uint8_t display_clock;

applications/services/power/power_service/power.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,16 @@ void power_api_set_settings(Power* power, const PowerSettings* settings) {
416416
//start furi timer for autopoweroff
417417
static void power_start_auto_poweroff_timer(Power* power) {
418418
furi_timer_start(
419-
power->p_auto_poweroff_timer, furi_ms_to_ticks(power->settings.p_auto_poweroff_delay_ms));
419+
power->auto_poweroff_timer, furi_ms_to_ticks(power->settings.auto_poweroff_delay_ms));
420420
}
421421

422422
//stop furi timer for autopoweroff
423423
static void power_stop_auto_poweroff_timer(Power* power) {
424-
furi_timer_stop(power->p_auto_poweroff_timer);
424+
furi_timer_stop(power->auto_poweroff_timer);
425425
}
426426

427427
static uint32_t power_is_running_auto_poweroff_timer(Power* power) {
428-
return furi_timer_is_running(power->p_auto_poweroff_timer);
428+
return furi_timer_is_running(power->auto_poweroff_timer);
429429
}
430430

431431
// start|restart poweroff timer
@@ -440,12 +440,19 @@ static void power_auto_poweroff_callback(const void* value, void* context) {
440440
static void power_auto_poweroff_timer_callback(void* context) {
441441
furi_assert(context);
442442
Power* power = context;
443-
power_off(power);
443+
//check charging state and dont poweroff if battery not fully charged
444+
power_check_charging_state(power);
445+
if (power->state == PowerStateCharged) {
446+
power_off(power);
447+
}
448+
else {
449+
FURI_LOG_D(TAG, "We dont auto_power_off until battery is charging");
450+
}
444451
}
445452

446453
//start|restart timer and events subscription and callbacks for input events (we restart timer when user press keys)
447454
static void power_auto_poweroff_arm(Power* power) {
448-
if(power->settings.p_auto_poweroff_delay_ms) {
455+
if(power->settings.auto_poweroff_delay_ms) {
449456
if(power->input_events_subscription == NULL) {
450457
power->input_events_subscription = furi_pubsub_subscribe(
451458
power->input_events_pubsub, power_auto_poweroff_callback, power);
@@ -485,7 +492,7 @@ static void power_loader_callback(const void* message, void* context) {
485492
// apply power settings
486493
static void power_settings_apply(Power* power) {
487494
//apply auto_poweroff settings
488-
if(power->settings.p_auto_poweroff_delay_ms && !power->app_running) {
495+
if(power->settings.auto_poweroff_delay_ms && !power->app_running) {
489496
return;
490497
power_auto_poweroff_arm(power);
491498
} else if (power_is_running_auto_poweroff_timer(power)) {
@@ -615,7 +622,7 @@ static Power* power_alloc(void) {
615622
furi_pubsub_subscribe(loader_get_pubsub(loader), power_loader_callback, power);
616623
power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
617624
//define autopoweroff timer and they callback
618-
power->p_auto_poweroff_timer =
625+
power->auto_poweroff_timer =
619626
furi_timer_alloc(power_auto_poweroff_timer_callback, FuriTimerTypeOnce, power);
620627

621628
// Gui

applications/services/power/power_service/power_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct Power {
3737
uint8_t battery_level;
3838
uint8_t power_off_timeout;
3939
PowerSettings settings;
40-
FuriTimer* p_auto_poweroff_timer;
40+
FuriTimer* auto_poweroff_timer;
4141
bool app_running;
4242
FuriPubSub* input_events_pubsub;
4343
FuriPubSubSubscription* input_events_subscription;

applications/services/power/power_service/power_settings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void power_settings_load(PowerSettings* settings) {
4444
POWER_SETTINGS_VER_0);
4545

4646
if(success) {
47-
settings->p_auto_poweroff_delay_ms = 0;
47+
settings->auto_poweroff_delay_ms = 0;
4848
}
4949

5050
free(settings_v0);

applications/services/power/power_service/power_settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <stdint.h>
44

55
typedef struct {
6-
uint32_t p_auto_poweroff_delay_ms;
6+
uint32_t auto_poweroff_delay_ms;
77
} PowerSettings;
88

99
#ifdef __cplusplus

applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ 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
52+
53+
const char* const usb_inhibit_auto_lock_delay_text[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {
54+
"OFF",
55+
"ON",
56+
"RPC",
57+
};
58+
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+
};
64+
4865
#define CLOCK_ENABLE_COUNT 2
4966
const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = {
5067
"OFF",
@@ -87,6 +104,7 @@ static void desktop_settings_scene_start_clock_enable_changed(VariableItem* item
87104
app->settings.display_clock = index;
88105
}
89106

107+
90108
static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) {
91109
DesktopSettingsApp* app = variable_item_get_context(item);
92110
uint8_t index = variable_item_get_current_value_index(item);
@@ -95,6 +113,14 @@ static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* i
95113
app->settings.auto_lock_delay_ms = auto_lock_delay_value[index];
96114
}
97115

116+
static void desktop_settings_scene_start_usb_inhibit_auto_lock_delay_changed(VariableItem* item) {
117+
DesktopSettingsApp* app = variable_item_get_context(item);
118+
uint8_t index = variable_item_get_current_value_index(item);
119+
120+
variable_item_set_current_value_text(item, usb_inhibit_auto_lock_delay_text[index]);
121+
app->settings.usb_inhibit_auto_lock = usb_inhibit_auto_lock_delay_value[index];
122+
}
123+
98124
void desktop_settings_scene_start_on_enter(void* context) {
99125
DesktopSettingsApp* app = context;
100126
VariableItemList* variable_item_list = app->variable_item_list;
@@ -116,6 +142,19 @@ void desktop_settings_scene_start_on_enter(void* context) {
116142
variable_item_set_current_value_index(item, value_index);
117143
variable_item_set_current_value_text(item, auto_lock_delay_text[value_index]);
118144

145+
// USB connection Inhibit autolock OFF|ON|with opened RPC session
146+
item = variable_item_list_add(
147+
variable_item_list,
148+
"USB disarm Auto Lock",
149+
USB_INHIBIT_AUTO_LOCK_DELAY_COUNT,
150+
desktop_settings_scene_start_usb_inhibit_auto_lock_delay_changed,
151+
app);
152+
153+
value_index = value_index_uint32(
154+
app->settings.usb_inhibit_auto_lock, usb_inhibit_auto_lock_delay_value, USB_INHIBIT_AUTO_LOCK_DELAY_COUNT);
155+
variable_item_set_current_value_index(item, value_index);
156+
variable_item_set_current_value_text(item, usb_inhibit_auto_lock_delay_text[value_index]);
157+
119158
item = variable_item_list_add(
120159
variable_item_list,
121160
"Battery View",

applications/settings/power_settings_app/scenes/power_settings_scene_start.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ enum PowerSettingsSubmenuIndex {
88
PowerSettingsSubmenuIndexOff,
99
};
1010

11-
#define P_AUTO_POWEROFF_DELAY_COUNT 8
12-
const char* const p_auto_poweroff_delay_text[P_AUTO_POWEROFF_DELAY_COUNT] =
13-
{"OFF","5min", "10min", "15min", "30min", "45min", "60min", "90min"};
11+
#define AUTO_POWEROFF_DELAY_COUNT 9
12+
const char* const auto_poweroff_delay_text[AUTO_POWEROFF_DELAY_COUNT] =
13+
{"OFF","5 sec","5min", "10min", "15min", "30min", "45min", "60min", "90min"};
1414

15-
const uint32_t p_auto_poweroff_delay_value[P_AUTO_POWEROFF_DELAY_COUNT] =
16-
{0, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000};
15+
const uint32_t auto_poweroff_delay_value[AUTO_POWEROFF_DELAY_COUNT] =
16+
{0, 5000, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000};
1717

1818
// change variable_item_list visible text and app_poweroff_delay_time_settings when user change item in variable_item_list
1919
static void power_settings_scene_start_auto_poweroff_delay_changed(VariableItem* item) {
2020
PowerSettingsApp* app = variable_item_get_context(item);
2121
uint8_t index = variable_item_get_current_value_index(item);
2222

23-
variable_item_set_current_value_text(item, p_auto_poweroff_delay_text[index]);
24-
app->settings.p_auto_poweroff_delay_ms = p_auto_poweroff_delay_value[index];
23+
variable_item_set_current_value_text(item, auto_poweroff_delay_text[index]);
24+
app->settings.auto_poweroff_delay_ms = auto_poweroff_delay_value[index];
2525
}
2626

2727
static void power_settings_scene_start_submenu_callback(void* context, uint32_t index) { //show selected menu screen
@@ -39,16 +39,16 @@ void power_settings_scene_start_on_enter(void* context) {
3939
item = variable_item_list_add(
4040
variable_item_list,
4141
"Auto PowerOff Time",
42-
P_AUTO_POWEROFF_DELAY_COUNT,
42+
AUTO_POWEROFF_DELAY_COUNT,
4343
power_settings_scene_start_auto_poweroff_delay_changed, //function for change visible item list value and app settings
4444
app);
4545

4646
value_index = value_index_uint32(
47-
app->settings.p_auto_poweroff_delay_ms,
48-
p_auto_poweroff_delay_value,
49-
P_AUTO_POWEROFF_DELAY_COUNT);
47+
app->settings.auto_poweroff_delay_ms,
48+
auto_poweroff_delay_value,
49+
AUTO_POWEROFF_DELAY_COUNT);
5050
variable_item_set_current_value_index(item, value_index);
51-
variable_item_set_current_value_text(item, p_auto_poweroff_delay_text[value_index]);
51+
variable_item_set_current_value_text(item, auto_poweroff_delay_text[value_index]);
5252

5353
variable_item_list_add(variable_item_list, "Battery Info", 1, NULL, NULL);
5454
variable_item_list_add(variable_item_list, "Reboot", 1, NULL, NULL);

0 commit comments

Comments
 (0)