current working, need find and remove 1 bug

This commit is contained in:
Dmitry422
2025-03-28 01:14:57 +07:00
parent 77865586e1
commit cd28f7d232
7 changed files with 264 additions and 80 deletions

View File

@@ -33,6 +33,51 @@ static uint8_t notification_settings_get_display_brightness(NotificationApp* app
static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value);
static uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app);
// --- NIGHT SHIFT ---
void night_shift_timer_start(NotificationApp* app) {
if(app->settings.night_shift != 1) {
furi_timer_start(app->night_shift_timer, furi_ms_to_ticks(2000));
}
}
void night_shift_timer_stop(NotificationApp* app) {
if(furi_timer_is_running(app->night_shift_timer)) {
furi_timer_stop(app->night_shift_timer);
}
}
// every callback time we check current time and current night_shift_settings value
void night_shift_timer_callback(void* context) {
furi_assert(context);
NotificationApp* app = context;
DateTime current_date_time;
// save current night_shift;
// float old_night_shift = app->current_night_shift;
// take system time and convert to minutes
furi_hal_rtc_get_datetime(&current_date_time);
uint32_t time = current_date_time.hour * 60 + current_date_time.minute;
// if current time not in night_shift range then current_night_shift = 1 else = settings value;
// set values to stock and rgb backlights
if((time > app->settings.night_shift_end) && (time < app->settings.night_shift_start)) {
app->current_night_shift = 1.0f;
app->rgb_srv->current_night_shift = 1.0f;
} else {
app->current_night_shift = app->settings.night_shift;
app->rgb_srv->current_night_shift = app->settings.night_shift;
}
// // if night shift was changed then update stock and rgb backlight to new value
// if(old_night_shift != app->current_night_shift) {
// notification_message(app, &sequence_display_backlight_on);
// }
}
// --- NIGHT SHIFT END ---
void notification_message_save_settings(NotificationApp* app) {
NotificationAppMessage m = {
.type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()};
@@ -129,7 +174,11 @@ static void notification_reset_notification_layer(
}
if(reset_mask & reset_display_mask) {
if(!float_is_equal(display_brightness_set, app->settings.display_brightness)) {
furi_hal_light_set(LightBacklight, app->settings.display_brightness * 0xFF);
// --- NIGHT SHIFT ---
furi_hal_light_set(
LightBacklight,
app->settings.display_brightness * 0xFF * app->current_night_shift);
// --- NIGHT SHIFT END---
}
furi_timer_start(app->display_timer, notification_settings_display_off_delay_ticks(app));
}
@@ -214,15 +263,17 @@ static void notification_process_notification_message(
// if on - switch on and start timer
// if off - switch off and stop timer
// on timer - switch off
// --- NIGHT SHIFT ---
if(notification_message->data.led.value > 0x00) {
notification_apply_notification_led_layer(
&app->display,
notification_message->data.led.value * display_brightness_setting);
notification_message->data.led.value * display_brightness_setting *
app->current_night_shift);
reset_mask |= reset_display_mask;
//start rgb_mod_rainbow_timer when display backlight is ON and all corresponding settings is ON too
rainbow_timer_starter(app->rgb_srv);
// --- NIGHT SHIFT END ---
} else {
reset_mask &= ~reset_display_mask;
notification_reset_notification_led_layer(&app->display);
@@ -238,10 +289,12 @@ static void notification_process_notification_message(
case NotificationMessageTypeLedDisplayBacklightEnforceOn:
furi_check(app->display_led_lock < UINT8_MAX);
app->display_led_lock++;
// --- NIGHT SHIFT ---
if(app->display_led_lock == 1) {
notification_apply_internal_led_layer(
&app->display,
notification_message->data.led.value * display_brightness_setting);
notification_message->data.led.value * display_brightness_setting *
app->current_night_shift);
}
break;
case NotificationMessageTypeLedDisplayBacklightEnforceAuto:
@@ -250,8 +303,10 @@ static void notification_process_notification_message(
if(app->display_led_lock == 0) {
notification_apply_internal_led_layer(
&app->display,
notification_message->data.led.value * display_brightness_setting);
notification_message->data.led.value * display_brightness_setting *
app->current_night_shift);
}
// --- NIGHT SHIFT END ---
} else {
FURI_LOG_E(TAG, "Incorrect BacklightEnforce use");
}
@@ -559,6 +614,17 @@ static NotificationApp* notification_app_alloc(void) {
furi_pubsub_subscribe(app->event_record, input_event_callback, app);
notification_message(app, &sequence_display_backlight_on);
// --- NIGHT SHIFT ---
app->rgb_srv = furi_record_open(RECORD_RGB_BACKLIGHT);
app->rgb_srv->current_night_shift = 1.0f;
app->current_night_shift = 1.0f;
app->settings.night_shift = 1.0f;
app->settings.night_shift_start = 1020;
app->settings.night_shift_end = 300;
app->night_shift_timer =
furi_timer_alloc(night_shift_timer_callback, FuriTimerTypePeriodic, app);
// --- NIGHT SHIFT END ---
return app;
}
@@ -582,6 +648,13 @@ static void notification_apply_settings(NotificationApp* app) {
}
notification_apply_lcd_contrast(app);
// --- NIGHT SHIFT ---
// if night_shift_enabled start timer for controlling current_night_shift multiplicator value depent from current time
if(app->settings.night_shift != 1) {
night_shift_timer_start(app);
}
// --- NIGHT SHIFT END ---
}
static void notification_init_settings(NotificationApp* app) {
@@ -600,7 +673,7 @@ static void notification_init_settings(NotificationApp* app) {
int32_t notification_srv(void* p) {
UNUSED(p);
NotificationApp* app = notification_app_alloc();
app->rgb_srv = furi_record_open(RECORD_RGB_BACKLIGHT);
notification_init_settings(app);
notification_vibro_off();