@@ -96,6 +96,19 @@ def raw_value(self):
96
96
"""The raw touch measurement."""
97
97
return self ._mpr121 .filtered_data (self ._channel )
98
98
99
+ @property
100
+ def thresholds (self ):
101
+ """The touch / release threholds."""
102
+ buf = bytearray (2 )
103
+ self ._mpr121 ._read_register_bytes (MPR121_TOUCHTH_0 + 2 * self ._channel , buf , 2 )
104
+ return (buf [0 ], buf [1 ])
105
+
106
+ @thresholds .setter
107
+ def thresholds (self , value ):
108
+ touch , release = value
109
+ self ._mpr121 ._write_register_byte (MPR121_TOUCHTH_0 + 2 * self ._channel , touch )
110
+ self ._mpr121 ._write_register_byte (MPR121_RELEASETH_0 + 2 * self ._channel , release )
111
+
99
112
class MPR121 :
100
113
"""Driver for the MPR121 capacitive touch breakout board."""
101
114
@@ -118,6 +131,18 @@ def touched_pins(self):
118
131
touched = self .touched ()
119
132
return tuple ([bool (touched >> i & 0x01 ) for i in range (12 )])
120
133
134
+ @property
135
+ def thresholds (self ):
136
+ """The touch / release threholds for all channels."""
137
+ buf = bytearray (24 )
138
+ self ._read_register_bytes (MPR121_TOUCHTH_0 , buf , 24 )
139
+ return tuple ( [ (buf [2 * i ], buf [2 * i + 1 ]) for i in range (12 ) ] )
140
+
141
+ @thresholds .setter
142
+ def thresholds (self , value ):
143
+ touch , release = value
144
+ self .set_thresholds (touch , release )
145
+
121
146
def _write_register_byte (self , register , value ):
122
147
# Write a byte value to the specifier register address.
123
148
# MPR121 must be put in Stop Mode to write to most registers
0 commit comments