Skip to content

Commit

Permalink
FIxed a bug in gamma initialization. Reworked settings file.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Aug 5, 2017
1 parent c5fb897 commit 888488f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 75 deletions.
100 changes: 50 additions & 50 deletions Extra/clight.conf
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
## Number of frames to be captured
# frames = 5;
############
# TIMEOUTS #
############

## Timeout between captures during the day on ac
# ac_day_timeout = 600;
## Timeouts between captures during day/night/event on ac
# ac_capture_timeouts = [ 600, 2700, 300 ];

## Timeout between captures during the day on batt
# batt_day_timeout = 1200;
## Timeouts between captures during day/night/event on batt
# batt_capture_timeouts = [ 1200, 5400, 600 ];

## Timeout between captures during the night on ac
# ac_night_timeout = 2700;
## Dimmer timeouts on ac/on batt
# dimmer_timeouts = [ 300, 45 ];

## Timeout between captures during the night on batt
# batt_night_timeout = 5400;
## Timeouts for dpms on ac
# ac_dpms_timeouts = [ 900, 1200, 1800 ];

## Timeout between captures during an event on ac
## ie: from 30 mins before a {sunrise, sunset}, until 30mins after.
# ac_event_timeout = 300;
## Timeout for dpms on battery
# batt_dpms_timeouts = [ 300, 420, 600 ];

## Timeout between captures during an event on batt
## ie: from 30 mins before a {sunrise, sunset}, until 30mins after.
# batt_event_timeout = 600;
#########
# GAMMA #
#########

## Gamma daily temperature
# day_temp = 6500;
## Gamma temperature during day and night
# gamma_temp = [ 6500, 4000 ]

## Gamma nightly temperature
# night_temp = 4000;
###################
# DISABLE MODULES #
###################

## Uncomment to disable gamma smooth transitions
# no_smooth_gamma_transition = 1;
Expand All @@ -36,6 +37,35 @@
## Uncomment to disable gamma support
# no_gamma = 1;

## Uncomment to disable dpms tool
# no_dpms = 1;

## Uncomment to disable org.freedesktop.PowerManagement.Inhibit
## interface support
# no_inhibit = 1;

## Uncomment to disable dimmer tool
# no_dimmer = 1;

####################
# BACKLIGHT CURVES #
####################

## Y points used to compute ambient_brightness while ON AC -> screen backlight curve best-fit parameters
## through polynomial regression. X values are simply array's indexes (from 0 to 10 included).
# ac_brightness_regression_points = [ 0.0, 0.15, 0.29, 0.45, 0.61, 0.74, 0.81, 0.88, 0.93, 0.97, 1.0 ];

## Y points used to compute ambient_brightness while ON BATTERY -> screen backlight curve best-fit parameters
## through polynomial regression. X values are simply array's indexes (from 0 to 10 included).
# batt_brightness_regression_points = [ 0.0, 0.15, 0.23, 0.36, 0.52, 0.59, 0.65, 0.71, 0.75, 0.78, 0.80 ];

###########
# GENERIC #
###########

## Number of frames to be captured
# frames = 5;

## Your desired latitude for gamma support (surise/sunset in this location)
# latitude = 40.9;

Expand All @@ -58,39 +88,9 @@
## from event_duration seconds before a sunrise/sunset, until event_duration seconds after.
# event_duration = 1800

## Y points used to compute ambient_brightness while ON AC -> screen backlight curve best-fit parameters
## through polynomial regression. X values are simply array's indexes (from 0 to 10 included).
# ac_brightness_regression_points = [ 0.0, 0.15, 0.29, 0.45, 0.61, 0.74, 0.81, 0.88, 0.93, 0.97, 1.0 ];

## Y points used to compute ambient_brightness while ON BATTERY -> screen backlight curve best-fit parameters
## through polynomial regression. X values are simply array's indexes (from 0 to 10 included).
# batt_brightness_regression_points = [ 0.0, 0.15, 0.23, 0.36, 0.52, 0.59, 0.65, 0.71, 0.75, 0.78, 0.80 ];

## Uncomment to disable dimmer tool
# no_dimmer = 1;

## Change dimmer backlight level, in percentage
# dimmer_pct = 20;

## Dimmer timeout while on AC
# ac_dimmer_timeout = 300;

## Dimmer timeout while on BATTERY
# batt_dimmer_timeout = 45;

## Uncomment to disable dpms tool
# no_dpms = 1;

## Uncomment to disable org.freedesktop.PowerManagement.Inhibit
## interface support
# no_inhibit = 1;

## Timeouts for dpms on ac
# ac_dpms_timeouts = [ 900, 1200, 1800 ];

## Timeout for dpms on battery
# batt_dpms_timeouts = [ 300, 420, 600 ];

## Verbose mode, useful in case of bugs:
## run clight in verbose mode,
## then open issue on github attaching log
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.2
- [ ] rework conf settings: timeouts should be: AC_capture_timeouts = { 600, 2700, 300 } BATT_capture_timeouts = { }
- [x] rework conf settings: timeouts should be: AC_capture_timeouts = { 600, 2700, 300 } BATT_capture_timeouts = { } etc etc
- [x] autodisabling of bus-dependent module seems broken now: it seems sd_bus_add_match returns 1 even if interface is not existent
- [x] start clight after org.freedesktop.PowerManagement.Inhibit interface? (it seems that interface is still missing when clight starts) -> if this can't be fixed, add a systemd timer that starts clight 5s later
- [x] fix gamma not setting correct gamma for current state first time clight is started

## 1.3
- [ ] subscribe to "interfaceEnabledChanged" signal from clightd (as soon as it is implemented in clightd) and do a capture as soon as interface became enabled (May be disable both dimmer and brightness while interface is disabled)
Expand Down
80 changes: 57 additions & 23 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ void read_config(enum CONFIG file) {
config_init(&cfg);
if (config_read_file(&cfg, config_file) == CONFIG_TRUE) {
config_lookup_int(&cfg, "frames", &conf.num_captures);
config_lookup_int(&cfg, "ac_day_timeout", &conf.timeout[ON_AC][DAY]);
config_lookup_int(&cfg, "ac_night_timeout", &conf.timeout[ON_AC][NIGHT]);
config_lookup_int(&cfg, "ac_event_timeout", &conf.timeout[ON_AC][EVENT]);
config_lookup_int(&cfg, "batt_day_timeout", &conf.timeout[ON_BATTERY][DAY]);
config_lookup_int(&cfg, "batt_night_timeout", &conf.timeout[ON_BATTERY][NIGHT]);
config_lookup_int(&cfg, "batt_event_timeout", &conf.timeout[ON_BATTERY][EVENT]);
config_lookup_int(&cfg, "day_temp", &conf.temp[DAY]);
config_lookup_int(&cfg, "night_temp", &conf.temp[NIGHT]);
config_lookup_int(&cfg, "no_smooth_gamma_transition", (int *)&modules[GAMMA_SMOOTH].state);
config_lookup_int(&cfg, "no_smooth_dimmer_transition", (int *)&modules[DIMMER_SMOOTH].state);
config_lookup_int(&cfg, "no_gamma", (int *)&modules[GAMMA].state);
Expand All @@ -48,8 +40,6 @@ void read_config(enum CONFIG file) {
config_lookup_int(&cfg, "event_duration", &conf.event_duration);
config_lookup_int(&cfg, "no_dimmer", (int *)&modules[DIMMER].state);
config_lookup_int(&cfg, "dimmer_pct", &conf.dimmer_pct);
config_lookup_int(&cfg, "ac_dimmer_timeout", &conf.dimmer_timeout[ON_AC]);
config_lookup_int(&cfg, "batt_dimmer_timeout", &conf.dimmer_timeout[ON_BATTERY]);
config_lookup_int(&cfg, "no_dpms", (int *)&modules[DPMS].state);
config_lookup_int(&cfg, "no_inhibit", (int *)&modules[INHIBIT].state);
config_lookup_int(&cfg, "verbose", &conf.verbose);
Expand All @@ -67,12 +57,12 @@ void read_config(enum CONFIG file) {
strncpy(conf.events[SUNSET], sunset, sizeof(conf.events[SUNSET]) - 1);
}

config_setting_t *points, *root, *dpms_timeouts;
config_setting_t *points, *root, *timeouts, *gamma;
root = config_root_setting(&cfg);

/* Load regression points for brightness curve */
if ((points = config_setting_get_member(root, "ac_brightness_regression_points"))) {
if (config_setting_length(points) >= SIZE_POINTS) {
if (config_setting_length(points) == SIZE_POINTS) {
for (int i = 0; i < SIZE_POINTS; i++) {
conf.regression_points[ON_AC][i] = config_setting_get_float_elem(points, i);
}
Expand All @@ -83,7 +73,7 @@ void read_config(enum CONFIG file) {

/* Load regression points for brightness curve */
if ((points = config_setting_get_member(root, "batt_brightness_regression_points"))) {
if (config_setting_length(points) >= SIZE_POINTS) {
if (config_setting_length(points) == SIZE_POINTS) {
for (int i = 0; i < SIZE_POINTS; i++) {
conf.regression_points[ON_BATTERY][i] = config_setting_get_float_elem(points, i);
}
Expand All @@ -92,25 +82,69 @@ void read_config(enum CONFIG file) {
}
}

/* Load dpms timeout while on ac */
if ((dpms_timeouts = config_setting_get_member(root, "ac_dpms_timeouts"))) {
if (config_setting_length(dpms_timeouts) >= SIZE_DPMS) {
/* Load dpms timeouts while on ac */
if ((timeouts = config_setting_get_member(root, "ac_dpms_timeouts"))) {
if (config_setting_length(timeouts) == SIZE_DPMS) {
for (int i = 0; i < SIZE_DPMS; i++) {
conf.dpms_timeouts[ON_AC][i] = config_setting_get_int_elem(dpms_timeouts, i);
conf.dpms_timeouts[ON_AC][i] = config_setting_get_int_elem(timeouts, i);
}
} else {
WARN("Wrong number of dpms timeouts array elements.\n");
WARN("Wrong number of ac_dpms_timeouts array elements.\n");
}
}

/* Load dpms timeout while on battery */
if ((dpms_timeouts = config_setting_get_member(root, "batt_dpms_timeouts"))) {
if (config_setting_length(dpms_timeouts) >= SIZE_DPMS) {
/* Load dpms timeouts while on battery */
if ((timeouts = config_setting_get_member(root, "batt_dpms_timeouts"))) {
if (config_setting_length(timeouts) == SIZE_DPMS) {
for (int i = 0; i < SIZE_DPMS; i++) {
conf.dpms_timeouts[ON_BATTERY][i] = config_setting_get_int_elem(dpms_timeouts, i);
conf.dpms_timeouts[ON_BATTERY][i] = config_setting_get_int_elem(timeouts, i);
}
} else {
WARN("Wrong number of dpms timeouts array elements.\n");
WARN("Wrong number of batt_dpms_timeouts array elements.\n");
}
}

/* Load capture timeouts while on battery */
if ((timeouts = config_setting_get_member(root, "ac_capture_timeouts"))) {
if (config_setting_length(timeouts) == SIZE_STATES) {
for (int i = 0; i < SIZE_STATES; i++) {
conf.timeout[ON_AC][i] = config_setting_get_int_elem(timeouts, i);
}
} else {
WARN("Wrong number of ac_capture_timeouts array elements.\n");
}
}

/* Load capture timeouts while on battery */
if ((timeouts = config_setting_get_member(root, "batt_capture_timeouts"))) {
if (config_setting_length(timeouts) == SIZE_STATES) {
for (int i = 0; i < SIZE_STATES; i++) {
conf.timeout[ON_BATTERY][i] = config_setting_get_int_elem(timeouts, i);
}
} else {
WARN("Wrong number of batt_capture_timeouts array elements.\n");
}
}

/* Load dimmer timeouts */
if ((timeouts = config_setting_get_member(root, "dimmer_timeouts"))) {
if (config_setting_length(timeouts) == SIZE_AC) {
for (int i = 0; i < SIZE_AC; i++) {
conf.dimmer_timeout[i] = config_setting_get_int_elem(timeouts, i);
}
} else {
WARN("Wrong number of dimmer_timeouts array elements.\n");
}
}

/* Load gamma temperatures -> SIZE_STATES - 1 because temp[EVENT] is not exposed */
if ((gamma = config_setting_get_member(root, "gamma_temp"))) {
if (config_setting_length(gamma) == SIZE_STATES - 1) {
for (int i = 0; i < SIZE_STATES - 1; i++) {
conf.temp[i] = config_setting_get_int_elem(gamma, i);
}
} else {
WARN("Wrong number of gamma_temp array elements.\n");
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/gamma.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static void callback(void) {
* set new BRIGHTNESS correct timeout according to new state.
*/
static void check_gamma(void) {
static int first_time = 1;

time_t t = time(NULL);
/*
* get_gamma_events will always poll today events. It should not be necessary,
Expand All @@ -78,7 +80,8 @@ static void check_gamma(void) {
enum states old_state = state.time;
get_gamma_events(&t, conf.lat, conf.lon, 0);

if (state.event_time_range == conf.event_duration) {
if (state.event_time_range == conf.event_duration || first_time) {
first_time = 0;
if (is_inited(GAMMA_SMOOTH)) {
start_gamma_transition(1);
} else {
Expand Down

0 comments on commit 888488f

Please sign in to comment.