def run(self): if ((self.map is None) or (self.db is None)): return print("[i] Starting Lirc Listener...") # Loading standard Keymap KEY_MAP = loadMap(self.map) # Reading user mapping from DB self.updateMapping() # Init IR connection conn = RawConnection() while not self._stop_event.is_set(): command = self.getIrCommand(conn) if (command is not None): # We override with the usermapping command if (command in self.user_mapping): command = self.user_mapping[command] # We trigger the proper KEY if (command in KEY_MAP): currentMap = KEY_MAP[command] print(currentMap) if (currentMap['keyboard']): sendKey(int(currentMap['value'], 0)) else: sendMultimediaKey(int(currentMap['value'], 0))
def handle_ir_remote(): ir_conn = RawConnection() #get IR command #keypress format = (hexcode, repeat_num, command_key, remote_id) while True: if is_radio_running(): return try: keypress = ir_conn.readline(.0001) except: keypress = "" time.sleep(0.1) if (keypress != "" and keypress != None): data = keypress.split() sequence = data[1] command = data[2] #ignore command repeats if (sequence != "00"): continue if (command == 'KEY_POWER'): logging.info('IR POWER key pressed') ir_conn.close() logging.info('Starting radio from IR') start_radio() elif (command == 'KEY_STOP'): logging.info('IR STOP key pressed') ir_conn.close() shutdown()
def testReceiveOneRawLine(self): ''' Receive a single, raw line. ''' if os.path.exists(_SOCKET): os.unlink(_SOCKET) cmd = [_SOCAT, 'UNIX-LISTEN:' + _SOCKET, 'EXEC:"echo %s"' % _PACKET_ONE] with subprocess.Popen(cmd) as child: _wait_for_socket() with RawConnection(socket_path=_SOCKET) as conn: line = conn.readline() self.assertEqual(line, _PACKET_ONE)
def testReceive10000RawLines(self): ''' Receive 10000 raw lines. ''' if os.path.exists(_SOCKET): os.unlink(_SOCKET) cmd = [_SOCAT, 'UNIX-LISTEN:' + _SOCKET, 'EXEC:"%s ./dummy-server 0"' % _EXPECT] with subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) as child: _wait_for_socket() lines = [] with RawConnection(socket_path=_SOCKET) as conn: for i in range(0, 10000): lines.append(conn.readline()) self.assertEqual(lines[0], _LINE_0) self.assertEqual(lines[9999], _LINE_0.replace(" 00 ", " 09 "))
keypress = conn.readline(.0001) #lee la tecla pulsada except: keypress = "" if (keypress != "" and keypress != None): data = keypress.split( ) #Separa los datos recibidos entre la cabecera y el numero del botón ( o identificación) #sequence = data[1] command = data[2] return command #define Global conn = RawConnection() print("Starting Up...") setup() while True: boton = ProcessIRRemote() if boton == 'KEY_1': if GPIO.input(4) == 1: # returns 1 print('Me enciendo') GPIO.output(LEDPIN1, GPIO.LOW) else: print('Me apago') GPIO.output(LEDPIN1, GPIO.HIGH) elif boton == 'KEY_2':