Skip to content

Commit 016a726

Browse files
committed
reformat with black
1 parent b89a85a commit 016a726

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

adafruit_debouncer.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ def current_duration(self):
131131

132132
class Button(Debouncer):
133133
"""Debounce counter"""
134-
def __init__(self, pin,
135-
short_duration_ms=200,
136-
long_duration_ms=500,
137-
active_down=True,
138-
**kwargs):
134+
135+
def __init__(
136+
self,
137+
pin,
138+
short_duration_ms=200,
139+
long_duration_ms=500,
140+
active_down=True,
141+
**kwargs
142+
):
139143
self.short_duration_ms = short_duration_ms
140144
self.long_duration_ms = long_duration_ms
141145
self.active_down = active_down
@@ -147,12 +151,14 @@ def __init__(self, pin,
147151
super().__init__(pin, **kwargs)
148152

149153
def _pushed(self):
150-
return (self.active_down and super().fell) or \
151-
(not self.active_down and super().rose)
154+
return (self.active_down and super().fell) or (
155+
not self.active_down and super().rose
156+
)
152157

153158
def _released(self):
154-
return (self.active_down and super().rose) or \
155-
(not self.active_down and super().fell)
159+
return (self.active_down and super().rose) or (
160+
not self.active_down and super().fell
161+
)
156162

157163
def update(self):
158164
super().update()
@@ -166,15 +172,19 @@ def update(self):
166172
self.long_showed = False
167173
else:
168174
duration = ticks_diff(ticks_ms(), self.last_change_ms)
169-
if not self.long_registered and \
170-
self.value != self.active_down and \
171-
duration > self.long_duration_ms:
175+
if (
176+
not self.long_registered
177+
and self.value != self.active_down
178+
and duration > self.long_duration_ms
179+
):
172180
self.long_registered = True
173181
self.short_to_show = self.short_counter - 1
174182
self.short_counter = 0
175-
elif self.short_counter > 0 and \
176-
self.value == self.active_down and \
177-
duration > self.short_duration_ms:
183+
elif (
184+
self.short_counter > 0
185+
and self.value == self.active_down
186+
and duration > self.short_duration_ms
187+
):
178188
self.short_to_show = self.short_counter
179189
self.short_counter = 0
180190

examples/debouncer_multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
while True:
1616
switch.update()
1717
if switch.long_press:
18-
print('long')
18+
print("long")
1919
count = switch.short_count
2020
if count != 0:
21-
print('count=', count)
21+
print("count=", count)

0 commit comments

Comments
 (0)