48
48
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CAP1188.git"
49
49
50
50
# pylint: disable=bad-whitespace
51
+ CAP1188_MID = const (0x5D )
52
+ CAP1188_PID = const (0x50 )
51
53
CAP1188_MAIN_CONTROL = const (0x00 )
52
54
CAP1188_GENERAL_STATUS = const (0x02 )
53
55
CAP1188_INPUT_STATUS = const (0x03 )
@@ -95,6 +97,12 @@ def recalibrate(self):
95
97
class CAP1188 :
96
98
"""CAP1188 driver base, must be extended for I2C/SPI interfacing."""
97
99
def __init__ (self ):
100
+ mid = self ._read_register (CAP1188_MANU_ID )
101
+ if mid != CAP1188_MID :
102
+ raise RuntimeError ('Failed to find CAP1188! Manufacturer ID: 0x{:02x}' .format (mid ))
103
+ pid = self ._read_register (CAP1188_PRODUCT_ID )
104
+ if pid != CAP1188_PID :
105
+ raise RuntimeError ('Failed to find CAP1188! Product ID: 0x{:02x}' .format (pid ))
98
106
self ._channels = [None ]* 8
99
107
self ._write_register (CAP1188_LED_LINKING , 0xFF ) # turn on LED linking
100
108
self ._write_register (CAP1188_MULTI_TOUCH_CFG , 0x00 ) # allow multi touch
@@ -109,21 +117,6 @@ def __getitem__(self, key):
109
117
self ._channels [index ] = CAP1188_Channel (self , pin )
110
118
return self ._channels [index ]
111
119
112
- @property
113
- def product_id (self ):
114
- """The product ID."""
115
- return self ._read_register (CAP1188_PRODUCT_ID )
116
-
117
- @property
118
- def manufacturer_id (self ):
119
- """The manufacturer ID."""
120
- return self ._read_register (CAP1188_MANU_ID )
121
-
122
- @property
123
- def revision (self ):
124
- """The revision number."""
125
- return self ._read_register (CAP1188_REVISION )
126
-
127
120
@property
128
121
def touched_pins (self ):
129
122
"""A tuple of touched state for all pins."""
@@ -146,7 +139,10 @@ def delta_count(self, pin):
146
139
"""Return the 8 bit delta count value for the channel."""
147
140
if pin < 1 or pin > 8 :
148
141
raise IndexError ('Pin must be a value 1-8.' )
149
- return self ._read_register (CAP1188_DELTA_COUNT [pin - 1 ])
142
+ # 8 bit 2's complement
143
+ raw_value = self ._read_register (CAP1188_DELTA_COUNT [pin - 1 ])
144
+ raw_value = raw_value - 256 if raw_value & 128 else raw_value
145
+ return raw_value
150
146
151
147
def recalibrate_pins (self , mask ):
152
148
"""Recalibrate pins specified by bit mask."""
0 commit comments