mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
*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.
This commit is contained in:
@@ -13,8 +13,15 @@
|
||||
#include "scenes/desktop_scene.h"
|
||||
#include "scenes/desktop_scene_locked.h"
|
||||
|
||||
#include "furi_hal_power.h"
|
||||
|
||||
#define TAG "Desktop"
|
||||
|
||||
// dublicate constants from desktop_setting_scene_start.c
|
||||
#define USB_INHIBIT_AUTOLOCK_OFF 0
|
||||
#define USB_INHIBIT_AUTOLOCK_ON 1
|
||||
#define USB_INHIBIT_AUTOLOCK_RPC 2
|
||||
|
||||
static void desktop_auto_lock_arm(Desktop*);
|
||||
static void desktop_auto_lock_inhibit(Desktop*);
|
||||
static void desktop_start_auto_lock_timer(Desktop*);
|
||||
@@ -143,6 +150,14 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
||||
|
||||
} else if(event == DesktopGlobalAutoLock) {
|
||||
if(!desktop->app_running && !desktop->locked) {
|
||||
// if usb_inhibit_autolock enabled and device charging or device charged but still connected to USB then break desktop locking.
|
||||
if ((desktop->settings.usb_inhibit_auto_lock == USB_INHIBIT_AUTOLOCK_ON) && ((furi_hal_power_is_charging()) || (furi_hal_power_is_charging_done()))){
|
||||
return(0);
|
||||
}
|
||||
// if usb_inhibit_autolock set to RPC and we have F0 connected to phone or PC app then break desktop locking.
|
||||
if (desktop->settings.usb_inhibit_auto_lock == USB_INHIBIT_AUTOLOCK_RPC){
|
||||
return(0);
|
||||
}
|
||||
desktop_lock(desktop);
|
||||
}
|
||||
} else if(event == DesktopGlobalSaveSettings) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint32_t auto_lock_delay_ms;
|
||||
uint32_t auto_poweroff_delay_ms;
|
||||
uint8_t displayBatteryPercentage;
|
||||
uint8_t dummy_mode;
|
||||
uint8_t display_clock;
|
||||
@@ -53,6 +54,7 @@ void desktop_settings_load(DesktopSettings* settings) {
|
||||
|
||||
if(success) {
|
||||
settings->auto_lock_delay_ms = settings_v15->auto_lock_delay_ms;
|
||||
settings->usb_inhibit_auto_lock = 0;
|
||||
settings->displayBatteryPercentage = settings_v15->displayBatteryPercentage;
|
||||
settings->dummy_mode = settings_v15->dummy_mode;
|
||||
settings->display_clock = settings_v15->display_clock;
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
uint32_t auto_lock_delay_ms;
|
||||
uint8_t usb_inhibit_auto_lock;
|
||||
uint8_t displayBatteryPercentage;
|
||||
uint8_t dummy_mode;
|
||||
uint8_t display_clock;
|
||||
|
||||
@@ -416,16 +416,16 @@ void power_api_set_settings(Power* power, const PowerSettings* settings) {
|
||||
//start furi timer for autopoweroff
|
||||
static void power_start_auto_poweroff_timer(Power* power) {
|
||||
furi_timer_start(
|
||||
power->p_auto_poweroff_timer, furi_ms_to_ticks(power->settings.p_auto_poweroff_delay_ms));
|
||||
power->auto_poweroff_timer, furi_ms_to_ticks(power->settings.auto_poweroff_delay_ms));
|
||||
}
|
||||
|
||||
//stop furi timer for autopoweroff
|
||||
static void power_stop_auto_poweroff_timer(Power* power) {
|
||||
furi_timer_stop(power->p_auto_poweroff_timer);
|
||||
furi_timer_stop(power->auto_poweroff_timer);
|
||||
}
|
||||
|
||||
static uint32_t power_is_running_auto_poweroff_timer(Power* power) {
|
||||
return furi_timer_is_running(power->p_auto_poweroff_timer);
|
||||
return furi_timer_is_running(power->auto_poweroff_timer);
|
||||
}
|
||||
|
||||
// start|restart poweroff timer
|
||||
@@ -440,12 +440,19 @@ static void power_auto_poweroff_callback(const void* value, void* context) {
|
||||
static void power_auto_poweroff_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Power* power = context;
|
||||
power_off(power);
|
||||
//check charging state and dont poweroff if battery not fully charged
|
||||
power_check_charging_state(power);
|
||||
if (power->state == PowerStateCharged) {
|
||||
power_off(power);
|
||||
}
|
||||
else {
|
||||
FURI_LOG_D(TAG, "We dont auto_power_off until battery is charging");
|
||||
}
|
||||
}
|
||||
|
||||
//start|restart timer and events subscription and callbacks for input events (we restart timer when user press keys)
|
||||
static void power_auto_poweroff_arm(Power* power) {
|
||||
if(power->settings.p_auto_poweroff_delay_ms) {
|
||||
if(power->settings.auto_poweroff_delay_ms) {
|
||||
if(power->input_events_subscription == NULL) {
|
||||
power->input_events_subscription = furi_pubsub_subscribe(
|
||||
power->input_events_pubsub, power_auto_poweroff_callback, power);
|
||||
@@ -485,7 +492,7 @@ static void power_loader_callback(const void* message, void* context) {
|
||||
// apply power settings
|
||||
static void power_settings_apply(Power* power) {
|
||||
//apply auto_poweroff settings
|
||||
if(power->settings.p_auto_poweroff_delay_ms && !power->app_running) {
|
||||
if(power->settings.auto_poweroff_delay_ms && !power->app_running) {
|
||||
return;
|
||||
power_auto_poweroff_arm(power);
|
||||
} else if (power_is_running_auto_poweroff_timer(power)) {
|
||||
@@ -615,7 +622,7 @@ static Power* power_alloc(void) {
|
||||
furi_pubsub_subscribe(loader_get_pubsub(loader), power_loader_callback, power);
|
||||
power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
||||
//define autopoweroff timer and they callback
|
||||
power->p_auto_poweroff_timer =
|
||||
power->auto_poweroff_timer =
|
||||
furi_timer_alloc(power_auto_poweroff_timer_callback, FuriTimerTypeOnce, power);
|
||||
|
||||
// Gui
|
||||
|
||||
@@ -37,7 +37,7 @@ struct Power {
|
||||
uint8_t battery_level;
|
||||
uint8_t power_off_timeout;
|
||||
PowerSettings settings;
|
||||
FuriTimer* p_auto_poweroff_timer;
|
||||
FuriTimer* auto_poweroff_timer;
|
||||
bool app_running;
|
||||
FuriPubSub* input_events_pubsub;
|
||||
FuriPubSubSubscription* input_events_subscription;
|
||||
|
||||
@@ -44,7 +44,7 @@ void power_settings_load(PowerSettings* settings) {
|
||||
POWER_SETTINGS_VER_0);
|
||||
|
||||
if(success) {
|
||||
settings->p_auto_poweroff_delay_ms = 0;
|
||||
settings->auto_poweroff_delay_ms = 0;
|
||||
}
|
||||
|
||||
free(settings_v0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t p_auto_poweroff_delay_ms;
|
||||
uint32_t auto_poweroff_delay_ms;
|
||||
} PowerSettings;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -45,6 +45,23 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
||||
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
|
||||
{0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000};
|
||||
|
||||
#define USB_INHIBIT_AUTO_LOCK_DELAY_COUNT 3
|
||||
#define USB_INHIBIT_AUTOLOCK_OFF 0
|
||||
#define USB_INHIBIT_AUTOLOCK_ON 1
|
||||
#define USB_INHIBIT_AUTOLOCK_RPC 2
|
||||
|
||||
const char* const usb_inhibit_auto_lock_delay_text[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
"RPC",
|
||||
};
|
||||
|
||||
const uint32_t usb_inhibit_auto_lock_delay_value[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {
|
||||
USB_INHIBIT_AUTOLOCK_OFF,
|
||||
USB_INHIBIT_AUTOLOCK_ON,
|
||||
USB_INHIBIT_AUTOLOCK_RPC,
|
||||
};
|
||||
|
||||
#define CLOCK_ENABLE_COUNT 2
|
||||
const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = {
|
||||
"OFF",
|
||||
@@ -87,6 +104,7 @@ static void desktop_settings_scene_start_clock_enable_changed(VariableItem* item
|
||||
app->settings.display_clock = index;
|
||||
}
|
||||
|
||||
|
||||
static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) {
|
||||
DesktopSettingsApp* app = variable_item_get_context(item);
|
||||
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
|
||||
app->settings.auto_lock_delay_ms = auto_lock_delay_value[index];
|
||||
}
|
||||
|
||||
static void desktop_settings_scene_start_usb_inhibit_auto_lock_delay_changed(VariableItem* item) {
|
||||
DesktopSettingsApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, usb_inhibit_auto_lock_delay_text[index]);
|
||||
app->settings.usb_inhibit_auto_lock = usb_inhibit_auto_lock_delay_value[index];
|
||||
}
|
||||
|
||||
void desktop_settings_scene_start_on_enter(void* context) {
|
||||
DesktopSettingsApp* app = context;
|
||||
VariableItemList* variable_item_list = app->variable_item_list;
|
||||
@@ -116,6 +142,19 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, auto_lock_delay_text[value_index]);
|
||||
|
||||
// USB connection Inhibit autolock OFF|ON|with opened RPC session
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"USB disarm Auto Lock",
|
||||
USB_INHIBIT_AUTO_LOCK_DELAY_COUNT,
|
||||
desktop_settings_scene_start_usb_inhibit_auto_lock_delay_changed,
|
||||
app);
|
||||
|
||||
value_index = value_index_uint32(
|
||||
app->settings.usb_inhibit_auto_lock, usb_inhibit_auto_lock_delay_value, USB_INHIBIT_AUTO_LOCK_DELAY_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, usb_inhibit_auto_lock_delay_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Battery View",
|
||||
|
||||
@@ -8,20 +8,20 @@ enum PowerSettingsSubmenuIndex {
|
||||
PowerSettingsSubmenuIndexOff,
|
||||
};
|
||||
|
||||
#define P_AUTO_POWEROFF_DELAY_COUNT 8
|
||||
const char* const p_auto_poweroff_delay_text[P_AUTO_POWEROFF_DELAY_COUNT] =
|
||||
{"OFF","5min", "10min", "15min", "30min", "45min", "60min", "90min"};
|
||||
#define AUTO_POWEROFF_DELAY_COUNT 9
|
||||
const char* const auto_poweroff_delay_text[AUTO_POWEROFF_DELAY_COUNT] =
|
||||
{"OFF","5 sec","5min", "10min", "15min", "30min", "45min", "60min", "90min"};
|
||||
|
||||
const uint32_t p_auto_poweroff_delay_value[P_AUTO_POWEROFF_DELAY_COUNT] =
|
||||
{0, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000};
|
||||
const uint32_t auto_poweroff_delay_value[AUTO_POWEROFF_DELAY_COUNT] =
|
||||
{0, 5000, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000};
|
||||
|
||||
// change variable_item_list visible text and app_poweroff_delay_time_settings when user change item in variable_item_list
|
||||
static void power_settings_scene_start_auto_poweroff_delay_changed(VariableItem* item) {
|
||||
PowerSettingsApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, p_auto_poweroff_delay_text[index]);
|
||||
app->settings.p_auto_poweroff_delay_ms = p_auto_poweroff_delay_value[index];
|
||||
variable_item_set_current_value_text(item, auto_poweroff_delay_text[index]);
|
||||
app->settings.auto_poweroff_delay_ms = auto_poweroff_delay_value[index];
|
||||
}
|
||||
|
||||
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) {
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Auto PowerOff Time",
|
||||
P_AUTO_POWEROFF_DELAY_COUNT,
|
||||
AUTO_POWEROFF_DELAY_COUNT,
|
||||
power_settings_scene_start_auto_poweroff_delay_changed, //function for change visible item list value and app settings
|
||||
app);
|
||||
|
||||
value_index = value_index_uint32(
|
||||
app->settings.p_auto_poweroff_delay_ms,
|
||||
p_auto_poweroff_delay_value,
|
||||
P_AUTO_POWEROFF_DELAY_COUNT);
|
||||
app->settings.auto_poweroff_delay_ms,
|
||||
auto_poweroff_delay_value,
|
||||
AUTO_POWEROFF_DELAY_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, p_auto_poweroff_delay_text[value_index]);
|
||||
variable_item_set_current_value_text(item, auto_poweroff_delay_text[value_index]);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Battery Info", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Reboot", 1, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user