Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to detect proper keyDown and keyUp from piface #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions doorpi/keyboard/from_piface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def __init__(self, input_pins, output_pins, keyboard_name, bouncetime,
self.__listener.register(
pin_num=input_pin,
direction=p.IODIR_BOTH,
callback=self.event_detect,
settle_time=bouncetime / 1000 # from milliseconds to seconds
callback=self.event_detect
)
self._register_EVENTS_for_pin(input_pin, __name__)
self.__listener.activate()
Expand All @@ -47,10 +46,10 @@ def destroy(self):
if self.is_destroyed:
return
logger.debug("destroy")

# shutdown listener
self.__listener.deactivate()

# shutdown all output-pins
for output_pin in self._OutputPins:
self.set_output(output_pin, 0, False)
Expand All @@ -59,7 +58,7 @@ def destroy(self):
self.__destroyed = True

def event_detect(self, event):
if self.status_input(event.pin_num):
if event.direction is 0:
self._fire_OnKeyDown(event.pin_num, __name__)
if self._pressed_on_key_down: # issue 134
self._fire_OnKeyPressed(event.pin_num, __name__)
Expand All @@ -69,10 +68,7 @@ def event_detect(self, event):
self._fire_OnKeyPressed(event.pin_num, __name__)

def status_input(self, pin):
if self._polarity is 0:
return str(p.digital_read(int(pin))).lower() in HIGH_LEVEL
else:
return str(p.digital_read(int(pin))).lower() in LOW_LEVEL
pass

def set_output(self, pin, value, log_output = True):
parsed_pin = doorpi.DoorPi().parse_string("!"+str(pin)+"!")
Expand Down