diff --git a/ambientd.c3 b/ambientd.c3 index ea9346d..005f017 100644 --- a/ambientd.c3 +++ b/ambientd.c3 @@ -94,29 +94,32 @@ fn int main() } // get the max brightness - int! _x = read_int(MAX_BRIGHTNESS_DEV); - if (catch excuse = _x) { + int max_brightness; + int min_brightness; + int! opt = read_int(MAX_BRIGHTNESS_DEV); + if (try unwrapped = opt) { + max_brightness = unwrapped; + } if (catch excuse = opt) { io::eprintfn("Error reading max brightness on %s: %s", MAX_BRIGHTNESS_DEV, excuse); - thread::exit(1); + return 1; } - int max_brightness = _x!!; - int min_brightness = (int)(max_brightness * MIN_BRIGHTNESS_PERCENT); + min_brightness = (int)(max_brightness * MIN_BRIGHTNESS_PERCENT); // try writing to brightness device - _x = read_int(BRIGHTNESS_DEV); - if (catch excuse = _x) { + int! br = read_int(BRIGHTNESS_DEV); + if (catch excuse = br) { io::eprintfn("Error reading from %s: %s", BRIGHTNESS_DEV, excuse); - thread::exit(1); + return 1; } - if (catch excuse = write_int(BRIGHTNESS_DEV, _x)) { - io::eprintfn("Error writing to brightness device %s: %s", BRIGHTNESS_DEV, excuse); - thread::exit(1); + if (catch excuse = write_int(BRIGHTNESS_DEV, br)) { + io::eprintfn("Error writing to brightness device %s: %s", BRIGHTNESS_DEV, excuse); + return 1; } // try reading from the actual brightness device if (catch excuse = read_int(ACTUAL_BRIGHTNESS_DEV)) { io::eprintfn("Error reading from %s: %s", ACTUAL_BRIGHTNESS_DEV, excuse); - thread::exit(1); + return 1; } int x = get_luminance_raw() ?? MAX_LUMINANCE; @@ -160,19 +163,19 @@ fn int main() thread::sleep_ms(SLEEP_DELAY); // read actual brightness to get the user offset - int! actual_brightness; + int actual_brightness; int off; - actual_brightness = read_int(ACTUAL_BRIGHTNESS_DEV); - if (catch excuse = actual_brightness) { + tmp = read_int(ACTUAL_BRIGHTNESS_DEV); + actual_brightness = tmp ?? brightness_adjusted; + if (catch excuse = tmp) { io::eprintfn("Error reading actual brightness: %s", excuse); - actual_brightness = brightness_adjusted; } // if the actual brightness is zero, it means that the screen is turned // off for some reason, usually DPMS. As such it should not count for user // offset. Look at the TODO file. - if (actual_brightness!! != 0) { - off = actual_brightness!! - brightness_target; + if (actual_brightness != 0) { + off = actual_brightness - brightness_target; if (brightness_target != max_brightness || off < 0){ user_offset = off; }