Exemplo n.º 1
0
    def run(self):
        while True:
            version = 0
            try:
                time.sleep(1)
                t0 = time.monotonic()
                import lirc as LIRC
                self.LIRC = LIRC
                version = 2
                print('have lirc for remote control', time.monotonic()-t0)
            except Exception as e:
                print('failed to load lirc', e)
                try:
                    import pylirc as LIRC
                    self.LIRC = LIRC
                    version = 1
                    print('have old lirc for remote control')
                except Exception as e:
                    print('no lirc available', e)

            try:
                if version == 1:
                    LIRC.init('pypilot')
                    break
                elif version == 2:
                    self.lircd = LIRC.RawConnection()
                    break
            except Exception as e:
                print('failed to initialize lirc. is .lircrc missing?', e)
            time.sleep(2)
        self.version = version
Exemplo n.º 2
0
def get_key():
    with lirc.RawConnection() as conn:
        press = conn.readline()

#   Typical response:
#   press = "0000000000ff38c7 00 KEY_OK HUIMAI"

    words = press.split()
#   print(key_info[words[2]])
    mykey = key_info[words[2]]
    return Key(mykey[0], mykey[1])
Exemplo n.º 3
0
    def receive_lirc_commands(self):
        with lirc.RawConnection(None) as conn:
            while True:
                (code, seq, key, remote) = conn.readline().split(' ')
                if remote != REMOTE_NAME:
                    logging.error(
                        'Received %s key for remote "%s" but configured for "%s"'
                        % (key, remote, REMOTE_NAME))
                    continue
                if key not in REMOTE_KEY_TO_COMMAND.keys():
                    logging.error('Received unregistered %s key' % key)
                    continue
                if seq != '00':
                    logging.debug('Ignoring repeated key press %s %s' %
                                  (key, seq))
                    continue

                self.command_sender.send(REMOTE_KEY_TO_COMMAND[key])
Exemplo n.º 4
0
'''
Reference python implementation of irw(1)

Run using python3 irw.py [socket_path]

'''

import sys

import lirc

if len(sys.argv) >= 3:
    sys.stderr.write("Usage: irw.py [socket path]")
    sys.exit(1)
path = sys.argv[1] if len(sys.argv) == 2 else None
with lirc.RawConnection(path) as conn:
    while True:
        print(conn.readline())
Exemplo n.º 5
0
def process_key(key):
    print("Processing key: {}".format(key))

    if not key in keys_lights:
        return

    if keys_lights[key] == -1:
        for key in keys_lights.keys():
            if keys_lights[key] != -1:
                print("Turning LED <OFF>: {}".format(keys_lights[key]))
                leds[key].off()
        return

    led = leds[key]
    if led.is_lit:
        print("Turning LED <OFF>: {}".format(keys_lights[key]))
        led.off()
    else:
        print("Turning LED <ON>: {}".format(keys_lights[key]))
        led.on()


init_leds()

with lirc.RawConnection(socket_path) as conn:
    while True:
        print("Scanning keypress...")
        keypress = conn.readline()
        print("Received keypress: {}".format(keypress))
        process_key(parse_key(keypress))