Skip to content

Commit

Permalink
button-backlight: dehardcode button brightnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
IMbackK committed Sep 26, 2022
1 parent 4442a4b commit b195430
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
13 changes: 13 additions & 0 deletions config/mce.ini
Expand Up @@ -349,3 +349,16 @@ NoAlsLowering=1
# on xt894/xt875
#[QuirksMapphone]
#OfflineCpu=0

[Backlights]

# Brightness in percent for different types of button backlights
# The 6 values in eatch profile corrispond to the level of brightness
# desired at:
# 0 - 25 lux
# 25 - 100 lux
# 100 - 300 lux
# 300 - 1000 lux
# 1000+ lux
KeyboardBrightness=80;128;0;0;0
ButtonBrightness=1;1;0;0;0
25 changes: 25 additions & 0 deletions src/modules/button-backlight.c
Expand Up @@ -40,6 +40,10 @@ static gboolean als_enabled = true;
static struct button_backlight *button_backlights = NULL;
static unsigned int count_backlights = 0;

/* format: { {series of 5 points in mlux}, {5 corresponding brightness values} } */
static struct brightness brightness_map_kbd = { {25, 100000, 300000, 1000000, 30000000}, {80, 128, 0, 0, 0} };
static struct brightness brightness_map_btn = { {25, 100000, 300000, 1000000, 30000000}, {1, 1, 0, 0, 0} };

static void set_backlight_states(bool by_display_state)
{
for (unsigned int i = 0; i < count_backlights; ++i) {
Expand Down Expand Up @@ -274,6 +278,24 @@ static gboolean init_backlights(void)
return true;
}

static bool load_brightness_profile(const char* key, struct brightness *profile)
{
gsize length;
gint *profilelist = mce_conf_get_int_list(MCE_CONF_BACKLIGHT_GROUP, key, &length, NULL);

if (profilelist == NULL || length != MCE_BUTTON_BACKLIGHT_BRIGHTNESS_VALUES) {
mce_log(LL_WARN, "%s: Failed to load brightness profile %s%s using defaults", MODULE_NAME, key,
profilelist != NULL && length != MCE_BUTTON_BACKLIGHT_BRIGHTNESS_VALUES ? " due to there being less or more than 5 values" : "");
return false;
}

for(size_t i = 0; i < length; ++i)
profile->value[i] = profilelist[i];

g_free(profilelist);
return true;
}

/**
* Init function for the keypad module
*
Expand All @@ -288,6 +310,9 @@ const gchar *g_module_check_init(GModule *module)
gchar *status = NULL;

(void)module;

load_brightness_profile("KeyboardBrightness", &brightness_map_kbd);
load_brightness_profile("ButtonBrightness", &brightness_map_btn);

if (!init_backlights())
return NULL;
Expand Down
11 changes: 4 additions & 7 deletions src/modules/button-backlight.h
Expand Up @@ -8,6 +8,8 @@
#define MCE_CONF_CONFIGURED_LIGHTS "ConfiguredLights"
#define MCE_CONF_COUNT_BACKLIGHT_FIELDS 6

#define MCE_BUTTON_BACKLIGHT_BRIGHTNESS_VALUES 5

#define LED_SYSFS_PATH "/sys/class/leds/"

#define LED_BRIGHTNESS_PATH "/brightness"
Expand All @@ -23,8 +25,8 @@ typedef enum {
} backlight_field;

struct brightness {
int lux[5];
int value[5];
int lux[MCE_BUTTON_BACKLIGHT_BRIGHTNESS_VALUES];
int value[MCE_BUTTON_BACKLIGHT_BRIGHTNESS_VALUES];
};

struct button_backlight{
Expand All @@ -38,9 +40,4 @@ struct button_backlight{
const struct brightness *brightness_map;
};

/* format: { {series of 5 points in mlux}, {5 corresponding brightness values} } */
static const struct brightness brightness_map_kbd = { {25, 250000, 1750000, 15000000, 30000000}, {80, 128, 0, 0, 0} };
static const struct brightness brightness_map_btn = { {25, 250000, 1750000, 15000000, 30000000}, {1, 1, 0, 0, 0} };


#endif

0 comments on commit b195430

Please sign in to comment.