mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-22 05:14:46 -07:00
"kostylling" )))
This commit is contained in:
@@ -283,20 +283,20 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
NotificationApp* app = context;
|
NotificationApp* app = context;
|
||||||
notification_message(app, &sequence_display_backlight_force_on);
|
notification_message(app, &sequence_display_backlight_force_on);
|
||||||
}
|
}
|
||||||
// --- NIGHT SHIFT END ---
|
// --- NIGHT SHIFT END ---
|
||||||
|
|
||||||
void notification_message_save_settings(NotificationApp * app) {
|
void notification_message_save_settings(NotificationApp* app) {
|
||||||
NotificationAppMessage m = {
|
NotificationAppMessage m = {
|
||||||
.type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()};
|
.type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()};
|
||||||
furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk);
|
furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk);
|
||||||
furi_event_flag_wait(
|
furi_event_flag_wait(
|
||||||
m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever);
|
m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever);
|
||||||
furi_event_flag_free(m.back_event);
|
furi_event_flag_free(m.back_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal layer
|
// internal layer
|
||||||
static void notification_apply_internal_led_layer(
|
static void
|
||||||
NotificationLedLayer * layer, uint8_t layer_value) {
|
notification_apply_internal_led_layer(NotificationLedLayer* layer, uint8_t layer_value) {
|
||||||
furi_assert(layer);
|
furi_assert(layer);
|
||||||
furi_assert(layer->index < LayerMAX);
|
furi_assert(layer->index < LayerMAX);
|
||||||
|
|
||||||
@@ -307,15 +307,15 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
if(layer->index == LayerInternal) {
|
if(layer->index == LayerInternal) {
|
||||||
furi_hal_light_set(layer->light, layer->value[LayerInternal]);
|
furi_hal_light_set(layer->light, layer->value[LayerInternal]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_apply_lcd_contrast(NotificationApp * app) {
|
static void notification_apply_lcd_contrast(NotificationApp* app) {
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
Gui* gui = furi_record_open(RECORD_GUI);
|
||||||
u8x8_d_st756x_set_contrast(&gui->canvas->fb.u8x8, app->settings.contrast);
|
u8x8_d_st756x_set_contrast(&gui->canvas->fb.u8x8, app->settings.contrast);
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool notification_is_any_led_layer_internal_and_not_empty(NotificationApp * app) {
|
static bool notification_is_any_led_layer_internal_and_not_empty(NotificationApp* app) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if((app->led[0].index == LayerInternal) || (app->led[1].index == LayerInternal) ||
|
if((app->led[0].index == LayerInternal) || (app->led[1].index == LayerInternal) ||
|
||||||
(app->led[2].index == LayerInternal)) {
|
(app->led[2].index == LayerInternal)) {
|
||||||
@@ -327,11 +327,12 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// notification layer
|
// notification layer
|
||||||
static void notification_apply_notification_led_layer(
|
static void notification_apply_notification_led_layer(
|
||||||
NotificationLedLayer * layer, const uint8_t layer_value) {
|
NotificationLedLayer* layer,
|
||||||
|
const uint8_t layer_value) {
|
||||||
furi_assert(layer);
|
furi_assert(layer);
|
||||||
furi_assert(layer->index < LayerMAX);
|
furi_assert(layer->index < LayerMAX);
|
||||||
|
|
||||||
@@ -346,9 +347,9 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
|
|
||||||
// apply
|
// apply
|
||||||
furi_hal_light_set(layer->light, layer->value[LayerNotification]);
|
furi_hal_light_set(layer->light, layer->value[LayerNotification]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_reset_notification_led_layer(NotificationLedLayer * layer) {
|
static void notification_reset_notification_led_layer(NotificationLedLayer* layer) {
|
||||||
furi_assert(layer);
|
furi_assert(layer);
|
||||||
furi_assert(layer->index < LayerMAX);
|
furi_assert(layer->index < LayerMAX);
|
||||||
|
|
||||||
@@ -359,10 +360,12 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
|
|
||||||
// apply
|
// apply
|
||||||
furi_hal_light_set(layer->light, layer->value[LayerInternal]);
|
furi_hal_light_set(layer->light, layer->value[LayerInternal]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_reset_notification_layer(
|
static void notification_reset_notification_layer(
|
||||||
NotificationApp * app, uint8_t reset_mask, float display_brightness_set) {
|
NotificationApp* app,
|
||||||
|
uint8_t reset_mask,
|
||||||
|
float display_brightness_set) {
|
||||||
if(reset_mask & reset_blink_mask) {
|
if(reset_mask & reset_blink_mask) {
|
||||||
furi_hal_light_blink_stop();
|
furi_hal_light_blink_stop();
|
||||||
}
|
}
|
||||||
@@ -392,67 +395,66 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
app->display_timer, notification_settings_display_off_delay_ticks(app));
|
app->display_timer, notification_settings_display_off_delay_ticks(app));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_apply_notification_leds(
|
static void notification_apply_notification_leds(NotificationApp* app, const uint8_t* values) {
|
||||||
NotificationApp * app, const uint8_t* values) {
|
|
||||||
for(uint8_t i = 0; i < NOTIFICATION_LED_COUNT; i++) {
|
for(uint8_t i = 0; i < NOTIFICATION_LED_COUNT; i++) {
|
||||||
notification_apply_notification_led_layer(
|
notification_apply_notification_led_layer(
|
||||||
&app->led[i], notification_settings_get_rgb_led_brightness(app, values[i]));
|
&app->led[i], notification_settings_get_rgb_led_brightness(app, values[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
uint8_t notification_settings_get_display_brightness(NotificationApp * app, uint8_t value) {
|
uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value) {
|
||||||
return value * app->settings.display_brightness;
|
return value * app->settings.display_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t notification_settings_get_rgb_led_brightness(
|
static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value) {
|
||||||
NotificationApp * app, uint8_t value) {
|
|
||||||
return value * app->settings.led_brightness;
|
return value * app->settings.led_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t notification_settings_display_off_delay_ticks(NotificationApp * app) {
|
static uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app) {
|
||||||
return (float)(app->settings.display_off_delay_ms) /
|
return (float)(app->settings.display_off_delay_ms) /
|
||||||
(1000.0f / furi_kernel_get_tick_frequency());
|
(1000.0f / furi_kernel_get_tick_frequency());
|
||||||
}
|
}
|
||||||
|
|
||||||
// generics
|
// generics
|
||||||
static void notification_vibro_on(bool force) {
|
static void notification_vibro_on(bool force) {
|
||||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
||||||
furi_hal_vibro_on(true);
|
furi_hal_vibro_on(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_vibro_off(void) {
|
static void notification_vibro_off(void) {
|
||||||
furi_hal_vibro_on(false);
|
furi_hal_vibro_on(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_sound_on(float freq, float volume, bool force) {
|
static void notification_sound_on(float freq, float volume, bool force) {
|
||||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
|
||||||
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
|
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
|
||||||
furi_hal_speaker_start(freq, volume);
|
furi_hal_speaker_start(freq, volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_sound_off(void) {
|
static void notification_sound_off(void) {
|
||||||
if(furi_hal_speaker_is_mine()) {
|
if(furi_hal_speaker_is_mine()) {
|
||||||
furi_hal_speaker_stop();
|
furi_hal_speaker_stop();
|
||||||
furi_hal_speaker_release();
|
furi_hal_speaker_release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// display timer
|
// display timer
|
||||||
static void notification_display_timer(void* ctx) {
|
static void notification_display_timer(void* ctx) {
|
||||||
furi_assert(ctx);
|
furi_assert(ctx);
|
||||||
NotificationApp* app = ctx;
|
NotificationApp* app = ctx;
|
||||||
notification_message(app, &sequence_display_backlight_off);
|
notification_message(app, &sequence_display_backlight_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
// message processing
|
// message processing
|
||||||
static void notification_process_notification_message(
|
static void notification_process_notification_message(
|
||||||
NotificationApp * app, NotificationAppMessage * message) {
|
NotificationApp* app,
|
||||||
|
NotificationAppMessage* message) {
|
||||||
uint32_t notification_message_index = 0;
|
uint32_t notification_message_index = 0;
|
||||||
bool force_volume = false;
|
bool force_volume = false;
|
||||||
bool force_vibro = false;
|
bool force_vibro = false;
|
||||||
@@ -671,10 +673,10 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
if(reset_notifications) {
|
if(reset_notifications) {
|
||||||
notification_reset_notification_layer(app, reset_mask, display_brightness_setting);
|
notification_reset_notification_layer(app, reset_mask, display_brightness_setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_process_internal_message(
|
static void
|
||||||
NotificationApp * app, NotificationAppMessage * message) {
|
notification_process_internal_message(NotificationApp* app, NotificationAppMessage* message) {
|
||||||
uint32_t notification_message_index = 0;
|
uint32_t notification_message_index = 0;
|
||||||
const NotificationMessage* notification_message;
|
const NotificationMessage* notification_message;
|
||||||
notification_message = (*message->sequence)[notification_message_index];
|
notification_message = (*message->sequence)[notification_message_index];
|
||||||
@@ -721,9 +723,9 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
notification_message_index++;
|
notification_message_index++;
|
||||||
notification_message = (*message->sequence)[notification_message_index];
|
notification_message = (*message->sequence)[notification_message_index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool notification_load_settings(NotificationApp * app) {
|
static bool notification_load_settings(NotificationApp* app) {
|
||||||
NotificationSettings settings;
|
NotificationSettings settings;
|
||||||
File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
||||||
const size_t settings_size = sizeof(NotificationSettings);
|
const size_t settings_size = sizeof(NotificationSettings);
|
||||||
@@ -743,10 +745,7 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
if(fs_result) {
|
if(fs_result) {
|
||||||
if(settings.version != NOTIFICATION_SETTINGS_VERSION) {
|
if(settings.version != NOTIFICATION_SETTINGS_VERSION) {
|
||||||
FURI_LOG_E(
|
FURI_LOG_E(
|
||||||
TAG,
|
TAG, "version(%d != %d) mismatch", settings.version, NOTIFICATION_SETTINGS_VERSION);
|
||||||
"version(%d != %d) mismatch",
|
|
||||||
settings.version,
|
|
||||||
NOTIFICATION_SETTINGS_VERSION);
|
|
||||||
} else {
|
} else {
|
||||||
furi_kernel_lock();
|
furi_kernel_lock();
|
||||||
memcpy(&app->settings, &settings, settings_size);
|
memcpy(&app->settings, &settings, settings_size);
|
||||||
@@ -760,10 +759,13 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
storage_file_free(file);
|
storage_file_free(file);
|
||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
return fs_result;
|
// "kostyl" for update old setting to new without change settings version
|
||||||
}
|
if(app->settings.display_off_delay_ms < 2000) app->settings.display_off_delay_ms = 2000;
|
||||||
|
|
||||||
static bool notification_save_settings(NotificationApp * app) {
|
return fs_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool notification_save_settings(NotificationApp* app) {
|
||||||
NotificationSettings settings;
|
NotificationSettings settings;
|
||||||
File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
||||||
const size_t settings_size = sizeof(NotificationSettings);
|
const size_t settings_size = sizeof(NotificationSettings);
|
||||||
@@ -795,17 +797,17 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
return fs_result;
|
return fs_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void input_event_callback(const void* value, void* context) {
|
static void input_event_callback(const void* value, void* context) {
|
||||||
furi_assert(value);
|
furi_assert(value);
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
NotificationApp* app = context;
|
NotificationApp* app = context;
|
||||||
notification_message(app, &sequence_display_backlight_on);
|
notification_message(app, &sequence_display_backlight_on);
|
||||||
}
|
}
|
||||||
|
|
||||||
// App alloc
|
// App alloc
|
||||||
static NotificationApp* notification_app_alloc(void) {
|
static NotificationApp* notification_app_alloc(void) {
|
||||||
NotificationApp* app = malloc(sizeof(NotificationApp));
|
NotificationApp* app = malloc(sizeof(NotificationApp));
|
||||||
app->queue = furi_message_queue_alloc(8, sizeof(NotificationAppMessage));
|
app->queue = furi_message_queue_alloc(8, sizeof(NotificationAppMessage));
|
||||||
app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypeOnce, app);
|
app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypeOnce, app);
|
||||||
@@ -871,9 +873,9 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
app->settings.lcd_inversion = false;
|
app->settings.lcd_inversion = false;
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_storage_callback(const void* message, void* context) {
|
static void notification_storage_callback(const void* message, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
NotificationApp* app = context;
|
NotificationApp* app = context;
|
||||||
const StorageEvent* event = message;
|
const StorageEvent* event = message;
|
||||||
@@ -885,9 +887,9 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
|
|
||||||
furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk);
|
furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_apply_settings(NotificationApp * app) {
|
static void notification_apply_settings(NotificationApp* app) {
|
||||||
if(!notification_load_settings(app)) {
|
if(!notification_load_settings(app)) {
|
||||||
notification_save_settings(app);
|
notification_save_settings(app);
|
||||||
}
|
}
|
||||||
@@ -907,9 +909,9 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
u8x8_d_st756x_set_inversion(&gui->canvas->fb.u8x8, app->settings.lcd_inversion);
|
u8x8_d_st756x_set_inversion(&gui->canvas->fb.u8x8, app->settings.lcd_inversion);
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notification_init_settings(NotificationApp * app) {
|
static void notification_init_settings(NotificationApp* app) {
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
furi_pubsub_subscribe(storage_get_pubsub(storage), notification_storage_callback, app);
|
furi_pubsub_subscribe(storage_get_pubsub(storage), notification_storage_callback, app);
|
||||||
|
|
||||||
@@ -919,10 +921,10 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notification_apply_settings(app);
|
notification_apply_settings(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
// App
|
// App
|
||||||
int32_t notification_srv(void* p) {
|
int32_t notification_srv(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
NotificationApp* app = notification_app_alloc();
|
NotificationApp* app = notification_app_alloc();
|
||||||
|
|
||||||
@@ -972,8 +974,7 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
|
|
||||||
NotificationAppMessage message;
|
NotificationAppMessage message;
|
||||||
while(1) {
|
while(1) {
|
||||||
furi_check(
|
furi_check(furi_message_queue_get(app->queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
furi_message_queue_get(app->queue, &message, FuriWaitForever) == FuriStatusOk);
|
|
||||||
|
|
||||||
switch(message.type) {
|
switch(message.type) {
|
||||||
case NotificationLayerMessage:
|
case NotificationLayerMessage:
|
||||||
@@ -996,4 +997,4 @@ void night_shift_demo_timer_callback(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ typedef struct {
|
|||||||
Light light;
|
Light light;
|
||||||
} NotificationLedLayer;
|
} NotificationLedLayer;
|
||||||
|
|
||||||
#define NOTIFICATION_SETTINGS_VERSION 0x06
|
#define NOTIFICATION_SETTINGS_VERSION 0x05
|
||||||
#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME)
|
#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user