2021-07-04 22:03:56 +00:00
|
|
|
#include <furi.h>
|
2022-09-14 16:11:38 +00:00
|
|
|
#include <notification/notification_app.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <gui/modules/variable_item_list.h>
|
2021-07-04 22:03:56 +00:00
|
|
|
#include <gui/view_dispatcher.h>
|
2022-04-14 12:20:41 +00:00
|
|
|
#include <lib/toolbox/value_index.h>
|
2021-07-04 22:03:56 +00:00
|
|
|
|
|
|
|
#define MAX_NOTIFICATION_SETTINGS 4
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
NotificationApp* notification;
|
|
|
|
Gui* gui;
|
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
|
VariableItemList* variable_item_list;
|
|
|
|
} NotificationAppSettings;
|
|
|
|
|
|
|
|
static const NotificationSequence sequence_note_c = {
|
|
|
|
&message_note_c5,
|
|
|
|
&message_delay_100,
|
|
|
|
&message_sound_off,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2023-06-06 17:46:01 +00:00
|
|
|
#define CONTRAST_COUNT 11
|
|
|
|
const char* const contrast_text[CONTRAST_COUNT] = {
|
|
|
|
"-5",
|
|
|
|
"-4",
|
|
|
|
"-3",
|
|
|
|
"-2",
|
|
|
|
"-1",
|
|
|
|
"0",
|
|
|
|
"+1",
|
|
|
|
"+2",
|
|
|
|
"+3",
|
|
|
|
"+4",
|
|
|
|
"+5",
|
|
|
|
};
|
|
|
|
const int32_t contrast_value[CONTRAST_COUNT] = {
|
|
|
|
-5,
|
|
|
|
-4,
|
|
|
|
-3,
|
|
|
|
-2,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
};
|
|
|
|
|
2023-07-05 16:33:27 +00:00
|
|
|
#define BACKLIGHT_COUNT 21
|
2021-07-04 22:03:56 +00:00
|
|
|
const char* const backlight_text[BACKLIGHT_COUNT] = {
|
2023-07-05 16:33:27 +00:00
|
|
|
"0%", "5%", "10%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%",
|
|
|
|
"55%", "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%",
|
2021-07-04 22:03:56 +00:00
|
|
|
};
|
|
|
|
const float backlight_value[BACKLIGHT_COUNT] = {
|
2023-07-05 16:33:27 +00:00
|
|
|
0.00f, 0.05f, 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.40f, 0.45f, 0.50f,
|
|
|
|
0.55f, 0.60f, 0.65f, 0.70f, 0.75f, 0.80f, 0.85f, 0.90f, 0.95f, 1.00f,
|
2021-07-04 22:03:56 +00:00
|
|
|
};
|
|
|
|
|
2023-07-05 16:33:27 +00:00
|
|
|
#define VOLUME_COUNT 21
|
2021-07-04 22:03:56 +00:00
|
|
|
const char* const volume_text[VOLUME_COUNT] = {
|
2023-07-05 16:33:27 +00:00
|
|
|
"0%", "5%", "10%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%",
|
|
|
|
"55%", "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%",
|
|
|
|
};
|
|
|
|
const float volume_value[VOLUME_COUNT] = {
|
|
|
|
0.00f, 0.05f, 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.40f, 0.45f, 0.50f,
|
|
|
|
0.55f, 0.60f, 0.65f, 0.70f, 0.75f, 0.80f, 0.85f, 0.90f, 0.95f, 1.00f,
|
2021-07-04 22:03:56 +00:00
|
|
|
};
|
|
|
|
|
2022-09-16 14:38:08 +00:00
|
|
|
#define DELAY_COUNT 11
|
2021-07-04 22:03:56 +00:00
|
|
|
const char* const delay_text[DELAY_COUNT] = {
|
|
|
|
"1s",
|
|
|
|
"5s",
|
2022-06-21 05:43:10 +00:00
|
|
|
"10s",
|
2021-07-04 22:03:56 +00:00
|
|
|
"15s",
|
|
|
|
"30s",
|
|
|
|
"60s",
|
2022-05-27 19:18:35 +00:00
|
|
|
"90s",
|
2021-07-04 22:03:56 +00:00
|
|
|
"120s",
|
2022-09-16 14:38:08 +00:00
|
|
|
"5min",
|
|
|
|
"10min",
|
|
|
|
"30min",
|
|
|
|
};
|
2022-09-20 20:24:34 +00:00
|
|
|
const uint32_t delay_value[DELAY_COUNT] =
|
|
|
|
{1000, 5000, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000, 1800000};
|
2021-07-04 22:03:56 +00:00
|
|
|
|
|
|
|
#define VIBRO_COUNT 2
|
|
|
|
const char* const vibro_text[VIBRO_COUNT] = {
|
|
|
|
"OFF",
|
|
|
|
"ON",
|
|
|
|
};
|
|
|
|
const bool vibro_value[VIBRO_COUNT] = {false, true};
|
|
|
|
|
2023-06-06 17:46:01 +00:00
|
|
|
static void contrast_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, contrast_text[index]);
|
|
|
|
app->notification->settings.contrast = contrast_value[index];
|
|
|
|
notification_message(app->notification, &sequence_lcd_contrast_update);
|
|
|
|
}
|
|
|
|
|
2021-07-04 22:03:56 +00:00
|
|
|
static void backlight_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, backlight_text[index]);
|
|
|
|
app->notification->settings.display_brightness = backlight_value[index];
|
2022-04-29 14:21:12 +00:00
|
|
|
notification_message(app->notification, &sequence_display_backlight_on);
|
2021-07-04 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, delay_text[index]);
|
|
|
|
app->notification->settings.display_off_delay_ms = delay_value[index];
|
2022-04-29 14:21:12 +00:00
|
|
|
notification_message(app->notification, &sequence_display_backlight_on);
|
2021-07-04 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 12:33:03 +00:00
|
|
|
const NotificationMessage apply_message = {
|
|
|
|
.type = NotificationMessageTypeLedBrightnessSettingApply,
|
|
|
|
};
|
|
|
|
const NotificationSequence apply_sequence = {
|
|
|
|
&apply_message,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2021-07-04 22:03:56 +00:00
|
|
|
static void led_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, backlight_text[index]);
|
|
|
|
app->notification->settings.led_brightness = backlight_value[index];
|
2022-04-21 12:33:03 +00:00
|
|
|
notification_message(app->notification, &apply_sequence);
|
|
|
|
notification_internal_message(app->notification, &apply_sequence);
|
2021-07-04 22:03:56 +00:00
|
|
|
notification_message(app->notification, &sequence_blink_white_100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void volume_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, volume_text[index]);
|
|
|
|
app->notification->settings.speaker_volume = volume_value[index];
|
|
|
|
notification_message(app->notification, &sequence_note_c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vibro_changed(VariableItem* item) {
|
|
|
|
NotificationAppSettings* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, vibro_text[index]);
|
|
|
|
app->notification->settings.vibro_on = vibro_value[index];
|
2021-11-26 14:01:03 +00:00
|
|
|
notification_message(app->notification, &sequence_single_vibro);
|
2021-07-04 22:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t notification_app_settings_exit(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-07-04 22:03:56 +00:00
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NotificationAppSettings* alloc_settings() {
|
|
|
|
NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings));
|
2022-07-26 12:21:51 +00:00
|
|
|
app->notification = furi_record_open(RECORD_NOTIFICATION);
|
|
|
|
app->gui = furi_record_open(RECORD_GUI);
|
2021-07-04 22:03:56 +00:00
|
|
|
|
|
|
|
app->variable_item_list = variable_item_list_alloc();
|
|
|
|
View* view = variable_item_list_get_view(app->variable_item_list);
|
|
|
|
view_set_previous_callback(view, notification_app_settings_exit);
|
|
|
|
|
|
|
|
VariableItem* item;
|
|
|
|
uint8_t value_index;
|
|
|
|
|
2023-06-06 17:46:01 +00:00
|
|
|
item = variable_item_list_add(
|
|
|
|
app->variable_item_list, "LCD Contrast", CONTRAST_COUNT, contrast_changed, app);
|
|
|
|
value_index =
|
|
|
|
value_index_int32(app->notification->settings.contrast, contrast_value, CONTRAST_COUNT);
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, contrast_text[value_index]);
|
|
|
|
|
2021-07-04 22:03:56 +00:00
|
|
|
item = variable_item_list_add(
|
2022-04-11 11:54:38 +00:00
|
|
|
app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app);
|
2022-04-14 12:20:41 +00:00
|
|
|
value_index = value_index_float(
|
2021-07-04 22:03:56 +00:00
|
|
|
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(
|
2022-04-11 11:54:38 +00:00
|
|
|
app->variable_item_list, "Backlight Time", DELAY_COUNT, screen_changed, app);
|
2022-04-14 12:20:41 +00:00
|
|
|
value_index = value_index_uint32(
|
2021-07-04 22:03:56 +00:00
|
|
|
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(
|
2022-04-11 11:54:38 +00:00
|
|
|
app->variable_item_list, "LED Brightness", BACKLIGHT_COUNT, led_changed, app);
|
2022-04-14 12:20:41 +00:00
|
|
|
value_index = value_index_float(
|
2021-07-04 22:03:56 +00:00
|
|
|
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]);
|
|
|
|
|
2023-04-19 09:33:23 +00:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) {
|
|
|
|
item = variable_item_list_add(app->variable_item_list, "Volume", 1, NULL, app);
|
|
|
|
value_index = 0;
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, "Stealth");
|
|
|
|
} else {
|
|
|
|
item = variable_item_list_add(
|
|
|
|
app->variable_item_list, "Volume", VOLUME_COUNT, volume_changed, app);
|
|
|
|
value_index = 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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)) {
|
|
|
|
item = variable_item_list_add(app->variable_item_list, "Vibro", 1, NULL, app);
|
|
|
|
value_index = 0;
|
|
|
|
variable_item_set_current_value_index(item, value_index);
|
|
|
|
variable_item_set_current_value_text(item, "Stealth");
|
|
|
|
} else {
|
|
|
|
item = variable_item_list_add(
|
|
|
|
app->variable_item_list, "Vibro", VIBRO_COUNT, vibro_changed, app);
|
|
|
|
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]);
|
|
|
|
}
|
2021-07-04 22:03:56 +00:00
|
|
|
|
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
|
|
view_dispatcher_add_view(app->view_dispatcher, 0, view);
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, 0);
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_settings(NotificationAppSettings* app) {
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, 0);
|
|
|
|
variable_item_list_free(app->variable_item_list);
|
|
|
|
view_dispatcher_free(app->view_dispatcher);
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
2021-07-04 22:03:56 +00:00
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
2021-08-07 16:54:42 +00:00
|
|
|
int32_t notification_settings_app(void* p) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(p);
|
2021-07-04 22:03:56 +00:00
|
|
|
NotificationAppSettings* app = alloc_settings();
|
|
|
|
view_dispatcher_run(app->view_dispatcher);
|
|
|
|
notification_message_save_settings(app->notification);
|
|
|
|
free_settings(app);
|
|
|
|
return 0;
|
2022-02-18 19:53:46 +00:00
|
|
|
}
|