Skip to content

Commit 3b36199

Browse files
committed
Running through black
Signed-off-by: Mike Stitt <[email protected]>
1 parent 7522ec2 commit 3b36199

File tree

2 files changed

+79
-48
lines changed

2 files changed

+79
-48
lines changed

subprojects/robotpy-wpilib/wpilib/iterativerobotpy.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
from enum import Enum
22

3-
from hal import report, tResourceType, tInstances, observeUserProgramDisabled, \
4-
observeUserProgramTest, observeUserProgramAutonomous, \
5-
observeUserProgramTeleop, simPeriodicBefore, simPeriodicAfter
3+
from hal import (
4+
report,
5+
tResourceType,
6+
tInstances,
7+
observeUserProgramDisabled,
8+
observeUserProgramTest,
9+
observeUserProgramAutonomous,
10+
observeUserProgramTeleop,
11+
simPeriodicBefore,
12+
simPeriodicAfter,
13+
)
614
from ntcore import NetworkTableInstance
7-
from wpilib import DriverStation, DSControlWord, Watchdog, LiveWindow, RobotBase, SmartDashboard, reportWarning
15+
from wpilib import (
16+
DriverStation,
17+
DSControlWord,
18+
Watchdog,
19+
LiveWindow,
20+
RobotBase,
21+
SmartDashboard,
22+
reportWarning,
23+
)
824
from wpilib.shuffleboard import Shuffleboard
925

1026
_kResourceType_SmartDashboard = tResourceType.kResourceType_SmartDashboard
1127
_kSmartDashboard_LiveWindow = tInstances.kSmartDashboard_LiveWindow
1228

29+
1330
class IterativeRobotMode(Enum):
1431
kNone = 0
1532
kDisabled = 1
1633
kAutonomous = 2
1734
kTeleop = 3
1835
kTest = 4
1936

37+
2038
class IterativeRobotPy(RobotBase):
2139

2240
def __init__(self, period: float):
@@ -78,33 +96,33 @@ def autonomousPeriodic(self) -> None:
7896
print(f"Default autonomousPeriodic() method...Override me!")
7997
self._autonomousPeriodicHasRun = True
8098

81-
def teleopPeriodic(self)->None:
99+
def teleopPeriodic(self) -> None:
82100
if not self._teleopPeriodicHasRun:
83101
print(f"Default teleopPeriodic() method...Override me!")
84102
self._teleopPeriodicHasRun = True
85103

86-
def testPeriodic(self)->None:
104+
def testPeriodic(self) -> None:
87105
if not self._testPeriodicHasRun:
88106
print(f"Default testPeriodic() method...Override me!")
89107
self._teleopPeriodicHasRun = True
90108

91-
def disabledExit(self)->None:
109+
def disabledExit(self) -> None:
92110
pass
93111

94-
def autonomousExit(self)->None:
112+
def autonomousExit(self) -> None:
95113
pass
96114

97-
def teleopExit(self)->None:
115+
def teleopExit(self) -> None:
98116
pass
99117

100-
def testExit(self)->None:
118+
def testExit(self) -> None:
101119
pass
102120

103121
# todo @Deprecated(forRemoval=true, since="2025")
104-
def setNetworkTablesFlushEnabled(self, enabled: bool)->None:
122+
def setNetworkTablesFlushEnabled(self, enabled: bool) -> None:
105123
self._ntFlushEnabled = enabled
106124

107-
def enableLiveWindowInTest(self, testLW: bool)->None:
125+
def enableLiveWindowInTest(self, testLW: bool) -> None:
108126
if self.isTestEnabled():
109127
raise RuntimeError("Can't configure test mode while in test mode!")
110128
if not self._reportedLw and testLW:
@@ -118,7 +136,7 @@ def isLiveWindowEnabledInTest(self) -> bool:
118136
def getPeriod(self) -> float:
119137
return self._periodS
120138

121-
def loopFunc(self)->None:
139+
def loopFunc(self) -> None:
122140
DriverStation.refreshData()
123141
self.watchdog.reset()
124142

@@ -248,10 +266,8 @@ def loopFunc(self)->None:
248266
if self.watchdog.isExpired():
249267
self.printWatchdogEpochs()
250268

251-
def printLoopOverrunMessage(self)->None:
252-
reportWarning(
253-
f"Loop time of {self.watchdog.getTimeout()}s overrun", False
254-
)
269+
def printLoopOverrunMessage(self) -> None:
270+
reportWarning(f"Loop time of {self.watchdog.getTimeout()}s overrun", False)
255271

256-
def printWatchdogEpochs(self)->None:
272+
def printWatchdogEpochs(self) -> None:
257273
self.watchdog.printEpochs()

subprojects/robotpy-wpilib/wpilib/timedrobotpy.py

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
from typing import Any, Callable, Iterable
22
from heapq import heappush, heappop
3-
from hal import report, initializeNotifier, setNotifierName, observeUserProgramStarting, updateNotifierAlarm, \
4-
waitForNotifierAlarm, stopNotifier, tResourceType, tInstances
3+
from hal import (
4+
report,
5+
initializeNotifier,
6+
setNotifierName,
7+
observeUserProgramStarting,
8+
updateNotifierAlarm,
9+
waitForNotifierAlarm,
10+
stopNotifier,
11+
tResourceType,
12+
tInstances,
13+
)
514
from wpilib import RobotController
615

716
from .iterativerobotpy import IterativeRobotPy
@@ -10,27 +19,24 @@
1019
_kResourceType_Framework = tResourceType.kResourceType_Framework
1120
_kFramework_Timed = tInstances.kFramework_Timed
1221

22+
1323
class _Callback:
14-
def __init__(self, func: Callable[[],None], periodUs: int, expirationUs: int):
24+
def __init__(self, func: Callable[[], None], periodUs: int, expirationUs: int):
1525
self.func = func
1626
self._periodUs = periodUs
1727
self.expirationUs = expirationUs
1828

1929
@classmethod
20-
def makeCallBack(cls,
21-
func: Callable[[],None],
22-
startTimeUs: int,
23-
periodUs: int,
24-
offsetUs: int) -> "_Callback":
25-
26-
callback = _Callback(
27-
func=func,
28-
periodUs=periodUs,
29-
expirationUs=startTimeUs
30-
)
30+
def makeCallBack(
31+
cls, func: Callable[[], None], startTimeUs: int, periodUs: int, offsetUs: int
32+
) -> "_Callback":
33+
34+
callback = _Callback(func=func, periodUs=periodUs, expirationUs=startTimeUs)
3135

3236
currentTimeUs = _getFPGATime()
33-
callback.expirationUs = offsetUs + callback.calcFutureExpirationUs(currentTimeUs)
37+
callback.expirationUs = offsetUs + callback.calcFutureExpirationUs(
38+
currentTimeUs
39+
)
3440
return callback
3541

3642
def calcFutureExpirationUs(self, currentTimeUs: int) -> int:
@@ -40,8 +46,11 @@ def calcFutureExpirationUs(self, currentTimeUs: int) -> int:
4046
# callback wouldn't be running otherwise.
4147
# todo does this math work?
4248
# todo does the "// periodUs * periodUs" do the correct integer math?
43-
return self.expirationUs + self._periodUs + \
44-
((currentTimeUs - self.expirationUs) // self._periodUs) * self._periodUs
49+
return (
50+
self.expirationUs
51+
+ self._periodUs
52+
+ ((currentTimeUs - self.expirationUs) // self._periodUs) * self._periodUs
53+
)
4554

4655
def setNextStartTimeUs(self, currentTimeUs: int) -> None:
4756
self.expirationUs = self.calcFutureExpirationUs(currentTimeUs)
@@ -63,7 +72,7 @@ def add(self, item: Any) -> None:
6372
def pop(self) -> Any:
6473
return heappop(self._data)
6574

66-
def peek(self) -> Any|None:
75+
def peek(self) -> Any | None:
6776
if self._data:
6877
return self._data[0]
6978
else:
@@ -94,7 +103,9 @@ def __init__(self, period: float = 0.020):
94103

95104
self._notifier, status = initializeNotifier()
96105
if status != 0:
97-
raise RuntimeError(f"initializeNotifier() returned {self._notifier}, {status}")
106+
raise RuntimeError(
107+
f"initializeNotifier() returned {self._notifier}, {status}"
108+
)
98109

99110
status = setNotifierName(self._notifier, "TimedRobot")
100111
if status != 0:
@@ -126,7 +137,9 @@ def startCompetition(self) -> None:
126137

127138
currentTimeUs, status = waitForNotifierAlarm(self._notifier)
128139
if status != 0:
129-
raise RuntimeError(f"waitForNotifierAlarm() returned currentTimeUs={currentTimeUs} status={status}")
140+
raise RuntimeError(
141+
f"waitForNotifierAlarm() returned currentTimeUs={currentTimeUs} status={status}"
142+
)
130143

131144
if currentTimeUs == 0:
132145
# when HAL_StopNotifier(self.notifier) is called the above waitForNotifierAlarm
@@ -142,7 +155,9 @@ def startCompetition(self) -> None:
142155
callback = self._callbacks.pop()
143156
self._runCallbackAndReschedule(callback, currentTimeUs)
144157

145-
def _runCallbackAndReschedule(self, callback: Callable[[],None], currentTimeUs: int) -> None:
158+
def _runCallbackAndReschedule(
159+
self, callback: Callable[[], None], currentTimeUs: int
160+
) -> None:
146161
callback.func()
147162
callback.setNextStartTimeUs(currentTimeUs)
148163
self._callbacks.add(callback)
@@ -151,16 +166,16 @@ def endCompetition(self) -> None:
151166
stopNotifier(self._notifier)
152167

153168
def getLoopStartTime(self) -> float:
154-
return self.loopStartTimeUs/1e6 # units are seconds
155-
156-
def addPeriodic(self,
157-
callback: Callable[[],None],
158-
period: float, # units are seconds
159-
offset: float = 0.0 # units are seconds
160-
) -> None:
169+
return self.loopStartTimeUs / 1e6 # units are seconds
170+
171+
def addPeriodic(
172+
self,
173+
callback: Callable[[], None],
174+
period: float, # units are seconds
175+
offset: float = 0.0, # units are seconds
176+
) -> None:
161177
self._callbacks.add(
162178
_Callback.makeCallBack(
163-
callback,
164-
self._startTimeUs, int(period * 1e6), int(offset * 1e6)
179+
callback, self._startTimeUs, int(period * 1e6), int(offset * 1e6)
165180
)
166181
)

0 commit comments

Comments
 (0)