8000 Add PEP484 type hints · robotpy/robotpy-wpilib@ecdef81 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit ecdef81

Browse files
committed
Add PEP484 type hints
1 parent 0b0285f commit ecdef81

File tree

110 files changed

+1157
-1307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1157
-1307
lines changed

wpilib/wpilib/adxl345_i2c.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# must be accompanied by the FIRST BSD license file in the root directory of
66
# the project.
77
#----------------------------------------------------------------------------
8+
from typing import Tuple
89

910
import hal
10-
11-
from .interfaces import Accelerometer
1211
from .i2c import I2C
12+
from .interfaces import Accelerometer
13+
from .sendablebuilder import SendableBuilder
1314
from .sensorbase import SensorBase
1415

1516
__all__ = ["ADXL345_I2C"]
@@ -43,13 +44,11 @@ class Axes:
4344
kY = 0x02
4445
kZ = 0x04
4546

46-
def __init__(self, port, range, address=None):
47+
def __init__(self, port: I2C.Port, range: Range, address: int = None) -> None:
4748
"""Constructor.
4849
4950
:param port: The I2C port the accelerometer is attached to.
50-
:type port: :class:`.I2C.Port`
5151
:param range: The range (+ or -) that the accelerometer will measure.
52-
:type range: :class:`.ADXL345_I2C.Range`
5352
:param address: the I2C address of the accelerometer (0x1D or 0x53)
5453
"""
5554
if address is None:
@@ -67,18 +66,17 @@ def __init__(self, port, range, address=None):
6766

6867
self.setName("ADXL345_I2C", < F438 span class=pl-s1>port)
6968

70-
def free(self):
69+
def free(self) -> None:
7170
self.i2c.free()
7271
super().free()
7372

7473
# Accelerometer interface
7574

76-
def setRange(self, range):
75+
def setRange(self, range: Range) -> None:
7776
"""Set the measuring range of the accelerometer.
7877
7978
:param range: The maximum acceleration, positive or negative, that
8079
the accelerometer will measure.
81-
:type range: :class:`ADXL345_I2C.Range`
8280
"""
8381
if range == self.Range.k2G:
8482
value = 0
@@ -94,28 +92,28 @@ def setRange(self, range):
9492
# Specify the data format to read
9593
self.i2c.write(self.kDataFormatRegister, self.kDataFormat_FullRes | value)
9694

97-
def getX(self):
95+
def getX(self) -> float:
9896
"""Get the x axis acceleration
9997
10098
:returns: The acceleration along the x axis in g-forces
10199
"""
102100
return self.getAcceleration(self.Axes.kX)
103101

104-
def getY(self):
102+
def getY(self) -> float:
105103
"""Get the y axis acceleration
106104
107105
:returns: The acceleration along the y axis in g-forces
108106
"""
109107
return self.getAcceleration(self.Axes.kY)
110108

111-
def getZ(self):
109+
def getZ(self) -> float:
112110
"""Get the z axis acceleration
113111
114112
:returns: The acceleration along the z axis in g-forces
115113
"""
116114
return self.getAcceleration(self.Axes.kZ)
117115

118-
def getAcceleration(self, axis):
116+
def getAcceleration(self, axis: Axes) -> float:
119117
"""Get the acceleration of one axis in Gs.
120118
121119
:param axis: The axis to read from.
@@ -126,7 +124,7 @@ def getAcceleration(self, axis):
126124
rawAccel = (data[1] << 8) | data[0]
127125
return rawAccel * self.kGsPerLSB
128126

129-
def getAccelerations(self):
127+
def getAccelerations(self) -> Tuple[float, float, float]:
130128
"""Get the acceleration of all axes in Gs.
131129
132130
:returns: X,Y,Z tuple of acceleration measured on all axes of the
@@ -144,13 +142,13 @@ def getAccelerations(self):
144142
rawData[2] * self.kGsPerLSB)
145143

146144

147-
def _updateValues(self):
145+
def _updateValues(self) -> None:
148146
data = self.getAccelerations()
149147
self._entryX.setDouble(data[0])
150148
self._entryY.setDouble(data[1])
151149
self._entryZ.setDouble(data[2])
152150

153-
def initSendable(self, builder):
151+
def initSendable(self, builder: SendableBuilder) -> None:
154152
builder.setSmartDashboardType("3AxisAccelerometer")
155153
self._entryX = builder.getEntry("X")
156154
self._entryY = builder.getEntry("Y")

wpilib/wpilib/adxl345_spi.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
# must be accompanied by the FIRST BSD license file in the root directory of
66
# the project.
77
#----------------------------------------------------------------------------
8+
from typing import Tuple
89

910
import hal
1011

1112
from .interfaces import Accelerometer
1213
from .spi import SPI
14+
from .sendablebuilder import SendableBuilder
1315
from .sensorbase import SensorBase
1416

1517
__all__ = ["ADXL345_SPI"]
@@ -47,14 +49,12 @@ class Axes:
4749
kY = 0x02
4850
kZ = 0x04
4951

50-
def __init__(self, port, range):
52+
def __init__(self, port: SPI.Port, range: Range) -> None:
5153
"""Constructor. Use this when the device is the first/only device on
5254
the bus
5355
5456
:param port: The SPI port that the accelerometer is connected to
55-
:type port: :class:`.SPI.Port`
5657
:param range: The range (+ or -) that the accelerometer will measure.
57-
:type range: :class:`.ADXL345_SPI.Range`
5858
"""
5959
self.spi = SPI(port)
6060
self.spi.setClockRate(500000)
@@ -73,18 +73,17 @@ def __init__(self, port, range):
7373

7474
self.setName("ADXL345_SPI", port)
7575

76-
def free(self):
76+
def free(self) -> None:
7777
self.spi.free()
7878
super().free()
7979

8080
# Accelerometer interface
8181

82-
def setRange(self, range):
82+
def setRange(self, range: Range) -> None:
8383
"""Set the measuring range of the accelerometer.
8484
8585
:param range: The maximum acceleration, positive or negative, that
8686
the accelerometer will measure.
87-
:type range: :class:`ADXL345_SPI.Range`
8887
"""
8988
if range == self.Range.k2G:
9089
value = 0
@@ -100,28 +99,28 @@ def setRange(self, range):
10099
self.spi.write([self.kDataFormatRegister,
101100
self.kDataFormat_FullRes | value])
102101

103-
def getX(self):
102+
def getX(self) -> float:
104103
"""Get the x axis acceleration
105104
106105
:returns: The acceleration along the x axis in g-forces
107106
"""
108107
return self.getAcceleration(self.Axes.kX)
109108

110-
def getY(self):
109+
def getY(self) -> float:
111110
"""Get the y axis acceleration
112111
113112
:returns: The acceleration along the y axis in g-forces
114113
"""
115114
return self.getAcceleration(self.Axes.kY)
116115

117-
def getZ(self):
116+
def getZ(self) -> float:
118117
"""Get the z axis acceleration
119118
120119
:returns: The acceleration along the z axis in g-forces
121120
"""
122121
return self.getAcceleration(self.Axes.kZ)
123122

124-
def getAcceleration(self, axis):
123+
def getAcceleration(self, axis: Axes) -> float:
125124
"""Get the acceleration of one axis in Gs.
126125
127126
:param axis: The axis to read from.
@@ -134,7 +133,7 @@ def getAcceleration(self, axis):
134133
rawAccel = (data[2] << 8) | data[1]
135134
return rawAccel * self.kGsPerLSB
136135

137-
def getAccelerations(self):
136+
def getAccelerations(self) -> Tuple[float, float, float]:
138137
"""Get the acceleration of all axes in Gs.
139138
140139
:returns: X,Y,Z tuple of acceleration measured on all axes of the
@@ -156,13 +155,13 @@ def getAccelerations(self):
156155
rawData[2] * self.kGsPerLSB)
157156

158157
# Live Window code, only does anything if live window is activated.
159-
def _updateValues(self):
158+
def _updateValues(self) -> None:
160159
data = self.getAccelerations()
161160
self._entryX.setDouble(data[0])
162161
self._entryY.setDouble(data[1])
163162
self._entryZ.setDouble(data[2])
164163

165-
def initSendable(self, builder):
164+
def initSendable(self, builder: SendableBuilder) -> None:
166165
builder.setSmartDashboardType("3AxisAccelerometer")
167166
self._entryX = builder.getEntry("X")
168167
self._entryY = builder.getEntry("Y")

wpilib/wpilib/adxl362.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
# must be accompanied by the FIRST BSD license file in the root directory of
66
# the project.
77
#----------------------------------------------------------------------------
8+
from typing import Tuple
89

910
import hal
1011

1112
from .driverstation import DriverStation
1213
from .interfaces import Accelerometer
1314
from .spi import SPI
15+
from .sendablebuilder import SendableBuilder
1416
from .sensorbase import SensorBase
1517

1618
__all__ = ["ADXL362"]
@@ -48,13 +50,11 @@ class Axes:
4850
kY = 0x02
4951
kZ = 0x04
5052

51-
def __init__(self, range, port=None):
53+
def __init__(self, range: Range, port: SPI.Port = None) -> None:
5254
"""Constructor.
5355
5456
:param range: The range (+ or -) that the accelerometer will measure.
55-
:type range: :class:`.ADXL362.Range`
5657
:param port: The SPI port that the accelerometer is connected to
57-
:type port: :class:`.SPI.Port`
5858
"""
5959
if port is None:
6060
port = SPI.Port.kOnboardCS1
@@ -86,20 +86,19 @@ def __init__(self, range, port=None):
8686

8787
self.setName("ADXL362", port)
8888

89-
def free(self):
89+
def free(self) -> None:
9090
if self.spi:
9191
self.spi.free()
9292
self.spi = None
9393
super().free()
9494

9595
# Accelerometer interface
9696

97-
def setRange(self, range):
97+
def setRange(self, range: Range) -> None:
9898
"""Set the measuring range of the accelerometer.
9999
100100
:param range: The maximum acceleration, positive or negative, that
101101
the accelerometer will measure.
102-
:type range: :class:`ADXL362.Range`
103102
"""
104103
if not self.spi:
105104
return
@@ -121,28 +120,28 @@ def setRange(self, range):
121120
self.spi.write([self.kRegWrite, self.kFilterCtlRegister,
122121
self.kFilterCtl_ODR_100Hz | value])
123122

124-
def getX(self):
123+
def getX(self) -> float:
125124
"""Get the x axis acceleration
126125
127126
:returns: The acceleration along the x axis in g-forces
128127
"""
129128
return self.getAcceleration(self.Axes.kX)
130129

131-
def getY(self):
130+
def getY(self) -> float:
132131
"""Get the y axis acceleration
133132
134133
:returns: The acceleration along the y axis in g-forces
135134
"""
136135
return self.getAcceleration(self.Axes.kY)
137136

138-
def getZ(self):
137+
def getZ(self) -> float:
139138
"""Get the z axis acceleration
140139
141140
:returns: The acceleration along the z axis in g-forces
142141
"""
143142
return self.getAcceleration(self.Axes.kZ)
144143

145-
def getAcceleration(self, axis):
144+
def getAcceleration(self, axis: Axes) -> float:
146145
"""Get the acceleration of one axis in Gs.
147146
148147
:param axis: The axis to read from.
@@ -158,7 +157,7 @@ def getAcceleration(self, axis):
158157
rawAccel = (data[2] << 8) | data[1]
159158
return rawAccel * self.gsPerLSB
160159

161-
def getAccelerations(self):
160+
def getAccelerations(self) -> Tuple[float, float, float]:
162161
"""Get the acceleration of all axes in Gs.
163162
164163
:returns: X,Y,Z tuple of acceleration measured on all axes in Gs.
@@ -181,13 +180,13 @@ def getAccelerations(self):
181180
rawData[1] * self.gsPerLSB,
182181
rawData[2] * self.gsPerLSB)
183182

184-
def _updateValues(self):
183+
def _updateValues(self) -> None:
185184
data = self.getAccelerations()
186185
self._entryX.setDouble(data[0])
187186
self._entryY.setDouble(data[1])
188187
self._entryZ.setDouble(data[2])
189188

190-
def initSendable(self, builder):
189+
def initSendable(self, builder: SendableBuilder) -> None:
191190
builder.setSmartDashboardType("3AxisAccelerometer")
192191
self._entryX = builder.getEntry("X")
193192
self._entryY = builder.getEntry("Y")

0 commit comments

Comments
 (0)
0