Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3316] Settings: add contrast adjustment #2737

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applications/services/notification/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ typedef enum {
NotificationMessageTypeForceDisplayBrightnessSetting,

NotificationMessageTypeLedBrightnessSettingApply,

NotificationMessageTypeLcdContrastUpdate,
} NotificationMessageType;

typedef struct {
Expand Down
55 changes: 35 additions & 20 deletions applications/services/notification/notification_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <furi_hal.h>
#include <storage/storage.h>
#include <input/input.h>
#include <gui/gui_i.h>
#include <u8g2_glue.h>

#include "notification.h"
#include "notification_messages.h"
#include "notification_app.h"
Expand All @@ -20,14 +23,14 @@ static const uint8_t reset_sound_mask = 1 << 4;
static const uint8_t reset_display_mask = 1 << 5;
static const uint8_t reset_blink_mask = 1 << 6;

void notification_vibro_on(bool force);
void notification_vibro_off();
void notification_sound_on(float freq, float volume, bool force);
void notification_sound_off();
static void notification_vibro_on(bool force);
static void notification_vibro_off();
static void notification_sound_on(float freq, float volume, bool force);
static void notification_sound_off();

uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);
uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value);
uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app);
static uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);
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);

void notification_message_save_settings(NotificationApp* app) {
NotificationAppMessage m = {
Expand All @@ -39,7 +42,8 @@ void notification_message_save_settings(NotificationApp* app) {
};

// internal layer
void notification_apply_internal_led_layer(NotificationLedLayer* layer, uint8_t layer_value) {
static void
notification_apply_internal_led_layer(NotificationLedLayer* layer, uint8_t layer_value) {
furi_assert(layer);
furi_assert(layer->index < LayerMAX);

Expand All @@ -52,7 +56,13 @@ void notification_apply_internal_led_layer(NotificationLedLayer* layer, uint8_t
}
}

bool notification_is_any_led_layer_internal_and_not_empty(NotificationApp* app) {
static void notification_apply_lcd_contrast(NotificationApp* app) {
Gui* gui = furi_record_open(RECORD_GUI);
u8x8_d_st756x_set_contrast(&gui->canvas->fb.u8x8, app->settings.contrast);
furi_record_close(RECORD_GUI);
}

static bool notification_is_any_led_layer_internal_and_not_empty(NotificationApp* app) {
bool result = false;
if((app->led[0].index == LayerInternal) || (app->led[1].index == LayerInternal) ||
(app->led[2].index == LayerInternal)) {
Expand All @@ -67,7 +77,7 @@ bool notification_is_any_led_layer_internal_and_not_empty(NotificationApp* app)
}

// notification layer
void notification_apply_notification_led_layer(
static void notification_apply_notification_led_layer(
NotificationLedLayer* layer,
const uint8_t layer_value) {
furi_assert(layer);
Expand All @@ -81,7 +91,7 @@ void notification_apply_notification_led_layer(
furi_hal_light_set(layer->light, layer->value[LayerNotification]);
}

void notification_reset_notification_led_layer(NotificationLedLayer* layer) {
static void notification_reset_notification_led_layer(NotificationLedLayer* layer) {
furi_assert(layer);
furi_assert(layer->index < LayerMAX);

Expand All @@ -94,7 +104,7 @@ void notification_reset_notification_led_layer(NotificationLedLayer* layer) {
furi_hal_light_set(layer->light, layer->value[LayerInternal]);
}

void notification_reset_notification_layer(NotificationApp* app, uint8_t reset_mask) {
static void notification_reset_notification_layer(NotificationApp* app, uint8_t reset_mask) {
if(reset_mask & reset_blink_mask) {
furi_hal_light_blink_stop();
}
Expand Down Expand Up @@ -130,36 +140,36 @@ uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8
return (value * app->settings.display_brightness);
}

uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value) {
static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value) {
return (value * app->settings.led_brightness);
}

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) /
(1000.0f / furi_kernel_get_tick_frequency()));
}

// generics
void notification_vibro_on(bool force) {
static void notification_vibro_on(bool force) {
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode) || force) {
furi_hal_vibro_on(true);
}
}

void notification_vibro_off() {
static void notification_vibro_off() {
furi_hal_vibro_on(false);
}

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_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(freq, volume);
}
}
}

void notification_sound_off() {
static void notification_sound_off() {
if(furi_hal_speaker_is_mine()) {
furi_hal_speaker_stop();
furi_hal_speaker_release();
Expand All @@ -174,7 +184,7 @@ static void notification_display_timer(void* ctx) {
}

// message processing
void notification_process_notification_message(
static void notification_process_notification_message(
NotificationApp* app,
NotificationAppMessage* message) {
uint32_t notification_message_index = 0;
Expand Down Expand Up @@ -333,6 +343,9 @@ void notification_process_notification_message(
reset_mask |= reset_green_mask;
reset_mask |= reset_blue_mask;
break;
case NotificationMessageTypeLcdContrastUpdate:
notification_apply_lcd_contrast(app);
break;
}
notification_message_index++;
notification_message = (*message->sequence)[notification_message_index];
Expand Down Expand Up @@ -361,7 +374,8 @@ void notification_process_notification_message(
}
}

void notification_process_internal_message(NotificationApp* app, NotificationAppMessage* message) {
static void
notification_process_internal_message(NotificationApp* app, NotificationAppMessage* message) {
uint32_t notification_message_index = 0;
const NotificationMessage* notification_message;
notification_message = (*message->sequence)[notification_message_index];
Expand Down Expand Up @@ -548,6 +562,7 @@ int32_t notification_srv(void* p) {
notification_apply_internal_led_layer(&app->led[0], 0x00);
notification_apply_internal_led_layer(&app->led[1], 0x00);
notification_apply_internal_led_layer(&app->led[2], 0x00);
notification_apply_lcd_contrast(app);

furi_record_create(RECORD_NOTIFICATION, app);

Expand Down
3 changes: 2 additions & 1 deletion applications/services/notification/notification_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct {
Light light;
} NotificationLedLayer;

#define NOTIFICATION_SETTINGS_VERSION 0x01
#define NOTIFICATION_SETTINGS_VERSION 0x02
#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME)

typedef struct {
Expand All @@ -41,6 +41,7 @@ typedef struct {
float led_brightness;
float speaker_volume;
uint32_t display_off_delay_ms;
int8_t contrast;
bool vibro_on;
} NotificationSettings;

Expand Down
9 changes: 9 additions & 0 deletions applications/services/notification/notification_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ const NotificationMessage message_force_display_brightness_setting_1f = {
.data.forced_settings.display_brightness = 1.0f,
};

const NotificationMessage message_lcd_contrast_update = {
.type = NotificationMessageTypeLcdContrastUpdate,
};

/****************************** Message sequences ******************************/

// Reset
Expand Down Expand Up @@ -566,3 +570,8 @@ const NotificationSequence sequence_audiovisual_alert = {
&message_vibro_off,
NULL,
};

const NotificationSequence sequence_lcd_contrast_update = {
&message_lcd_contrast_update,
NULL,
};
6 changes: 6 additions & 0 deletions applications/services/notification/notification_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ extern const NotificationMessage message_force_vibro_setting_on;
extern const NotificationMessage message_force_vibro_setting_off;
extern const NotificationMessage message_force_display_brightness_setting_1f;

// LCD Messages
extern const NotificationMessage message_lcd_contrast_update;

/****************************** Message sequences ******************************/

// Reset
Expand Down Expand Up @@ -138,6 +141,9 @@ extern const NotificationSequence sequence_success;
extern const NotificationSequence sequence_error;
extern const NotificationSequence sequence_audiovisual_alert;

// LCD
extern const NotificationSequence sequence_lcd_contrast_update;

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ static const NotificationSequence sequence_note_c = {
NULL,
};

#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,
};

#define BACKLIGHT_COUNT 5
const char* const backlight_text[BACKLIGHT_COUNT] = {
"0%",
Expand Down Expand Up @@ -64,6 +92,15 @@ const char* const vibro_text[VIBRO_COUNT] = {
};
const bool vibro_value[VIBRO_COUNT] = {false, true};

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

static void backlight_changed(VariableItem* item) {
NotificationAppSettings* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand Down Expand Up @@ -136,6 +173,13 @@ static NotificationAppSettings* alloc_settings() {
VariableItem* item;
uint8_t value_index;

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

item = variable_item_list_add(
app->variable_item_list, "LCD Backlight", BACKLIGHT_COUNT, backlight_changed, app);
value_index = value_index_float(
Expand Down
5 changes: 4 additions & 1 deletion firmware/targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,28.2,,
Version,+,28.3,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -1999,6 +1999,7 @@ Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*"
Function,+,validator_is_file_free,void,ValidatorIsFile*
Function,+,value_index_bool,uint8_t,"const _Bool, const _Bool[], uint8_t"
Function,+,value_index_float,uint8_t,"const float, const float[], uint8_t"
Function,+,value_index_int32,uint8_t,"const int32_t, const int32_t[], uint8_t"
Function,+,value_index_uint32,uint8_t,"const uint32_t, const uint32_t[], uint8_t"
Function,+,variable_item_get_context,void*,VariableItem*
Function,+,variable_item_get_current_value_index,uint8_t,VariableItem*
Expand Down Expand Up @@ -2259,6 +2260,7 @@ Variable,+,message_force_vibro_setting_off,const NotificationMessage,
Variable,+,message_force_vibro_setting_on,const NotificationMessage,
Variable,+,message_green_0,const NotificationMessage,
Variable,+,message_green_255,const NotificationMessage,
Variable,+,message_lcd_contrast_update,const NotificationMessage,
Variable,+,message_note_a0,const NotificationMessage,
Variable,+,message_note_a1,const NotificationMessage,
Variable,+,message_note_a2,const NotificationMessage,
Expand Down Expand Up @@ -2402,6 +2404,7 @@ Variable,+,sequence_display_backlight_off_delay_1000,const NotificationSequence,
Variable,+,sequence_display_backlight_on,const NotificationSequence,
Variable,+,sequence_double_vibro,const NotificationSequence,
Variable,+,sequence_error,const NotificationSequence,
Variable,+,sequence_lcd_contrast_update,const NotificationSequence,
Variable,+,sequence_not_charging,const NotificationSequence,
Variable,+,sequence_reset_blue,const NotificationSequence,
Variable,+,sequence_reset_display,const NotificationSequence,
Expand Down
5 changes: 4 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,28.2,,
Version,+,28.3,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -2923,6 +2923,7 @@ Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*"
Function,+,validator_is_file_free,void,ValidatorIsFile*
Function,+,value_index_bool,uint8_t,"const _Bool, const _Bool[], uint8_t"
Function,+,value_index_float,uint8_t,"const float, const float[], uint8_t"
Function,+,value_index_int32,uint8_t,"const int32_t, const int32_t[], uint8_t"
Function,+,value_index_uint32,uint8_t,"const uint32_t, const uint32_t[], uint8_t"
Function,+,variable_item_get_context,void*,VariableItem*
Function,+,variable_item_get_current_value_index,uint8_t,VariableItem*
Expand Down Expand Up @@ -3192,6 +3193,7 @@ Variable,+,message_force_vibro_setting_off,const NotificationMessage,
Variable,+,message_force_vibro_setting_on,const NotificationMessage,
Variable,+,message_green_0,const NotificationMessage,
Variable,+,message_green_255,const NotificationMessage,
Variable,+,message_lcd_contrast_update,const NotificationMessage,
Variable,+,message_note_a0,const NotificationMessage,
Variable,+,message_note_a1,const NotificationMessage,
Variable,+,message_note_a2,const NotificationMessage,
Expand Down Expand Up @@ -3335,6 +3337,7 @@ Variable,+,sequence_display_backlight_off_delay_1000,const NotificationSequence,
Variable,+,sequence_display_backlight_on,const NotificationSequence,
Variable,+,sequence_double_vibro,const NotificationSequence,
Variable,+,sequence_error,const NotificationSequence,
Variable,+,sequence_lcd_contrast_update,const NotificationSequence,
Variable,+,sequence_not_charging,const NotificationSequence,
Variable,+,sequence_reset_blue,const NotificationSequence,
Variable,+,sequence_reset_display,const NotificationSequence,
Expand Down
13 changes: 13 additions & 0 deletions lib/toolbox/value_index.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "value_index.h"

uint8_t value_index_int32(const int32_t value, const int32_t values[], uint8_t values_count) {
int64_t last_value = INT64_MIN;
uint8_t index = 0;
for(uint8_t i = 0; i < values_count; i++) {
if((value >= last_value) && (value <= values[i])) {
index = i;
break;
}
last_value = values[i];
}
return index;
}

uint8_t value_index_uint32(const uint32_t value, const uint32_t values[], uint8_t values_count) {
int64_t last_value = INT64_MIN;
uint8_t index = 0;
Expand Down
13 changes: 13 additions & 0 deletions lib/toolbox/value_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
extern "C" {
#endif

/** Get the index of a int32_t array element which is closest to the given value.
*
* Returned index corresponds to the first element found.
* If no suitable elements were found, the function returns 0.
*
* @param value value to be searched.
* @param values pointer to the array to perform the search in.
* @param values_count array size.
*
* @return value's index.
*/
uint8_t value_index_int32(const int32_t value, const int32_t values[], uint8_t values_count);

/** Get the index of a uint32_t array element which is closest to the given value.
*
* Returned index corresponds to the first element found.
Expand Down
Loading