12
12
* Author(s): Scott Shawcroft
13
13
"""
14
14
15
+ try :
16
+ from typing import Optional
17
+ from pwmio import PWMOut
18
+ except ImportError :
19
+ pass
20
+
21
+
15
22
__version__ = "0.0.0-auto.0"
16
23
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Motor.git"
17
24
@@ -24,11 +31,11 @@ class _BaseServo: # pylint: disable-msg=too-few-public-methods
24
31
:param int min_pulse: The minimum pulse length of the servo in microseconds.
25
32
:param int max_pulse: The maximum pulse length of the servo in microseconds."""
26
33
27
- def __init__ (self , pwm_out , * , min_pulse = 750 , max_pulse = 2250 ):
34
+ def __init__ (self , pwm_out : PWMOut , * , min_pulse : int = 750 , max_pulse : int = 2250 ):
28
35
self ._pwm_out = pwm_out
29
36
self .set_pulse_width_range (min_pulse , max_pulse )
30
37
31
- def set_pulse_width_range (self , min_pulse = 750 , max_pulse = 2250 ):
38
+ def set_pulse_width_range (self , min_pulse : int = 750 , max_pulse : int = 2250 ):
32
39
"""Change min and max pulse widths."""
33
40
self ._min_duty = int ((min_pulse * self ._pwm_out .frequency ) / 1000000 * 0xFFFF )
34
41
max_duty = (max_pulse * self ._pwm_out .frequency ) / 1000000 * 0xFFFF
@@ -45,7 +52,7 @@ def fraction(self):
45
52
return (self ._pwm_out .duty_cycle - self ._min_duty ) / self ._duty_range
46
53
47
54
@fraction .setter
48
- def fraction (self , value ):
55
+ def fraction (self , value : Optional [ float ] ):
49
56
if value is None :
50
57
self ._pwm_out .duty_cycle = 0 # disable the motor
51
58
return
@@ -85,7 +92,7 @@ class Servo(_BaseServo):
85
92
Test carefully to find the safe minimum and maximum.
86
93
"""
87
94
88
- def __init__ (self , pwm_out , * , actuation_range = 180 , min_pulse = 750 , max_pulse = 2250 ):
95
+ def __init__ (self , pwm_out : PWMOut , * , actuation_range : int = 180 , min_pulse : int = 750 , max_pulse : int = 2250 ):
89
96
super ().__init__ (pwm_out , min_pulse = min_pulse , max_pulse = max_pulse )
90
97
self .actuation_range = actuation_range
91
98
"""The physical range of motion of the servo in degrees."""
@@ -100,7 +107,7 @@ def angle(self):
100
107
return self .actuation_range * self .fraction
101
108
102
109
@angle .setter
103
- def angle (self , new_angle ):
110
+ def angle (self , new_angle : Optional [ int ] ):
104
111
if new_angle is None : # disable the servo by sending 0 signal
105
112
self .fraction = None
106
113
return
@@ -123,7 +130,7 @@ def throttle(self):
123
130
return self .fraction * 2 - 1
124
131
125
132
@throttle .setter
126
- def throttle (self , value ):
133
+ def throttle (self , value : float ):
127
134
if value > 1.0 or value < - 1.0 :
128
135
raise ValueError ("Throttle must be between -1.0 and 1.0" )
129
136
if value is None :
0 commit comments