oopsie
This commit is contained in:
parent
2c1e78f723
commit
439ed71e6e
2 changed files with 12 additions and 5 deletions
6
Makefile
6
Makefile
|
|
@ -1,4 +1,8 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wextra -pedantic -std=c99
|
CFLAGS = -Wall -Wextra -pedantic -std=c99 -O2
|
||||||
|
PREFIX = /usr/local
|
||||||
|
|
||||||
ambientd: ambientd.c
|
ambientd: ambientd.c
|
||||||
|
|
||||||
|
install:
|
||||||
|
cp ambientd ${PREFIX}/bin/
|
||||||
|
|
|
||||||
11
ambientd.c
11
ambientd.c
|
|
@ -29,20 +29,21 @@ float min_brightness_percent = 0.05;
|
||||||
// returns the luminance value in percentage between 0 and 1
|
// returns the luminance value in percentage between 0 and 1
|
||||||
int get_luminance_raw (void)
|
int get_luminance_raw (void)
|
||||||
{
|
{
|
||||||
|
freopen(NULL, "r", luminance_fp);
|
||||||
const char *x = fgets(STR_BUFFER, sizeof(STR_BUFFER), luminance_fp);
|
const char *x = fgets(STR_BUFFER, sizeof(STR_BUFFER), luminance_fp);
|
||||||
if (x == NULL) {
|
if (x == NULL) {
|
||||||
fprintf(stderr, "Could not read luminance value: %s\n", strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int luminance = strtol(STR_BUFFER, NULL, 10);
|
int luminance = strtol(STR_BUFFER, NULL, 10);
|
||||||
rewind(luminance_fp);
|
|
||||||
|
|
||||||
return luminance;
|
return luminance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read a string from a file and convert it to int, should only be used for
|
||||||
|
// positive numbers since negative numbers mean an error
|
||||||
int read_int(FILE *fp)
|
int read_int(FILE *fp)
|
||||||
{
|
{
|
||||||
fflush(fp);
|
freopen(NULL, "r", fp);
|
||||||
const char *p = fgets(STR_BUFFER, sizeof(STR_BUFFER), fp);
|
const char *p = fgets(STR_BUFFER, sizeof(STR_BUFFER), fp);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -51,7 +52,6 @@ int read_int(FILE *fp)
|
||||||
if (r == LONG_MIN || r == LONG_MAX) {
|
if (r == LONG_MIN || r == LONG_MAX) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
rewind(fp);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,6 +101,9 @@ int main (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = get_luminance_raw();
|
int x = get_luminance_raw();
|
||||||
|
if (x < 0) {
|
||||||
|
fprintf(stderr, "Could not read luminance value: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
int luminance_samples[MEDIAN_SAMPLES] = {x, x, x, x};
|
int luminance_samples[MEDIAN_SAMPLES] = {x, x, x, x};
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
int user_offset = 0;
|
int user_offset = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue