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
@@ -65,12 +72,12 @@ class ServoKit:
65
72
def __init__ (
66
73
self ,
67
74
* ,
68
- channels ,
69
- i2c = None ,
70
- address = 0x40 ,
71
- reference_clock_speed = 25000000 ,
72
- frequency = 50
73
- ):
75
+ channels : int ,
76
+ i2c : Optional [ I2C ] = None ,
77
+ address : int = 0x40 ,
78
+ reference_clock_speed : int = 25000000 ,
79
+ frequency : int = 50
80
+ ) -> None :
74
81
if channels not in [8 , 16 ]:
75
82
raise ValueError ("servo_channels must be 8 or 16!" )
76
83
self ._items = [None ] * channels
@@ -86,7 +93,7 @@ def __init__(
86
93
self ._continuous_servo = _ContinuousServo (self )
87
94
88
95
@property
89
- def servo (self ):
96
+ def servo (self ) -> "_Servo" :
90
97
""":class:`~adafruit_motor.servo.Servo` controls for standard servos.
91
98
92
99
This FeatherWing example rotates a servo on channel ``0`` to ``180`` degrees for one second,
@@ -107,7 +114,7 @@ def servo(self):
107
114
return self ._servo
108
115
109
116
@property
110
- def continuous_servo (self ):
117
+ def continuous_servo (self ) -> "_ContinuousServo" :
111
118
""":class:`~adafruit_motor.servo.ContinuousServo` controls for continuous rotation
112
119
servos.
113
120
@@ -133,10 +140,10 @@ def continuous_servo(self):
133
140
134
141
class _Servo :
135
142
# pylint: disable=protected-access
136
- def __init__ (self , kit ) :
143
+ def __init__ (self , kit : ServoKit ) -> None :
137
144
self .kit = kit
138
145
139
- def __getitem__ (self , servo_channel ) :
146
+ def __getitem__ (self , servo_channel : int ) -> Servo :
140
147
import adafruit_motor .servo # pylint: disable=import-outside-toplevel
141
148
142
149
num_channels = self .kit ._channels
@@ -151,16 +158,16 @@ def __getitem__(self, servo_channel):
151
158
return servo
152
159
raise ValueError ("Channel {} is already in use." .format (servo_channel ))
153
160
154
- def __len__ (self ):
161
+ def __len__ (self ) -> int :
155
162
return len (self .kit ._items )
156
163
157
164
158
165
class _ContinuousServo :
159
166
# pylint: disable=protected-access
160
- def __init__ (self , kit ) :
167
+ def __init__ (self , kit : ServoKit ) -> None :
161
168
self .kit = kit
162
169
163
- def __getitem__ (self , servo_channel ) :
170
+ def __getitem__ (self , servo_channel : int ) -> ContinuousServo :
164
171
import adafruit_motor .servo # pylint: disable=import-outside-toplevel
165
172
166
173
num_channels = self .kit ._channels
@@ -179,5 +186,5 @@ def __getitem__(self, servo_channel):
179
186
return servo
180
187
raise ValueError ("Channel {} is already in use." .format (servo_channel ))
181
188
182
- def __len__ (self ):
189
+ def __len__ (self ) -> int :
183
190
return len (self .kit ._items )
0 commit comments