-
Notifications
You must be signed in to change notification settings - Fork 0
/
brightness.c
74 lines (60 loc) · 1.84 KB
/
brightness.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* brightness.c -- Set brightness based on hour
This file is part of brightness.
Brightness is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Brightness is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Brightness. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2013 Jakub Tymejczyk <tymmej@gmail.com>
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "solar.h"
#define TRANSITION_LOW SOLAR_CIVIL_TWILIGHT_ELEV
#define TRANSITION_HIGH 3.0
#define DEG(x) ((x)*(180/M_PI))
/*also from Redshift*/
float calculate_interpolated_value(double elevation, float day, float night)
{
float result;
if (elevation < TRANSITION_LOW) {
result = night;
} else if (elevation < TRANSITION_HIGH) {
/* Transition period: interpolate */
float a = (TRANSITION_LOW - elevation) /
(TRANSITION_LOW - TRANSITION_HIGH);
result = (1.0-a)*night + a*day;
} else {
result = day;
}
return result;
}
int main(){
int brightness_day=100;
int brightness_night=5;
double date=0;
double lat=51.0;
double lon=17.0;
int brightness=0;
int prev_brightness=0;
int elevation=0;
char command[255];
while(1){
elevation=solar_elevation(date, lat, lon);
brightness=(int)calculate_interpolated_value(elevation, brightness_day, brightness_night);
if(brightness != prev_brightness){
sprintf(command, "light -S %d", brightness);
system(command);
prev_brightness=brightness;
}
sleep(60);
}
return 0;
}