Skip to content
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: 9 additions & 5 deletions pifacecad/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lirc
import pifacecommon.interrupts

# The lirc API changed. Need a global object replacement for lirc
Glircd = None

class IREvent(object):
"""An IR event."""
Expand Down Expand Up @@ -60,7 +62,8 @@ def activate(self):
"""When activated the :class:`IREventListener` will run callbacks
associated with IR codes.
"""
lirc.init(self.prog, self.lircrc)
global Glircd
Glircd = lirc.LircdConnection(self.prog, self.lircrc)
self.dispatcher.start()
self.detector.start()

Expand All @@ -71,8 +74,8 @@ def deactivate(self):
self.event_queue.put(self.TERMINATE_SIGNAL)
self.dispatcher.join()
self.detector.terminate() # maybe use a message queue instead?
lirc.deinit()

global Glircd
Glircd.close()

def _event_matches_ir_function_map(event, ir_function_map):
return event.ir_code == ir_function_map.ir_code
Expand All @@ -84,6 +87,7 @@ def watch_ir_events(event_queue):
:param event_queue: A queue to put events on.
:type event_queue: :py:class:`multiprocessing.Queue`
"""
global Glircd
while True:
for ir_code in lirc.nextcode():
event_queue.put(IREvent(ir_code))
ir_code = Glircd.readline()
event_queue.put(IREvent(ir_code))