diff --git a/TODO.md b/TODO.md index b1c0f77..20742e1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ ## 1.3 - [x] Fix check for <= 0 dimmer_timeout[state.ac_state] in dimmer module (to pause it) - [ ] 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) +- [x] FIX: bug in gamma -> if laptop gets sleeped after sunset (eg at 1.00pm) and resumed after sunrise (eg at 11am), it won't set 6500k ## Later - [ ] add weather support -> New struct for timeouts wuld be something like conf.timeout[enum state][enum weather] where enum weather = { UNWKNOWN, SUNNY, RAINY, CLOUDY } and defaults to 0 obviously -> state.weather = 0; ...or just use something like conf.temp[state.time] that cuts up to 50% at 100% cloudiness diff --git a/src/gamma.c b/src/gamma.c index 68d465d..029f616 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -51,7 +51,7 @@ static void destroy(void) { static void callback(void) { uint64_t t; - read(main_p[self.idx].fd, &t, sizeof(uint64_t)); + read(main_p[self.idx].fd, &t, sizeof(uint64_t)); check_gamma(); } @@ -67,8 +67,6 @@ 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, @@ -80,13 +78,17 @@ 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 || first_time) { - first_time = 0; - if (is_inited(GAMMA_SMOOTH)) { - start_gamma_transition(1); - } else { - set_temp(conf.temp[state.time]); - } + /* + * Force set every time correct gamma + * to avoid any possible sync issue + * between time of day and gamma (eg after long suspend). + * Note that in case correct gamma temp is already set, + * it won't do anything. + */ + if (is_inited(GAMMA_SMOOTH)) { + start_gamma_transition(1); + } else { + set_temp(conf.temp[state.time]); } /* desired gamma temp has been setted. Set new GAMMA timer and reset transitioning state. */