def setUp(self): self.barrier = threading.Barrier(2, timeout=5) self.listener = pifacecad.IREventListener( prog="pifacecadtest", lircrc="./tests/testlircrc") self.listener.register('1', self.ir_test_helper) self.test_passed = False
def init(self, media_player): """ Sets up the PiFace CAD 2 module. :param media_player: instance of MediaPlayer class which is being controlled :return: None """ self._media_player = media_player # https://github.com/piface/pifacedigitalio/issues/27 self._listeners_barrier = Barrier(2) self._listeners_wait_for_deactivation_thread = Thread(target=self._switch_listener_wait_for_deactivation, args=[]) self._listeners_wait_for_deactivation_thread.setDaemon(True) self._listeners_wait_for_deactivation_thread.start() self._switch_listener = pifacecad.SwitchEventListener() self._switch_listener.register(0, pifacecad.IODIR_ON, lambda event: self._clear_and_call(media_player.prev_branch)) self._switch_listener.register(1, pifacecad.IODIR_ON, lambda event: self._clear_and_call(media_player.next_branch)) self._switch_listener.register(2, pifacecad.IODIR_ON, lambda event: media_player.volume_down()) self._switch_listener.register(3, pifacecad.IODIR_ON, lambda event: media_player.volume_up()) self._switch_listener.register(5, pifacecad.IODIR_ON, lambda event: media_player.play_pause()) self._switch_listener.register(6, pifacecad.IODIR_ON, lambda event: self._clear_and_call(media_player.prev_track)) self._switch_listener.register(7, pifacecad.IODIR_ON, lambda event: self._clear_and_call(media_player.next_track)) self._switch_listener.activate() try: self._ir_listener = pifacecad.IREventListener(self._config['NAME']) self._ir_listener.register('play_pause', lambda event: call_and_sleep(media_player.play_pause)) self._ir_listener.register('next_track', lambda event: call_and_sleep(self._clear_and_call, media_player.next_track)) self._ir_listener.register('prev_track', lambda event: call_and_sleep(self._clear_and_call, media_player.prev_track)) self._ir_listener.register('next_branch', lambda event: call_and_sleep(self._clear_and_call, media_player.next_branch)) self._ir_listener.register('prev_branch', lambda event: call_and_sleep(self._clear_and_call, media_player.prev_branch)) self._ir_listener.register('eject', lambda event: call_and_sleep(media_player.stop)) self._ir_listener.register('volume_up', lambda event: call_and_sleep(media_player.volume_up)) self._ir_listener.register('volume_down', lambda event: call_and_sleep(media_player.volume_down)) self._ir_listener.activate() except Exception: print('LIRC cannot be initialized.') self._cad.lcd.clear() self._cad.lcd.backlight_on() self._cad.lcd.write('Loading') self._write_info_thread = Thread(target=self._write_info_thread_func) self._write_info_thread.setDaemon(True) self._write_info_thread.start()
def enter(self): try: self.ir_listener = pifacecad.IREventListener('camera') self.ir_listener.register('0', self.take_picture) self.ir_listener.activate() self.ir_listener_is_active = True self.error = False except Exception as e: super().update_display_option_text("error") self.ir_listener_is_active = False self.error = True print("ERROR (IR Mode):", e)
def mainFunc(): global volume listener = pifacecad.SwitchEventListener(chip=cad) for i in range(8): listener.register(i, pifacecad.IODIR_FALLING_EDGE, update_pin_text) listener.activate() remote_listener = pifacecad.IREventListener(prog='myprogram') for i in range(8): remote_listener.register(str(i), print_ir_code) remote_listener.activate() #musicMain = threading.Thread(target=musicMainfunc) radioMain = threading.Thread(target=radioMainFunc) while True: musicMainfunc() radioMain = threading.Thread(target=radioMainFunc) os.remove(path) os.mkfifo(path) radioMain.start() os.system('mplayer -slave -input file=' + path + ' ' + channelLink[0]) radioMain.join()
def ir2(event): print("ir 2 pressed") def ir3(event): print("ir 3 pressed") def ir4(event): print("ir 4 pressed") pifacecad.init() sl = pifacecad.SwitchEventListener() sl.register(0, pifacecad.IODIR_ON, input0) sl.register(1, pifacecad.IODIR_ON, input1) sl.register(2, pifacecad.IODIR_ON, input2) sl.register(3, pifacecad.IODIR_ON, input3) irl = pifacecad.IREventListener(prog="pifacecadtest", lircrc="./tests/testlircrc") irl.register('1', ir1) irl.register('2', ir2) irl.register('3', ir3) irl.register('4', ir4) sl.activate() irl.activate()
break pin = -1 elif pin == 7 or remote == 7: # volume up while True: subprocess.call('echo \"volume 1\" > /tmp/mplayer-control', shell=True) sleep(0.1) remote = -1 if not cad.switches[7].value: break pin = -1 main = threading.Thread(target=radioMainFunc) main.start() listener = pifacecad.SwitchEventListener(chip=cad) for i in range(8): listener.register(i, pifacecad.IODIR_FALLING_EDGE, update_pin_text) listener.activate() remote_listener = pifacecad.IREventListener(prog='myprogram') for i in range(8): remote_listener.register(str(i), print_ir_code) remote_listener.activate() os.system('mplayer -slave -input file='+path+' '+channelLink[0])
# finished using a barrier. global end_barrier end_barrier = Barrier(2) # wait for button presses switchlistener = pifacecad.SwitchEventListener(chip=cad) for pstation in range(4): switchlistener.register(pstation, pifacecad.IODIR_ON, radio_preset_switch) switchlistener.register(4, pifacecad.IODIR_ON, end_barrier.wait) switchlistener.register(5, pifacecad.IODIR_ON, radio.toggle_playing) switchlistener.register(6, pifacecad.IODIR_ON, radio.previous_station) switchlistener.register(7, pifacecad.IODIR_ON, radio.next_station) irlistener = pifacecad.IREventListener( prog="pifacecad-radio-example", lircrc="/usr/share/doc/python3-pifacecad/examples/radiolircrc") for i in range(4): irlistener.register(str(i), radio_preset_ir) switchlistener.activate() try: irlistener.activate() except lirc.InitError: print("Could not initialise IR, radio running without IR contorls.") irlistener_activated = False else: irlistener_activated = True end_barrier.wait() # wait unitl exit