Skip to content

Commit dda5f56

Browse files
committed
pylint fixes
1 parent a4526a6 commit dda5f56

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

adafruit_debouncer.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
__version__ = "0.0.0-auto.0"
2929
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Debouncer.git"
3030

31-
from adafruit_ticks import ticks_ms, ticks_diff
3231
from micropython import const
32+
from adafruit_ticks import ticks_ms, ticks_diff
3333

3434
_DEBOUNCED_STATE = const(0x01)
3535
_UNSTABLE_STATE = const(0x02)
@@ -132,52 +132,53 @@ def current_duration(self):
132132

133133
class Button(Debouncer):
134134
"""Debounce counter"""
135-
def __init__(self, pin, short_duration = 0.2, long_duration = 0.5, active_down = True, **kwargs):
135+
def __init__(self, pin, short_duration=0.2, long_duration=0.5, active_down=True, **kwargs):
136136
self.short_duration = short_duration
137137
self.long_duration = long_duration
138138
self.active_down = active_down
139139
self.last_change_ticks = ticks_ms()
140140
self.short_counter = 0
141-
self.short_showed = 0
141+
self.short_to_show = 0
142142
self.long_registered = False
143143
self.long_showed = False
144144
super(Button, self).__init__(pin, **kwargs)
145145

146-
def pushed (self):
146+
def _pushed(self):
147147
return (self.active_down and super().fell) or (not self.active_down and super().rose)
148148

149-
def released (self):
149+
def _released(self):
150150
return (self.active_down and super().rose) or (not self.active_down and super().fell)
151151

152-
def update (self):
152+
def update(self):
153153
super().update()
154-
if self.pushed():
154+
if self._pushed():
155155
self.last_change_ticks = ticks_ms()
156156
self.short_counter = self.short_counter + 1
157-
elif self.released():
157+
elif self._released():
158158
self.last_change_ticks = ticks_ms()
159159
if self.long_registered:
160160
self.long_registered = False
161161
self.long_showed = False
162162
else:
163-
now_ticks = ticks_ms()
164-
duration = ticks_diff(now_ticks, self.last_change_ticks)
163+
duration = ticks_diff(ticks_ms(), self.last_change_ticks)
165164
if not self.long_registered and self.value != self.active_down and duration > self.long_duration:
166165
self.long_registered = True
167-
self.short_showed = self.short_counter - 1
166+
self.short_to_show = self.short_counter - 1
168167
self.short_counter = 0
169168
elif self.short_counter > 0 and self.value == self.active_down and duration > self.short_duration:
170-
self.short_showed = self.short_counter
169+
self.short_to_show = self.short_counter
171170
self.short_counter = 0
172171

173172
@property
174-
def short_count (self):
175-
ret = self.short_showed
176-
self.short_showed = 0
173+
def short_count(self):
174+
"""Return the number of short press"""
175+
ret = self.short_to_show
176+
self.short_to_show = 0
177177
return ret
178178

179179
@property
180-
def long_press (self):
180+
def long_press(self):
181+
"""Return whether long press has occured"""
181182
if self.long_registered and not self.long_showed:
182183
self.long_showed = True
183184
return True

examples/debouncer_multi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import digitalio
33
from adafruit_debouncer import Button
44

5-
"""
6-
This example shows how to count short clicks or detect a long press
7-
"""
5+
# This example shows how to count short clicks or detect a long press
86

97
pin = digitalio.DigitalInOut(board.D12)
108
pin.direction = digitalio.Direction.INPUT

0 commit comments

Comments
 (0)