completed c implementation
This commit is contained in:
parent
d06794b06e
commit
810a7e29b8
5 changed files with 12 additions and 7 deletions
11
ambientd.c
11
ambientd.c
|
|
@ -26,13 +26,13 @@ int max_luminance = 400;
|
|||
// minimum display brightness in percent
|
||||
float min_brightness_percent = 0.05;
|
||||
|
||||
// retturns the luminance value in percentage between 0 and 1
|
||||
// returns the luminance value in percentage between 0 and 1
|
||||
int get_luminance_raw (void)
|
||||
{
|
||||
const char *x = fgets(STR_BUFFER, sizeof(STR_BUFFER), luminance_fp);
|
||||
if (x == NULL) {
|
||||
fprintf(stderr, "Could not read luminance value: %s\n", strerror(errno));
|
||||
return 1.0;
|
||||
return -1;
|
||||
}
|
||||
int luminance = strtol(STR_BUFFER, NULL, 10);
|
||||
rewind(luminance_fp);
|
||||
|
|
@ -109,7 +109,8 @@ int main (void)
|
|||
static float luminance;
|
||||
static float luminance_percent;
|
||||
|
||||
luminance_samples[idx] = get_luminance_raw();
|
||||
x = get_luminance_raw();
|
||||
if (x >= 0) luminance_samples[idx] = x;
|
||||
idx = (idx + 1) % MEDIAN_SAMPLES;
|
||||
|
||||
luminance = 0;
|
||||
|
|
@ -147,7 +148,7 @@ int main (void)
|
|||
actual_brightness = read_int(actual_brightness_fp);
|
||||
if (actual_brightness < 0) {
|
||||
fprintf(stderr, "error reading actual brightness: %s\n", strerror(errno));
|
||||
actual_brightness = brightness_target;
|
||||
actual_brightness = brightness_adjusted;
|
||||
}
|
||||
|
||||
off = actual_brightness - brightness_target;
|
||||
|
|
@ -155,7 +156,7 @@ int main (void)
|
|||
user_offset = off;
|
||||
}
|
||||
|
||||
printf("brightness target: %d; user offset: %d; brightness adjusted: %d\n\n", brightness_target, user_offset, brightness_adjusted);
|
||||
printf("brightness target: %d; user offset: %d; brightness adjusted: %d\n", brightness_target, user_offset, brightness_adjusted);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue