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();

View File

@@ -34,7 +34,7 @@ typedef struct {
Light light;
} NotificationLedLayer;
#define NOTIFICATION_SETTINGS_VERSION 0x02
#define NOTIFICATION_SETTINGS_VERSION 0x03
#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME)
typedef struct {
@@ -61,6 +61,11 @@ struct NotificationApp {
NotificationSettings settings;
RGBBacklightApp* rgb_srv;
FuriTimer* night_shift_timer;
float current_night_shift;
};
void notification_message_save_settings(NotificationApp* app);
void night_shift_timer_start(NotificationApp* app);
void night_shift_timer_stop(NotificationApp* app);

View File

@@ -137,9 +137,9 @@ void rgb_backlight_update(float brightness) {
if(app->settings->rgb_backlight_installed) {
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
uint8_t r = current_led[i].red * (brightness * 1.0f);
uint8_t g = current_led[i].green * (brightness * 1.0f);
uint8_t b = current_led[i].blue * (brightness * 1.0f);
uint8_t r = current_led[i].red * brightness;
uint8_t g = current_led[i].green * brightness;
uint8_t b = current_led[i].blue * brightness;
SK6805_set_led_color(i, r, g, b);
}
SK6805_update();
@@ -154,7 +154,7 @@ void rainbow_timer_start(RGBBacklightApp* app) {
// stop furi timer for rainbow
void rainbow_timer_stop(RGBBacklightApp* app) {
if (furi_timer_is_running (app->rainbow_timer)){
if(furi_timer_is_running(app->rainbow_timer)) {
furi_timer_stop(app->rainbow_timer);
}
}
@@ -214,7 +214,7 @@ static void rainbow_timer_callback(void* context) {
break;
}
rgb_backlight_update(app->settings->brightness);
rgb_backlight_update(app->settings->brightness * app->current_night_shift);
}
}
@@ -233,6 +233,7 @@ int32_t rgb_backlight_srv(void* p) {
rgb_backlight_settings_load(app->settings);
app->rainbow_hue = 1;
app->current_night_shift = 1.0f;
furi_record_create(RECORD_RGB_BACKLIGHT, app);
@@ -244,7 +245,7 @@ int32_t rgb_backlight_srv(void* p) {
rgb_backlight_set_led_static_color(2, app->settings->led_2_color_index);
rgb_backlight_set_led_static_color(1, app->settings->led_1_color_index);
rgb_backlight_set_led_static_color(0, app->settings->led_0_color_index);
rgb_backlight_update(app->settings->brightness);
rgb_backlight_update(app->settings->brightness * app->current_night_shift);
}
// if rgb_backlight not installed then set default static orange color(index=0) to all leds (0-2) and force light on
} else {

View File

@@ -33,6 +33,9 @@ typedef struct {
uint8_t rainbow_green;
uint8_t rainbow_blue;
RGBBacklightSettings* settings;
// night_shift multiplicator for leds brightnes coming from Notificatoin app.
float current_night_shift;
} RGBBacklightApp;
#define RECORD_RGB_BACKLIGHT "rgb_backlight"

View File

@@ -30,6 +30,7 @@ typedef struct {
uint16_t rainbow_step;
uint8_t rainbow_saturation;
uint8_t rainbow_wide;
} RGBBacklightSettingsPrevious;
void rgb_backlight_settings_load(RGBBacklightSettings* settings) {

View File

@@ -20,7 +20,7 @@ typedef struct {
uint16_t rainbow_step;
uint8_t rainbow_saturation;
uint8_t rainbow_wide;
} RGBBacklightSettings;
#ifdef __cplusplus