From ad7363a888515a8bb6ce121477acd7dfe800b427 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 25 May 2021 14:58:02 -0700 Subject: [PATCH 1/2] update slider --- adafruit_funhouse/peripherals.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 30d14b9..41aaa61 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -179,15 +179,11 @@ def slider(self): Return the slider position value in the range of 0.0-1.0 or None if not touched """ val = 0 - cap_map = b"\x01\x03\x02\x06\x04\x0c\x08\x18\x10" + cap_map = (0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18, 0x10) for cap in range(5): if self._ctp[cap + 3].value: val += 1 << (cap) - for i, pos in enumerate(tuple(cap_map)): - if val == pos: - print(i, len(cap_map) - 1) - return round(i / (len(cap_map) - 1), 1) - return None + return cap_map.index(val) / 8 if val in cap_map else None @property def light(self): From 6f6dc7d666ea2bf0d3e4bc3f29ddc6ed8ff91f34 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 25 May 2021 18:00:55 -0700 Subject: [PATCH 2/2] black --- adafruit_funhouse/peripherals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_funhouse/peripherals.py b/adafruit_funhouse/peripherals.py index 41aaa61..3ea876a 100755 --- a/adafruit_funhouse/peripherals.py +++ b/adafruit_funhouse/peripherals.py @@ -179,7 +179,7 @@ def slider(self): Return the slider position value in the range of 0.0-1.0 or None if not touched """ val = 0 - cap_map = (0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18, 0x10) + cap_map = (0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x18, 0x10) for cap in range(5): if self._ctp[cap + 3].value: val += 1 << (cap)