Просмотр исходного кода

tweak formula for prototype client

Thomas B 3 месяцев назад
Родитель
Сommit
6fcab3b981
2 измененных файлов: 9 добавлений и 9 удалений
  1. 5
    5
      client/brightness.py
  2. 4
    4
      client/ddc.py

+ 5
- 5
client/brightness.py Просмотреть файл

@@ -6,8 +6,7 @@ import time
6 6
 
7 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 10
 calibration = {
12 11
     "HPN:HP 27xq:CNK1072BJY": [
13 12
         1.0, 30.0, # out_a, out_b
@@ -19,7 +18,8 @@ calibration = {
19 18
 }
20 19
 
21 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 24
 def filter_lux(old, new):
25 25
     return (old * filter_fact) + (new * (1.0 - filter_fact))
@@ -45,7 +45,7 @@ if __name__ == "__main__":
45 45
         print("Display \"{}\" at {}".format(d["name"], d["prev"]))
46 46
 
47 47
     print()
48
-    print("Starting main loop")
48
+    print("{}: Starting main loop".format(time.ctime()))
49 49
     print()
50 50
 
51 51
     while True:
@@ -55,7 +55,7 @@ if __name__ == "__main__":
55 55
             val = lux_to_disp(d["name"], brightness)
56 56
             if val != d["prev"]:
57 57
                 d["prev"] = val
58
-                print("Setting \"{}\" to {}".format(d["name"], val))
58
+                print("{}: Setting \"{}\" to {}".format(time.ctime(), d["name"], val))
59 59
                 ddc.ddc_set(d["id"], val)
60 60
 
61 61
         time.sleep(1.0)

+ 4
- 4
client/ddc.py Просмотреть файл

@@ -5,7 +5,7 @@ import subprocess
5 5
 def ddc_detect():
6 6
     r = subprocess.run(["ddcutil", "detect", "-t"], capture_output=True)
7 7
     if r.returncode != 0:
8
-        raise ValueError("ddcutil returned {}".format(r.returncode))
8
+        raise ValueError("ddcutil returned {} \"{}\"".format(r.returncode))
9 9
 
10 10
     out = []
11 11
 
@@ -38,11 +38,11 @@ def ddc_detect():
38 38
 def ddc_get(dev):
39 39
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "getvcp", "10"], capture_output=True)
40 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 43
     s = r.stdout.decode("utf-8").split()
44 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 47
     return int(s[3])
48 48
 
@@ -53,7 +53,7 @@ def ddc_set(dev, val):
53 53
 
54 54
     r = subprocess.run(["ddcutil", "-d", str(dev), "-t", "setvcp", "10", str(val)], capture_output=True)
55 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 58
 if __name__ == "__main__":
59 59
     devs = ddc_detect()

Загрузка…
Отмена
Сохранить