Example #1
0
def find_devices():
    devices = list()
    for i in xrange(128):
        try:
            device_factory(i)
            devices.append(i)
            print(i)
        except IOError:
            pass
        return devices
Example #2
0
def find_devices():
    devices = list()
    for i in xrange(128):
        try:
            device_factory(i)
            devices.append(i)
            print(i)
        except IOError:
            pass
        return devices
Example #3
0
def listen(device_address):
    if raw_input("[!] warning this will write to your device! continue [Y/n]"
                 ).lower() not in ['y', '']:
        return
    device = device_factory(device_address)
    change = False
    drive = 'B'
    inp = 'A'
    prev_column_data = 0
    prev_row_data = 0

    device.set_io_mode('output', drive)
    device.set_io_mode('input', inp)

    while True:
        if change:
            print("[+]  input detected: row: {}| column: {}".format(
                repr_binary(row_data), repr_binary(column_data)))
            change = False
        column_data = device.read_port(drive)
        row_data = device.read_port(inp)
        if column_data != prev_column_data or row_data != prev_row_data:
            change = True
            prev_column_data = column_data
            prev_row_data = row_data
        time.sleep(0.1)
Example #4
0
def speed_test(device_address, reg):
    device = device_factory(device_address)
    start_time = time.time()
    for i in xrange(256):
        device.read_reg(reg)
    end_time = time.time()

    delta_time = end_time - start_time
    print("Read reg '{}': 256 times in: {}ms".format(reg, delta_time*1000))
Example #5
0
def turn_on_address(device_addrss, column, row):
    device = device_factory(device_addrss)
    column, row = find_int(column), find_int(row)
    column, row = turn_bit_on(0, 0, (column, row))
    if 0 > column > 8 or 0 > row > 8:
        raise ValueError("[-] column and row have to be 0 to 8, instead\nrow: {}\ncolumn: {}".format(row, column))
    device.write_port('A', column)
    device.write_port('B', row)
    return
Example #6
0
def speed_test(device_address, reg):
    device = device_factory(device_address)
    start_time = time.time()
    for i in xrange(256):
        device.read_reg(reg)
    end_time = time.time()

    delta_time = end_time - start_time
    print("Read reg '{}': 256 times in: {}ms".format(reg, delta_time * 1000))
Example #7
0
def device_mode(command):
    command = {'action': ""}

    device = device_factory(raw_input("insert device address > "))

    while command['action'] not in ['q', 'quit', 'exit']:
        command = parse_command_strings(raw_input("\ntest> "), exclude=['device'])
        command['device'] = device
        parse_command(command)
    quit()
Example #8
0
def write_byte(device_addr, reg, data):
    if reg == "a":
        reg = "GPIOA"
    elif reg == "b":
        reg = "GPIOB"
    data = data_lookup(data)
    reg = register_lookup(reg)
    device = device_factory(device_addr)

    device.write_byte(reg, data)
Example #9
0
def write_byte(device_addr, reg, data):
    if reg == "a":
        reg = "GPIOA"
    elif reg == "b":
        reg = "GPIOB"
    data = data_lookup(data)
    reg = register_lookup(reg)
    device = device_factory(device_addr)

    device.write_byte(reg, data)
Example #10
0
def device_mode(command):
    command = {'action': ""}

    device = device_factory(raw_input("insert device address > "))

    while command['action'] not in ['q', 'quit', 'exit']:
        command = parse_command_strings(raw_input("\ntest> "),
                                        exclude=['device'])
        command['device'] = device
        parse_command(command)
    quit()
Example #11
0
def turn_on_address(device_addrss, column, row):
    device = device_factory(device_addrss)
    column, row = find_int(column), find_int(row)
    column, row = turn_bit_on(0, 0, (column, row))
    if 0 > column > 8 or 0 > row > 8:
        raise ValueError(
            "[-] column and row have to be 0 to 8, instead\nrow: {}\ncolumn: {}"
            .format(row, column))
    device.write_port('A', column)
    device.write_port('B', row)
    return
Example #12
0
def read_byte(device_addr, reg):
    device = device_factory(device_addr)
    try:
        reg = register_lookup(reg)
    except ValueError:
        if raw_input("[!] the register '{}' could not be found! ingore warning [N/y]".format(reg)).lower() in ['','n']:
            return

    data = device.read_byte(reg)

    try:
        reg = register_names[reg]
    except KeyError:
        print("[!]  warning: register {} is unknown".format(reg))
    print("[+]  read: {}: {}".format(reg,repr_binary(data)))

    return data
Example #13
0
def read_byte(device_addr, reg):
    device = device_factory(device_addr)
    try:
        reg = register_lookup(reg)
    except ValueError:
        if raw_input(
                "[!] the register '{}' could not be found! ingore warning [N/y]"
                .format(reg)).lower() in ['', 'n']:
            return

    data = device.read_byte(reg)

    try:
        reg = register_names[reg]
    except KeyError:
        print("[!]  warning: register {} is unknown".format(reg))
    print("[+]  read: {}: {}".format(reg, repr_binary(data)))

    return data
Example #14
0
def listen(device_address):
    if raw_input("[!] warning this will write to your device! continue [Y/n]").lower() not in ['y', '']: return
    device = device_factory(device_address)
    change = False
    drive = 'B'
    inp = 'A'
    prev_column_data = 0
    prev_row_data = 0

    device.set_io_mode('output', drive)
    device.set_io_mode('input', inp)

    while True:
        if change:
            print("[+]  input detected: row: {}| column: {}".format(repr_binary(row_data), repr_binary(column_data)))
            change = False
        column_data = device.read_port(drive)
        row_data = device.read_port(inp)
        if column_data != prev_column_data or row_data != prev_row_data:
            change = True
            prev_column_data = column_data
            prev_row_data = row_data
        time.sleep(0.1)
Example #15
0
def pin_mode(device_addr, reg, io):  # todo: rewrite into 'port_mode'
    device = device_factory(device_addr)
    device.pin_mode(reg, io)
Example #16
0
def debug_IO(device_addr):
    device = device_factory(device_addr)
    print("++++++++ debug ++++++++")
    for line in repr(device).split('\n'):
        print("| " + line)
    print("-----------------------")
Example #17
0
def pin_mode(device_addr, reg, io):  # todo: rewrite into 'port_mode'
    device = device_factory(device_addr)
    device.pin_mode(reg, io)
Example #18
0
def debug_IO(device_addr):
    device = device_factory(device_addr)
    print("++++++++ debug ++++++++")
    for line in repr(device).split('\n'):
        print("| " + line)
    print("-----------------------")