21
21
# THE SOFTWARE.
22
22
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
23
23
24
- from micropython import const
24
+ """
25
+ `adafruit_seesaw.keypad`
26
+ ====================================================
27
+ """
28
+
29
+ try :
30
+ from micropython import const
31
+ except ImportError :
32
+ def const (x ):
33
+ return x
25
34
from adafruit_seesaw .seesaw import Seesaw
26
35
27
36
__version__ = "0.0.0-auto.0"
38
47
39
48
# pylint: disable=too-few-public-methods
40
49
class KeyEvent :
50
+ """Holds information about a key event in its properties
51
+
52
+ :param int num: The number of the key
53
+ :param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad`
54
+ """
41
55
def __init__ (self , num , edge ):
42
56
self .number = int (num )
43
57
self .edge = int (edge )
44
58
# pylint: enable=too-few-public-methods
45
59
46
60
class Keypad (Seesaw ):
61
+ """On compatible SeeSaw devices, reads from a keypad.
62
+
63
+ :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to
64
+ :param int addr: I2C address of the SeeSaw device
65
+ :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output"""
47
66
67
+ #: Indicates that the key is currently pressed
48
68
EDGE_HIGH = 0
69
+ #: Indicates that the key is currently released
49
70
EDGE_LOW = 1
71
+ #: Indicates that the key was recently pressed
50
72
EDGE_FALLING = 2
73
+ #: Indicates that the key was recently released
51
74
EDGE_RISING = 3
52
75
53
76
def __init__ (self , i2c_bus , addr = 0x49 , drdy = None ):
@@ -56,6 +79,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None):
56
79
57
80
@property
58
81
def interrupt_enabled (self ):
82
+ """Retrieve or set the interrupt enable flag"""
59
83
return self ._interrupt_enabled
60
84
61
85
@interrupt_enabled .setter
@@ -71,6 +95,7 @@ def interrupt_enabled(self, value):
71
95
72
96
@property
73
97
def count (self ):
98
+ """Retrieve or set the number of keys"""
74
99
return self .read8 (_KEYPAD_BASE , _KEYPAD_COUNT )
75
100
76
101
# pylint: disable=unused-argument, no-self-use
@@ -80,6 +105,12 @@ def count(self, value):
80
105
# pylint: enable=unused-argument, no-self-use
81
106
82
107
def set_event (self , key , edge , enable ):
108
+ """Control which kinds of events are set
109
+
110
+ :param int key: The key number
111
+ :param int edge: The type of event
112
+ :param bool enable: True to enable the event, False to disable it"""
113
+
83
114
if enable not in (True , False ):
84
115
raise ValueError ("event enable must be True or False" )
85
116
if edge > 3 or edge < 0 :
@@ -92,6 +123,9 @@ def set_event(self, key, edge, enable):
92
123
self .write (_KEYPAD_BASE , _KEYPAD_EVENT , cmd )
93
124
94
125
def read_keypad (self , num ):
126
+ """Read data from the keypad
127
+
128
+ :param int num: The number of bytes to read"""
95
129
ret = bytearray (num )
96
130
self .read (_KEYPAD_BASE , _KEYPAD_FIFO , ret )
97
131
return ret
0 commit comments