35
35
import board
36
36
from adafruit_pca9685 import PCA9685
37
37
38
+ try :
39
+ from typing import Optional
40
+ from busio import I2C
41
+ from adafruit_motor .servo import Servo , ContinuousServo
42
+ except ImportError :
43
+ pass
44
+
38
45
__version__ = "0.0.0-auto.0"
39
46
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ServoKit.git"
40
47
@@ -54,6 +61,8 @@ class ServoKit:
54
61
55
62
:param int channels: The number of servo channels available. Must be 8 or 16. The FeatherWing
56
63
has 8 channels. The Shield, HAT, and Bonnet have 16 channels.
64
+ :param ~I2C i2c: The I2C bus to use. If not provided, it will use generate the default I2C
65
+ bus singleton ``busio.I2C()`` and use that.
57
66
:param int address: The I2C address of the PCA9685. Default address is ``0x40``.
58
67
:param int reference_clock_speed: The frequency of the internal reference clock in Hertz.
59
68
Default reference clock speed is ``25000000``.
@@ -65,12 +74,12 @@ class ServoKit:
65
74
def __init__ (
66
75
self ,
67
76
* ,
68
- channels ,
69
- i2c = None ,
70
- address = 0x40 ,
71
- reference_clock_speed = 25000000 ,
72
- frequency = 50
73
- ):
77
+ channels : int ,
78
+ i2c : Optional [ I2C ] = None ,
79
+ address : int = 0x40 ,
80
+ reference_clock_speed : int = 25000000 ,
81
+ frequency : int = 50
82
+ ) -> None :
74
83
if channels not in [8 , 16 ]:
75
84
raise ValueError ("servo_channels must be 8 or 16!" )
76
85
self ._items = [None ] * channels
@@ -86,7 +95,7 @@ def __init__(
86
95
self ._continuous_servo = _ContinuousServo (self )
87
96
88
97
@property
89
- def servo (self ):
98
+ def servo (self ) -> "_Servo" :
90
99
""":class:`~adafruit_motor.servo.Servo` controls for standard servos.
91
100
92
101
This FeatherWing example rotates a servo on channel ``0`` to ``180`` degrees for one second,
@@ -107,7 +116,7 @@ def servo(self):
107
116
return self ._servo
108
117
109
118
@property
110
- def continuous_servo (self ):
119
+ def continuous_servo (self ) -> "_ContinuousServo" :
111
120
""":class:`~adafruit_motor.servo.ContinuousServo` controls for continuous rotation
112
121
servos.
113
122
@@ -133,10 +142,10 @@ def continuous_servo(self):
133
142
134
143
class _Servo :
135
144
# pylint: disable=protected-access
136
- def __init__ (self , kit ) :
145
+ def __init__ (self , kit : ServoKit ) -> None :
137
146
self .kit = kit
138
147
139
- def __getitem__ (self , servo_channel ) :
148
+ def __getitem__ (self , servo_channel : int ) -> Servo :
140
149
import adafruit_motor .servo # pylint: disable=import-outside-toplevel
141
150
142
151
num_channels = self .kit ._channels
@@ -151,16 +160,16 @@ def __getitem__(self, servo_channel):
151
160
return servo
152
161
raise ValueError ("Channel {} is already in use." .format (servo_channel ))
153
162
154
- def __len__ (self ):
163
+ def __len__ (self ) -> int :
155
164
return len (self .kit ._items )
156
165
157
166
158
167
class _ContinuousServo :
159
168
# pylint: disable=protected-access
160
- def __init__ (self , kit ) :
169
+ def __init__ (self , kit : ServoKit ) -> None :
161
170
self .kit = kit
162
171
163
- def __getitem__ (self , servo_channel ) :
172
+ def __getitem__ (self , servo_channel : int ) -> ContinuousServo :
164
173
import adafruit_motor .servo # pylint: disable=import-outside-toplevel
165
174
166
175
num_channels = self .kit ._channels
@@ -179,5 +188,5 @@ def __getitem__(self, servo_channel):
179
188
return servo
180
189
raise ValueError ("Channel {} is already in use." .format (servo_channel ))
181
190
182
- def __len__ (self ):
191
+ def __len__ (self ) -> int :
183
192
return len (self .kit ._items )
0 commit comments