Merge branch 'pylint' of https://github.com/craigargh/Adafruit_Learning_System_Guides into pylint
This commit is contained in:
commit
8fb8ca76c8
2 changed files with 20 additions and 10 deletions
|
|
@ -40,8 +40,10 @@ class Debouncer(object):
|
||||||
def __init__(self, pin, mode=None, interval=0.010):
|
def __init__(self, pin, mode=None, interval=0.010):
|
||||||
"""Make am instance.
|
"""Make am instance.
|
||||||
:param int pin: the pin (from board) to debounce
|
:param int pin: the pin (from board) to debounce
|
||||||
:param int mode: digitalio.Pull.UP or .DOWN (default is no pull up/down)
|
:param int mode: digitalio.Pull.UP or .DOWN (default is no
|
||||||
:param int interval: bounce threshold in seconds (default is 0.010, i.e. 10 milliseconds)
|
pull up/down)
|
||||||
|
:param int interval: bounce threshold in seconds (default is 0.010,
|
||||||
|
i.e. 10 milliseconds)
|
||||||
"""
|
"""
|
||||||
self.state = 0x00
|
self.state = 0x00
|
||||||
self.pin = digitalio.DigitalInOut(pin)
|
self.pin = digitalio.DigitalInOut(pin)
|
||||||
|
|
@ -70,7 +72,8 @@ class Debouncer(object):
|
||||||
return (self.state & bits) != 0
|
return (self.state & bits) != 0
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the debouncer state. Must be called before using any of the properties below"""
|
"""Update the debouncer state. Must be called before using any of
|
||||||
|
the properties below"""
|
||||||
self.__unset_state(Debouncer.CHANGED_STATE)
|
self.__unset_state(Debouncer.CHANGED_STATE)
|
||||||
current_state = self.pin.value
|
current_state = self.pin.value
|
||||||
if current_state != self.__get_state(Debouncer.UNSTABLE_STATE):
|
if current_state != self.__get_state(Debouncer.UNSTABLE_STATE):
|
||||||
|
|
@ -78,7 +81,8 @@ class Debouncer(object):
|
||||||
self.__toggle_state(Debouncer.UNSTABLE_STATE)
|
self.__toggle_state(Debouncer.UNSTABLE_STATE)
|
||||||
else:
|
else:
|
||||||
if time.monotonic() - self.previous_time >= self.interval:
|
if time.monotonic() - self.previous_time >= self.interval:
|
||||||
if current_state != self.__get_state(Debouncer.DEBOUNCED_STATE):
|
debounced_state = self.__get_state(Debouncer.DEBOUNCED_STATE)
|
||||||
|
if current_state != debounced_state:
|
||||||
self.previous_time = time.monotonic()
|
self.previous_time = time.monotonic()
|
||||||
self.__toggle_state(Debouncer.DEBOUNCED_STATE)
|
self.__toggle_state(Debouncer.DEBOUNCED_STATE)
|
||||||
self.__set_state(Debouncer.CHANGED_STATE)
|
self.__set_state(Debouncer.CHANGED_STATE)
|
||||||
|
|
@ -90,10 +94,14 @@ class Debouncer(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rose(self):
|
def rose(self):
|
||||||
"""Return whether the debounced input went from low to high at the most recent update."""
|
"""Return whether the debounced input went from low to high at
|
||||||
return self.__get_state(self.DEBOUNCED_STATE) and self.__get_state(self.CHANGED_STATE)
|
the most recent update."""
|
||||||
|
return self.__get_state(self.DEBOUNCED_STATE) \
|
||||||
|
and self.__get_state(self.CHANGED_STATE)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fell(self):
|
def fell(self):
|
||||||
"""Return whether the debounced input went from high to low at the most recent update."""
|
"""Return whether the debounced input went from high to low at
|
||||||
return (not self.__get_state(self.DEBOUNCED_STATE)) and self.__get_state(self.CHANGED_STATE)
|
the most recent update."""
|
||||||
|
return (not self.__get_state(self.DEBOUNCED_STATE)) \
|
||||||
|
and self.__get_state(self.CHANGED_STATE)
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ class Emulator(object):
|
||||||
self.address_clock_pin.value = CLOCK_INACTIVE
|
self.address_clock_pin.value = CLOCK_INACTIVE
|
||||||
|
|
||||||
def __output_on_port_a(self, data_byte):
|
def __output_on_port_a(self, data_byte):
|
||||||
"""A hack to get around the limitation of the 23017 library to use 8-bit ports"""
|
"""A hack to get around the limitation of the 23017
|
||||||
|
library to use 8-bit ports"""
|
||||||
self.mcp.gpio = (self.mcp.gpio & 0xFF00) | (data_byte & 0x00FF)
|
self.mcp.gpio = (self.mcp.gpio & 0xFF00) | (data_byte & 0x00FF)
|
||||||
|
|
||||||
def enter_program_mode(self):
|
def enter_program_mode(self):
|
||||||
|
|
@ -113,7 +114,8 @@ class Emulator(object):
|
||||||
self.led_pin.value = LED_OFF
|
self.led_pin.value = LED_OFF
|
||||||
|
|
||||||
def enter_emulate_mode(self):
|
def enter_emulate_mode(self):
|
||||||
"""Enter emulate mode, giving control of the emulator ram to the host."""
|
"""Enter emulate mode, giving control of the emulator
|
||||||
|
ram to the host."""
|
||||||
self.mode_pin.value = EMULATE_USE
|
self.mode_pin.value = EMULATE_USE
|
||||||
self.led_pin.value = LED_ON
|
self.led_pin.value = LED_ON
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue