Browse Source

tweak formula for prototype client

Thomas B 3 months ago
parent
commit
6fcab3b981
2 changed files with 9 additions and 9 deletions
  1. 5
    5
      client/brightness.py
  2. 4
    4
      client/ddc.py

+ 5
- 5
client/brightness.py View File

6
 
6
 
7
 filter_fact = 0.9
7
 filter_fact = 0.9
8
 
8
 
9
-# out = out_b + out_a * in_a * (in_b + in)
10
-c_in = 1.0, -40.0, # in_a, in_b
9
+c_in = 0.6, -60.0, # in_a, in_b
11
 calibration = {
10
 calibration = {
12
     "HPN:HP 27xq:CNK1072BJY": [
11
     "HPN:HP 27xq:CNK1072BJY": [
13
         1.0, 30.0, # out_a, out_b
12
         1.0, 30.0, # out_a, out_b
19
 }
18
 }
20
 
19
 
21
 def cal(v, c):
20
 def cal(v, c):
22
-    return c[1] + c[0] * c_in[0] * (c_in[1] + v)
21
+    # out = out_b + out_a * in_a * max(0, in_b + in)
22
+    return c[1] + c[0] * c_in[0] * max(0, c_in[1] + v)
23
 
23
 
24
 def filter_lux(old, new):
24
 def filter_lux(old, new):
25
     return (old * filter_fact) + (new * (1.0 - filter_fact))
25
     return (old * filter_fact) + (new * (1.0 - filter_fact))
45
         print("Display \"{}\" at {}".format(d["name"], d["prev"]))
45
         print("Display \"{}\" at {}".format(d["name"], d["prev"]))
46
 
46
 
47
     print()
47
     print()
48
-    print("Starting main loop")
48
+    print("{}: Starting main loop".format(time.ctime()))
49
     print()
49
     print()
50
 
50
 
51
     while True:
51
     while True:
55
             val = lux_to_disp(d["name"], brightness)
55
             val = lux_to_disp(d["name"], brightness)
56
             if val != d["prev"]:
56
             if val != d["prev"]:
57
                 d["prev"] = val
57
                 d["prev"] = val
58
-                print("Setting \"{}\" to {}".format(d["name"], val))
58
+                print("{}: Setting \"{}\" to {}".format(time.ctime(), d["name"], val))
59
                 ddc.ddc_set(d["id"], val)
59
                 ddc.ddc_set(d["id"], val)
60
 
60
 
61
         time.sleep(1.0)
61
         time.sleep(1.0)

+ 4
- 4
client/ddc.py View File

5
 def ddc_detect():
5
 def ddc_detect():
6
     r = subprocess.run(["ddcutil", "detect", "-t"], capture_output=True)
6
     r = subprocess.run(["ddcutil", "detect", "-t"], capture_output=True)
7
     if r.returncode != 0:
7
     if r.returncode != 0:
8
-        raise ValueError("ddcutil returned {}".format(r.returncode))
8
+        raise ValueError("ddcutil returned {} \"{}\"".format(r.returncode))
9
 
9
 
10
     out = []
10
     out = []
11
 
11
 
38
 def ddc_get(dev):
38
 def ddc_get(dev):
39
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "getvcp", "10"], capture_output=True)
39
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "getvcp", "10"], capture_output=True)
40
     if r.returncode != 0:
40
     if r.returncode != 0:
41
-        raise ValueError("ddcutil returned {}".format(r.returncode))
41
+        raise ValueError("ddcutil returned {} \"{}\"".format(r.returncode, r.stderr.decode("utf-8")))
42
 
42
 
43
     s = r.stdout.decode("utf-8").split()
43
     s = r.stdout.decode("utf-8").split()
44
     if (s[0] != "VCP") or (s[1] != "10") or (s[2] != "C") or (s[4] != "100"):
44
     if (s[0] != "VCP") or (s[1] != "10") or (s[2] != "C") or (s[4] != "100"):
45
-        raise ValueError("unexpected identifier")
45
+        raise ValueError("unexpected identifier \"{}\"".format(r.stdout.decode("utf-8")))
46
 
46
 
47
     return int(s[3])
47
     return int(s[3])
48
 
48
 
53
 
53
 
54
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "setvcp", "10", str(val)], capture_output=True)
54
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "setvcp", "10", str(val)], capture_output=True)
55
     if r.returncode != 0:
55
     if r.returncode != 0:
56
-        raise ValueError("ddcutil returned {}".format(r.returncode))
56
+        raise ValueError("ddcutil returned {} \"{}\"".format(r.returncode, r.stderr.decode("utf-8")))
57
 
57
 
58
 if __name__ == "__main__":
58
 if __name__ == "__main__":
59
     devs = ddc_detect()
59
     devs = ddc_detect()

Loading…
Cancel
Save