[FL-2430] Automatic Desktop Locking (#1101)
* Add Auto Lock Time setting * Update .gitignore * Add value_index toolbox module * Auto locking basic implementation * Better AutoLock implementation, edge cases and cleanup * Fix NULL pointer crash * Turn off backlight shortly in locked mode * Re-enable auto lock after pin lock * Correctly handle start when pin locked * Use timer to hide locked hint * Use a single state variable instead of multiple bools * Do not call update callback recursively * Allow input when the Unlocked hint is shown * Add a delay to backlight switch off while locking * Better user input handling * Switch backlight off after pin timeout * Correct grammar in notification settings Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
#include <input/input.h>
|
||||
#include "notification.h"
|
||||
#include "notification_messages.h"
|
||||
#include "notification_app.h"
|
||||
@@ -416,8 +417,13 @@ static bool notification_save_settings(NotificationApp* app) {
|
||||
};
|
||||
|
||||
static void input_event_callback(const void* value, void* context) {
|
||||
furi_assert(value);
|
||||
furi_assert(context);
|
||||
const InputEvent* event = value;
|
||||
NotificationApp* app = context;
|
||||
notification_message(app, &sequence_display_on);
|
||||
if(event->type == InputTypePress) {
|
||||
notification_message(app, &sequence_display_on);
|
||||
}
|
||||
}
|
||||
|
||||
// App alloc
|
||||
|
@@ -21,7 +21,7 @@ const NotificationMessage message_display_lock = {
|
||||
};
|
||||
|
||||
const NotificationMessage message_display_unlock = {
|
||||
.type = NotificationMessageTypeLedDisplayLock,
|
||||
.type = NotificationMessageTypeLedDisplayUnlock,
|
||||
.data.led.value = 0x00,
|
||||
};
|
||||
|
||||
@@ -208,6 +208,12 @@ const NotificationSequence sequence_display_unlock = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
const NotificationSequence sequence_display_off_delay_1000 = {
|
||||
&message_delay_1000,
|
||||
&message_display_off,
|
||||
NULL,
|
||||
};
|
||||
|
||||
// Charging
|
||||
const NotificationSequence sequence_charging = {
|
||||
&message_red_255,
|
||||
@@ -436,4 +442,4 @@ const NotificationSequence sequence_audiovisual_alert = {
|
||||
&message_sound_off,
|
||||
&message_vibro_off,
|
||||
NULL,
|
||||
};
|
||||
};
|
||||
|
@@ -78,6 +78,8 @@ extern const NotificationSequence sequence_display_off;
|
||||
extern const NotificationSequence sequence_display_lock;
|
||||
/** Display: backlight always on unlock */
|
||||
extern const NotificationSequence sequence_display_unlock;
|
||||
/** Display: backlight force off after a delay of 1000ms */
|
||||
extern const NotificationSequence sequence_display_off_delay_1000;
|
||||
|
||||
// Charging
|
||||
extern const NotificationSequence sequence_charging;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "notification_app.h"
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <lib/toolbox/value_index.h>
|
||||
|
||||
#define MAX_NOTIFICATION_SETTINGS 4
|
||||
|
||||
@@ -63,44 +64,6 @@ const char* const vibro_text[VIBRO_COUNT] = {
|
||||
};
|
||||
const bool vibro_value[VIBRO_COUNT] = {false, true};
|
||||
|
||||
uint8_t float_value_index(const float value, const float values[], uint8_t values_count) {
|
||||
const float epsilon = 0.01f;
|
||||
float last_value = values[0];
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < values_count; i++) {
|
||||
if((value >= last_value - epsilon) && (value <= values[i] + epsilon)) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
last_value = values[i];
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t uint32_value_index(const uint32_t value, const uint32_t values[], uint8_t values_count) {
|
||||
int64_t last_value = INT64_MIN;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < values_count; i++) {
|
||||
if((value >= last_value) && (value <= values[i])) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
last_value = values[i];
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t bool_value_index(const bool value, const bool values[], uint8_t values_count) {
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < values_count; i++) {
|
||||
if(value == values[i]) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static void backlight_changed(VariableItem* item) {
|
||||
NotificationAppSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
@@ -164,21 +127,21 @@ static NotificationAppSettings* alloc_settings() {
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app);
|
||||
value_index = float_value_index(
|
||||
value_index = value_index_float(
|
||||
app->notification->settings.display_brightness, backlight_value, BACKLIGHT_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, backlight_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app);
|
||||
value_index = uint32_value_index(
|
||||
value_index = value_index_uint32(
|
||||
app->notification->settings.display_off_delay_ms, delay_value, DELAY_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, delay_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app);
|
||||
value_index = float_value_index(
|
||||
value_index = value_index_float(
|
||||
app->notification->settings.led_brightness, backlight_value, BACKLIGHT_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, backlight_text[value_index]);
|
||||
@@ -186,13 +149,13 @@ static NotificationAppSettings* alloc_settings() {
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app);
|
||||
value_index =
|
||||
float_value_index(app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT);
|
||||
value_index_float(app->notification->settings.speaker_volume, volume_value, VOLUME_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, volume_text[value_index]);
|
||||
|
||||
item =
|
||||
variable_item_list_add(app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app);
|
||||
value_index = bool_value_index(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT);
|
||||
value_index = value_index_bool(app->notification->settings.vibro_on, vibro_value, VIBRO_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, vibro_text[value_index]);
|
||||
|
||||
|
Reference in New Issue
Block a user