source: main/pyfprint/trunk/src/fprint.py @ 11529

Last change on this file since 11529 was 11529, checked in by uli, 11 years ago

Make at least test pass again.

File size: 3.3 KB
Line 
1# A ctypes wrapper around libfprint, a C lib for fingerprint scanners.
2import ctypes
3
4lib = ctypes.cdll.LoadLibrary("libfprint.so.0")
5
6#
7# Enums...
8#
9
10# enum fp_driver_type
11(
12    DRIVER_PRIMITIVE,
13    DRIVER_IMAGING,
14) = map(ctypes.c_int, xrange(0, 2))
15
16# enum fp_scan_type
17(
18    FP_SCAN_TYPE_PRESS,  # press
19    FP_SCAN_TYPE_SWIPE,  # swipe
20) = map(ctypes.c_int, xrange(0, 2))
21
22
23class usb_id(ctypes.Structure):
24    _fields_ = [
25        ('vendor', ctypes.c_uint16),
26        ('product', ctypes.c_uint16),
27        ('driver_data', ctypes.c_ulong),
28        ]
29
30class libusb_device_descriptor(ctypes.Structure):
31    # from libusb.h
32    _fields_ = [
33        ('bLength', ctypes.c_uint8),
34        ('bDescriptorType', ctypes.c_uint8),
35        ('bcdUSB', ctypes.c_uint16),
36        ('bDeviceClass', ctypes.c_uint8),
37        ('bDeviceSubClass', ctypes.c_uint8),
38        ('bDeviceProtocol', ctypes.c_uint8),
39        ('bMaxPacketSize0', ctypes.c_uint8),
40        ('idVendor', ctypes.c_uint16),
41        ('idProduct', ctypes.c_uint16),
42        ('bcdDevice', ctypes.c_uint16),
43        ('iManufacturer', ctypes.c_uint8),
44        ('iProduct', ctypes.c_uint8),
45        ('iSerialNumber', ctypes.c_uint8),
46        ('bNumConfigurations', ctypes.c_uint8),
47        ]
48
49
50#
51# 'Hidden' types, i.e. types that should not be accessed internally by apps
52# (defined in fprint_internal.h)
53#
54fp_dscv_dev = None
55fp_dscv_print = None
56fp_dev = None
57class fp_driver(ctypes.Structure):
58    _fields_ = [
59        ('id', ctypes.c_uint16),
60        ('name', ctypes.c_char_p),
61        ('full_name', ctypes.c_char_p),
62        ('id_table', usb_id),
63        ('type', ctypes.c_int),       # fp_driver_type
64        ('scan_type', ctypes.c_int),  # fp_scan_type
65        ('priv', ctypes.c_void_p),
66        #  Device operations
67        ('discover', ctypes.CFUNCTYPE(
68            ctypes.c_int,  # Returntype?
69            ctypes.POINTER(libusb_device_descriptor),
70            ctypes.POINTER(ctypes.c_uint32)),
71         ),
72        # int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype);
73        # int (*open)(struct fp_dev *dev, unsigned long driver_data);
74        # void (*close)(struct fp_dev *dev);
75        # int (*enroll_start)(struct fp_dev *dev);
76        # int (*enroll_stop)(struct fp_dev *dev);
77        # int (*verify_start)(struct fp_dev *dev);
78        # int (*verify_stop)(struct fp_dev *dev, gboolean iterating);
79        # int (*identify_start)(struct fp_dev *dev);
80        # int (*identify_stop)(struct fp_dev *dev, gboolean iterating);
81# };
82     
83        ]
84fp_print_data = None
85fp_img = None
86
87# enum fp_finger   Some enum...
88(
89    LEFT_THUMB, # thumb (left hand)
90    LEFT_INDEX,  # index finger (left hand)
91    LEFT_MIDDLE,  # middle finger (left hand)
92    LEFT_RING,  # ring finger (left hand)
93    LEFT_LITTLE,  # little finger (left hand)
94    RIGHT_THUMB,  # thumb (right hand)
95    RIGHT_INDEX,  # index finger (right hand)
96    RIGHT_MIDDLE,  # middle finger (right hand)
97    RIGHT_RING,  # ring finger (right hand)
98    RIGHT_LITTLE,  # little finger (right hand)
99) = map(ctypes.c_int, xrange(1, 11))
100
101
102
103# Drivers
104
105lib.fp_driver_get_name.restype = ctypes.POINTER(ctypes.c_char)
106lib.fp_driver_get_name.argtypes = [ctypes.POINTER(fp_driver)]
107driver_get_name = lib.fp_driver_get_name
108
109
110discover_devs = lib.fp_discover_devs
111
112
113if __name__ == '__main__':
114    print discover_devs()
115    import pdb; pdb.set_trace()
Note: See TracBrowser for help on using the repository browser.