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)
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
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