diff --git a/ambientd.c3 b/ambientd.c3 index f923461..a8fabad 100644 --- a/ambientd.c3 +++ b/ambientd.c3 @@ -74,9 +74,18 @@ fn void! write_int(String path, int value) fp.write(b)!; } -// returns the luminance value in percentage between 0 and 1 +// returns the raw luminance value macro get_luminance_raw() { return read_int(LUMINANCE_DEV); } +// write the brightness value, on fail log on stderr +macro write_brightness(int b) +{ + anyfault e = @catch(write_int(BRIGHTNESS_DEV, b)); + if (e) { + io::eprintfn("Error writing brightness: %s", e); + } +} + fn float bezier(float t) { const float B = 0.66; @@ -164,16 +173,10 @@ fn int main() if (brightness_now == brightness_adjusted) { return; } int step = (brightness_adjusted-brightness_now)/(SMOOTH_SAMPLES-1); for (int i; i < SMOOTH_SAMPLES-1; i++) { - anyfault e = @catch(write_int(BRIGHTNESS_DEV, brightness_now + step*i)); - if (e) { - io::eprintfn("Error writing brightness: %s", e); - } + write_brightness(brightness_now + step*i); thread::sleep_ms(SMOOTH_DURATION/SMOOTH_SAMPLES); } - anyfault e = @catch(write_int(BRIGHTNESS_DEV, brightness_adjusted)); - if (e) { - io::eprintfn("Error writing brightness: %s", e); - } + write_brightness(brightness_adjusted); |}; thread::sleep_ms(SLEEP_DELAY);