Skip to content

Commit

Permalink
FIxed a rare bug in gamma
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Aug 17, 2017
1 parent 13fab6b commit af5dfb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 12 additions & 10 deletions src/gamma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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,
Expand All @@ -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. */
Expand Down

0 comments on commit af5dfb0

Please sign in to comment.