macro to write brightness

This commit is contained in:
Alessandro Mauri 2024-10-29 13:32:02 +01:00
parent 9ba6ed6136
commit 4bb263c961

View file

@ -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);