diff options
author | dianshi <dianshi@main.lv> | 2020-07-18 22:18:41 +0100 |
---|---|---|
committer | dianshi <dianshi@main.lv> | 2020-07-18 22:18:41 +0100 |
commit | 8fb35efbfd14e38ed1f6b369b4ef879f2d8de73c (patch) | |
tree | ff63c1015553778119deb8aead76e4b264abf863 /obacklight/obacklight.ml | |
parent | e00d2439c9a327198845303d293fb0e0a4a4439f (diff) | |
download | osystem-8fb35efbfd14e38ed1f6b369b4ef879f2d8de73c.tar.gz osystem-8fb35efbfd14e38ed1f6b369b4ef879f2d8de73c.zip |
Diffstat (limited to 'obacklight/obacklight.ml')
-rw-r--r-- | obacklight/obacklight.ml | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/obacklight/obacklight.ml b/obacklight/obacklight.ml index f5eb296..8edb381 100644 --- a/obacklight/obacklight.ml +++ b/obacklight/obacklight.ml @@ -30,6 +30,39 @@ begin set_backlight_brightness_path () end +let read_data filename = + let ic = open_in filename in + try + let line = input_line ic in + close_in ic; + (line) + with e -> + close_in_noerr ic; + raise e + +let show_brightness () = + let b = read_data !default_backlight_brightness_path in + let mb = read_data !default_backlight_maxbrightness_path in + let _ = Printf.printf "Brightness: %s\n" b in + Printf.printf "Max Brightness: %s\n" mb + +(* Set brightness from 0-100% *) +let write_data filename a = + let oc = open_out filename in + output_string oc a; + close_out oc;; + +let set_brightness brightness_path nv = + let mb = read_data !default_backlight_maxbrightness_path in + let i_mb = int_of_string mb in + let nv_percent =((float_of_int nv) /. 100.0) *. (float_of_int i_mb) in + let _ = Printf.printf "%f\n" nv_percent in + write_data brightness_path (string_of_int (int_of_float nv_percent)) + + + +let arg_num = Array.length Sys.argv + let main = begin @@ -40,7 +73,11 @@ begin let usage_msg = "set backlight value" in let _ = Arg.parse speclist print_endline usage_msg in (* If there is not argument print value of default path *) + if arg_num == 1 then + show_brightness(); (* If there is 1 argument set value to brigthness *) + if arg_num == 2 then + set_brightness !default_backlight_brightness_path (int_of_string Sys.argv.(1)); print_debug (); end |