Beispiel #1
0
def init_capture():

    global state
    global img_transfer
    global irq_transfer

    r = usb.submit_transfer(irq_transfer)
    if r < 0:
        return r

    r = usb.submit_transfer(img_transfer)
    if r < 0:
        usb.cancel_transfer(irq_transfer)
        while irq_transfer:
            if usb.handle_events(None) < 0:
                break
        return r

    # start state machine
    state = STATE_AWAIT_IRQ_FINGER_REMOVED
    return next_state()
Beispiel #2
0
def main():

    global devh
    global img_transfer
    global irq_transfer
    global do_exit

    exit_sem = sem_open(SEM_NAME, O_CREAT, 0)
    if not exit_sem:
        print("failed to initialise semaphore error {}".format(errno), file=sys.stderr)
        sys.exit(1)

    # only using this semaphore in this process so go ahead and unlink it now
    sem_unlink(SEM_NAME)

    r = usb.init(None)
    if r < 0:
        print("failed to initialise libusb", file=sys.stderr)
        sys.exit(1)

    r = find_dpfp_device()
    try:
        if r < 0:
            print("Could not find/open device", file=sys.stderr)
            return abs(r)

        r = usb.claim_interface(devh, 0)
        if r < 0:
            print("usb_claim_interface error {} {}".format(r, usb.strerror(usb.error(r))), file=sys.stderr)
            return abs(r)
        print("claimed interface")

        r = print_f0_data()
        if r < 0:
            usb.release_interface(devh, 0)
            return abs(r)

        r = do_init()
        try:
            if r < 0:
                return abs(r)

            # async from here onwards

            #sigact = struct_sigaction()
            #sigact.sa_handler = sighandler
            #sigemptyset(ct.byref(sigact.sa_mask))
            #sigact.sa_flags = 0
            signal.signal(signal.SIGINT,  sighandler)
            signal.signal(signal.SIGTERM, sighandler)
            if hasattr(signal, "SIGQUIT"):
                signal.signal(signal.SIGQUIT, sighandler)

            r = pthread_create(ct.byref(poll_thread), NULL, poll_thread_main, NULL)
            if r:
                return abs(r)

            r = alloc_transfers()
            if r < 0:
                request_exit(1)
                pthread_join(poll_thread, NULL)
                return abs(r)

            r = init_capture()
            if r < 0:
                request_exit(1)
                pthread_join(poll_thread, NULL)
                return abs(r)

            while not do_exit:
                sem_wait(exit_sem)

            print("shutting down...")
            pthread_join(poll_thread, NULL)

            r = usb.cancel_transfer(irq_transfer)
            if r < 0:
                request_exit(1)
                return abs(r)

            r = usb.cancel_transfer(img_transfer)
            if r < 0:
                request_exit(1)
                return abs(r)

            while irq_transfer or img_transfer:
                if usb.handle_events(None) < 0:
                    break

            r = 0 if do_exit == 1 else 1

        finally:
            usb.free_transfer(img_transfer)
            usb.free_transfer(irq_transfer)
            set_mode(0);
            set_hwstat(0x80)
            usb.release_interface(devh, 0)
    finally:
        usb.close(devh)
        usb.exit(None)

    return abs(r)
Beispiel #3
0
def main(argv=sys.argv):

    global devh
    global img_transfer
    global irq_transfer
    global do_exit

    r = usb.init(None)
    if r < 0:
        print("failed to initialise libusb", file=sys.stderr)
        sys.exit(1)

    r = find_dpfp_device()
    try:
        if r < 0:
            print("Could not find/open device", file=sys.stderr)
            return abs(r)

        r = usb.claim_interface(devh, 0)
        if r < 0:
            print("usb_claim_interface error {}".format(r), file=sys.stderr)
            return abs(r)
        print("claimed interface")

        r = print_f0_data()
        if r < 0:
            usb.release_interface(devh, 0)
            return abs(r)

        r = do_init()
        try:
            if r < 0:
                return abs(r)

            # async from here onwards

            r = alloc_transfers()
            if r < 0:
                return abs(r)

            r = init_capture()
            if r < 0:
                return abs(r)

            #sigact = struct_sigaction()
            #sigact.sa_handler = sighandler
            #sigemptyset(ct.byref(sigact.sa_mask))
            #sigact.sa_flags = 0
            signal.signal(signal.SIGINT,  sighandler)
            signal.signal(signal.SIGTERM, sighandler)
            if hasattr(signal, "SIGQUIT"):
                signal.signal(signal.SIGQUIT, sighandler)

            while not do_exit:
                r = usb.handle_events(None)
                if r < 0:
                    return abs(r)

            print("shutting down...")

            if irq_transfer:
                r = usb.cancel_transfer(irq_transfer)
                if r < 0:
                    return abs(r)

            if img_transfer:
                r = usb.cancel_transfer(img_transfer)
                if r < 0:
                    return abs(r)

            while irq_transfer or img_transfer:
                if usb.handle_events(None) < 0:
                    break

            r = 0 if do_exit == 1 else 1

        finally:
            usb.free_transfer(img_transfer)
            usb.free_transfer(irq_transfer)
            set_mode(0);
            set_hwstat(0x80)
            usb.release_interface(devh, 0)
    finally:
        usb.close(devh)
        usb.exit(None)

    return abs(r)