forked from brokenmass/AIOLCDUnchained
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (28 loc) · 906 Bytes
/
util.py
File metadata and controls
32 lines (28 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Gracefully taken from liquidctl
def normalizeProfile(profile, critx, max_value=100):
profile = sorted(list(profile) + [(critx, max_value)], key=lambda p: (p[0], -p[1]))
mono = profile[0:1]
for (x, y), (xb, yb) in zip(profile[1:], profile[:-1]):
if x == xb:
continue
if y < yb:
y = yb
mono.append((x, y))
if y == max_value:
break
return mono
def interpolateProfile(profile, x):
lower, upper = profile[0], profile[-1]
for step in profile:
if step[0] <= x:
lower = step
if step[0] >= x:
upper = step
break
if lower[0] == upper[0]:
return lower[1]
return round(lower[1] + (x - lower[0])/(upper[0] - lower[0])*(upper[1] - lower[1]))
def clamp(value, clampmin, clampmax):
clamped = max(clampmin, min(clampmax, value))
return clamped
# ---