Skip to content

Commit e232452

Browse files
authored
Merge pull request #39 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 6615856 + 07ca9a0 commit e232452

File tree

10 files changed

+174
-138
lines changed

10 files changed

+174
-138
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123+
notes=FIXME,XXX
123124

124125

125126
[TYPECHECK]

adafruit_motor/motor.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
__version__ = "0.0.0-auto.0"
4141
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Motor.git"
4242

43+
4344
class DCMotor:
4445
"""DC motor driver. ``positive_pwm`` and ``negative_pwm`` can be swapped if the motor runs in
4546
the opposite direction from what was expected for "forwards".
@@ -48,6 +49,7 @@ class DCMotor:
4849
when high and the other is low.
4950
:param ~pulseio.PWMOut negative_pwm: The motor input that causes the motor to spin backwards
5051
when high and the other is low."""
52+
5153
def __init__(self, positive_pwm, negative_pwm):
5254
self._positive = positive_pwm
5355
self._negative = negative_pwm
@@ -70,10 +72,10 @@ def throttle(self, value):
7072
self._positive.duty_cycle = 0
7173
self._negative.duty_cycle = 0
7274
elif value == 0:
73-
self._positive.duty_cycle = 0xffff
74-
self._negative.duty_cycle = 0xffff
75+
self._positive.duty_cycle = 0xFFFF
76+
self._negative.duty_cycle = 0xFFFF
7577
else:
76-
duty_cycle = int(0xffff * abs(value))
78+
duty_cycle = int(0xFFFF * abs(value))
7779
if value < 0:
7880
self._positive.duty_cycle = 0
7981
self._negative.duty_cycle = duty_cycle

adafruit_motor/servo.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@
3434

3535
# We disable the too few public methods check because this is a private base class for the two types
3636
# of servos.
37-
class _BaseServo: # pylint: disable-msg=too-few-public-methods
37+
class _BaseServo: # pylint: disable-msg=too-few-public-methods
3838
"""Shared base class that handles pulse output based on a value between 0 and 1.0
3939
4040
:param ~pulseio.PWMOut pwm_out: PWM output object.
4141
:param int min_pulse: The minimum pulse length of the servo in microseconds.
4242
:param int max_pulse: The maximum pulse length of the servo in microseconds."""
43+
4344
def __init__(self, pwm_out, *, min_pulse=750, max_pulse=2250):
4445
self._pwm_out = pwm_out
4546
self.set_pulse_width_range(min_pulse, max_pulse)
4647

4748
def set_pulse_width_range(self, min_pulse=750, max_pulse=2250):
4849
"""Change min and max pulse widths."""
49-
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xffff)
50-
max_duty = (max_pulse * self._pwm_out.frequency) / 1000000 * 0xffff
50+
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xFFFF)
51+
max_duty = (max_pulse * self._pwm_out.frequency) / 1000000 * 0xFFFF
5152
self._duty_range = int(max_duty - self._min_duty)
5253

5354
@property
@@ -56,20 +57,21 @@ def fraction(self):
5657
For conventional servos, corresponds to the servo position as a fraction
5758
of the actuation range. Is None when servo is diabled (pulsewidth of 0ms).
5859
"""
59-
if self._pwm_out.duty_cycle == 0: # Special case for disabled servos
60+
if self._pwm_out.duty_cycle == 0: # Special case for disabled servos
6061
return None
6162
return (self._pwm_out.duty_cycle - self._min_duty) / self._duty_range
6263

6364
@fraction.setter
6465
def fraction(self, value):
6566
if value is None:
66-
self._pwm_out.duty_cycle = 0 # disable the motor
67+
self._pwm_out.duty_cycle = 0 # disable the motor
6768
return
6869
if not 0.0 <= value <= 1.0:
6970
raise ValueError("Must be 0.0 to 1.0")
7071
duty_cycle = self._min_duty + int(value * self._duty_range)
7172
self._pwm_out.duty_cycle = duty_cycle
7273

74+
7375
class Servo(_BaseServo):
7476
"""Control the position of a servo.
7577
@@ -99,6 +101,7 @@ class Servo(_BaseServo):
99101
the servo mechanism may hit the end stops, buzz, and draw extra current as it stalls.
100102
Test carefully to find the safe minimum and maximum.
101103
"""
104+
102105
def __init__(self, pwm_out, *, actuation_range=180, min_pulse=750, max_pulse=2250):
103106
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse)
104107
self.actuation_range = actuation_range
@@ -115,18 +118,20 @@ def angle(self):
115118

116119
@angle.setter
117120
def angle(self, new_angle):
118-
if new_angle is None: # disable the servo by sending 0 signal
121+
if new_angle is None: # disable the servo by sending 0 signal
119122
self.fraction = None
120123
return
121124
if new_angle < 0 or new_angle > self.actuation_range:
122125
raise ValueError("Angle out of range")
123126
self.fraction = new_angle / self.actuation_range
124127

128+
125129
class ContinuousServo(_BaseServo):
126130
"""Control a continuous rotation servo.
127131
128132
:param int min_pulse: The minimum pulse width of the servo in microseconds.
129133
:param int max_pulse: The maximum pulse width of the servo in microseconds."""
134+
130135
@property
131136
def throttle(self):
132137
"""How much power is being delivered to the motor. Values range from ``-1.0`` (full

adafruit_motor/stepper.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"""Step a fraction of a step by partially activating two neighboring coils. Step size is determined
5858
by ``microsteps`` constructor argument."""
5959

60+
6061
class StepperMotor:
6162
"""A bipolar stepper motor or four coil unipolar motor.
6263
@@ -70,10 +71,11 @@ class StepperMotor:
7071
the fourth coil (unipolar) or second input to second coil (bipolar).
7172
:param int microsteps: Number of microsteps between full steps. Must be at least 2 and even.
7273
"""
74+
7375
def __init__(self, ain1, ain2, bin1, bin2, *, microsteps=16):
7476
self._coil = (ain2, bin1, ain1, bin2)
7577

76-
# set a safe pwm freq for each output
78+
# set a safe pwm freq for each output
7779
for i in range(4):
7880
if self._coil[i].frequency < 1500:
7981
self._coil[i].frequency = 2000
@@ -84,8 +86,10 @@ def __init__(self, ain1, ain2, bin1, bin2, *, microsteps=16):
8486
if microsteps % 2 == 1:
8587
raise ValueError("Microsteps must be even")
8688
self._microsteps = microsteps
87-
self._curve = [int(round(0xffff * math.sin(math.pi / (2 * microsteps) * i)))
88-
for i in range(microsteps + 1)]
89+
self._curve = [
90+
int(round(0xFFFF * math.sin(math.pi / (2 * microsteps) * i)))
91+
for i in range(microsteps + 1)
92+
]
8993
self._update_coils()
9094

9195
def _update_coils(self, *, microstepping=False):
@@ -98,10 +102,12 @@ def _update_coils(self, *, microstepping=False):
98102

99103
# This ensures DOUBLE steps use full torque. Without it, we'd use partial torque from the
100104
# microstepping curve (0xb504).
101-
if not microstepping and (duty_cycles[leading_coil] == duty_cycles[trailing_coil] and
102-
duty_cycles[leading_coil] > 0):
103-
duty_cycles[leading_coil] = 0xffff
104-
duty_cycles[trailing_coil] = 0xffff
105+
if not microstepping and (
106+
duty_cycles[leading_coil] == duty_cycles[trailing_coil]
107+
and duty_cycles[leading_coil] > 0
108+
):
109+
duty_cycles[leading_coil] = 0xFFFF
110+
duty_cycles[trailing_coil] = 0xFFFF
105111

106112
# Energize coils as appropriate:
107113
for i in range(4):
@@ -145,8 +151,9 @@ def onestep(self, *, direction=FORWARD, style=SINGLE):
145151
step_size = half_step
146152

147153
current_interleave = self._current_microstep // half_step
148-
if ((style == SINGLE and current_interleave % 2 == 1) or
149-
(style == DOUBLE and current_interleave % 2 == 0)):
154+
if (style == SINGLE and current_interleave % 2 == 1) or (
155+
style == DOUBLE and current_interleave % 2 == 0
156+
):
150157
step_size = half_step
151158
elif style in (SINGLE, DOUBLE):
152159
step_size = full_step

0 commit comments

Comments
 (0)