Ejemplo n.º 1
0
    def perform_dfu_fwreboot(self, update_animation):
        fwreboot(self.dev)

        WAIT_TIME_MAX = 60
        CHECK_PERIOD = 0.5
        start_time = time.time()

        # Wait until device turns off
        while self.dev.initialized():
            self.dev.close_device()
            self.dev = NrfHidDevice(self.type, get_device_vid(self.type),
                                    get_device_pid(self.type),
                                    get_device_pid('dongle'))
            time.sleep(CHECK_PERIOD)

        while not self.dev.initialized():
            update_animation()
            self.dev = NrfHidDevice(self.type, get_device_vid(self.type),
                                    get_device_pid(self.type),
                                    get_device_pid('dongle'))
            if time.time() - start_time > WAIT_TIME_MAX:
                break
            time.sleep(CHECK_PERIOD)

        if self.dev.initialized():
            print('DFU completed')
        else:
            print('Cannot connect to device after reboot')

        return self.dev.initialized()
Ejemplo n.º 2
0
def open_device(device_type):
    dev = None

    devlist = [device_type]
    if 'dongle' not in devlist:
        devlist.append('dongle')

    for i in devlist:
        try:
            vid = get_device_vid(i)
            pid = get_device_pid(i)
            dev = hid.Device(vid=vid, pid=pid)
            break
        except hid.HIDException:
            pass
        except Exception:
            logging.error('Unknown error: {}'.format(sys.exc_info()[0]))

    if dev is None:
        print('Cannot find selected device nor dongle')
    elif i == device_type:
        print('Device found')
    else:
        print('Device connected via {}'.format(i))

    return dev
Ejemplo n.º 3
0
    def list_devices():
        devices = hid.enumerate()
        device_list = []
        for device in devices:
            device_type = get_device_type(device['product_id'])
            if device_type is not None and \
               get_device_vid(device_type) == device['vendor_id']:
                print("Add {} to device list".format(device_type))
                device_list.append(device_type)

        return device_list
def configurator():
    logging.basicConfig(level=logging.ERROR)
    logging.info('Configuration channel for nRF52 Desktop')

    args = parse_arguments()

    dev = NrfHidDevice(args.device_type, get_device_vid(args.device_type),
                       get_device_pid(args.device_type),
                       get_device_pid('dongle'))

    if not dev.initialized():
        print('Cannot find selected device')
        return

    configurator.ALLOWED_COMMANDS[args.command](dev, args)

    dev.close_device()
Ejemplo n.º 5
0
 def __init__(self, device_type):
     self.type = device_type
     self.dev = NrfHidDevice(device_type, get_device_vid(device_type),
                             get_device_pid(device_type),
                             get_device_pid('dongle'))