implemented write_int()
This commit is contained in:
parent
550fa7f18b
commit
73dc9bc0de
1 changed files with 21 additions and 11 deletions
32
ambientd.c
32
ambientd.c
|
|
@ -41,9 +41,11 @@ int get_luminance_raw (void)
|
|||
|
||||
// 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)
|
||||
static int read_int(FILE *fp)
|
||||
{
|
||||
freopen(NULL, "r", fp);
|
||||
if (freopen(NULL, "r", fp) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
const char *p = fgets(STR_BUFFER, sizeof(STR_BUFFER), fp);
|
||||
if (p == NULL) {
|
||||
return -1;
|
||||
|
|
@ -55,10 +57,23 @@ int read_int(FILE *fp)
|
|||
return r;
|
||||
}
|
||||
|
||||
float bezier(float t)
|
||||
// write an intger value to a file as a string
|
||||
static int write_int(FILE* fp, int value)
|
||||
{
|
||||
if (freopen(NULL, "w", fp) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", value);
|
||||
if (x <= 0) {
|
||||
return -1;
|
||||
}
|
||||
return fputs(STR_BUFFER, fp);
|
||||
}
|
||||
|
||||
static inline float bezier(float t)
|
||||
{
|
||||
const float B = 0.66;
|
||||
const float D = 0.28;
|
||||
const float D = 0.28;
|
||||
return 3*B*t+(3*D-6*B)*t*t+(1+3*B-3*D)*t*t*t;
|
||||
}
|
||||
|
||||
|
|
@ -144,15 +159,10 @@ int main (void)
|
|||
}
|
||||
|
||||
brightness_adjusted = MIN(MAX(brightness_target + user_offset, min_brightness), max_brightness);
|
||||
// TODO: put this in write_int() function
|
||||
x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", brightness_adjusted);
|
||||
if (x <= 0) {
|
||||
fprintf(stderr, "Error in snprintf(): %s\n", strerror(errno));
|
||||
}
|
||||
if (fputs(STR_BUFFER, brightness_fp) == EOF) {
|
||||
x = write_int(brightness_fp, brightness_adjusted);
|
||||
if (x < 0) {
|
||||
fprintf(stderr, "error writing brightness: %s\n", strerror(errno));
|
||||
}
|
||||
rewind(brightness_fp);
|
||||
|
||||
sleep(3);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue