flipperzero-firmware/applications/settings/notification_settings/notification_settings_app.c

200 lines
6.9 KiB
C
Raw Normal View History

#include <furi.h>
#include <notification/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
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,
};
#define BACKLIGHT_COUNT 5
const char* const backlight_text[BACKLIGHT_COUNT] = {
"0%",
"25%",
"50%",
"75%",
"100%",
};
const float backlight_value[BACKLIGHT_COUNT] = {
0.0f,
0.25f,
0.5f,
0.75f,
1.0f,
};
#define VOLUME_COUNT 5
const char* const volume_text[VOLUME_COUNT] = {
"0%",
"25%",
"50%",
"75%",
"100%",
};
const float volume_value[VOLUME_COUNT] = {0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
#define DELAY_COUNT 6
const char* const delay_text[DELAY_COUNT] = {
"1s",
"5s",
"15s",
"30s",
"60s",
"120s",
};
const uint32_t delay_value[DELAY_COUNT] = {1000, 5000, 15000, 30000, 60000, 120000};
#define VIBRO_COUNT 2
const char* const vibro_text[VIBRO_COUNT] = {
"OFF",
"ON",
};
const bool vibro_value[VIBRO_COUNT] = {false, true};
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];
notification_message(app->notification, &sequence_display_backlight_on);
}
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];
notification_message(app->notification, &sequence_display_backlight_on);
}
const NotificationMessage apply_message = {
.type = NotificationMessageTypeLedBrightnessSettingApply,
};
const NotificationSequence apply_sequence = {
&apply_message,
NULL,
};
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];
notification_message(app->notification, &apply_sequence);
notification_internal_message(app->notification, &apply_sequence);
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];
notification_message(app->notification, &sequence_single_vibro);
}
static uint32_t notification_app_settings_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
}
static NotificationAppSettings* alloc_settings() {
NotificationAppSettings* app = malloc(sizeof(NotificationAppSettings));
app->notification = furi_record_open(RECORD_NOTIFICATION);
app->gui = furi_record_open(RECORD_GUI);
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;
item = variable_item_list_add(
app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app);
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 = 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 = 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]);
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]);
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]);
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);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);
free(app);
}
int32_t notification_settings_app(void* p) {
UNUSED(p);
NotificationAppSettings* app = alloc_settings();
view_dispatcher_run(app->view_dispatcher);
notification_message_save_settings(app->notification);
free_settings(app);
return 0;
[FL-2274] Inventing streams and moving FFF to them (#981) * Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 19:53:46 +00:00
}