Permalink
Browse files

Added a hid_exit function do do cleanup some before exiting

  - Close device in hidtest.cpp
  - Call hid_exit() at the end

  - TODO: MacOS and Windows use a blank hid_exit

Signed-off-by: Camille Moncelier <moncelier@devlife.org>
  • Loading branch information...
1 parent 687a838 commit 4467a20d6830ba1ae5242b12ce9d69f3c8dd5ad6 @pix committed Jul 19, 2011
Showing with 38 additions and 0 deletions.
  1. +11 −0 hidapi/hidapi.h
  2. +4 −0 hidtest/hidtest.cpp
  3. +8 −0 linux/hid-libusb.c
  4. +4 −0 linux/hid.c
  5. +4 −0 mac/hid.c
  6. +7 −0 windows/hid.cpp
View
@@ -77,6 +77,17 @@ extern "C" {
};
+ /** @brief Deinitialize hidapi
+
+ Deinitialize libusb.
+
+ This function should be called after closing all open devices
+ and before your application terminates.
+
+ @ingroup API
+ */
+ void HID_API_EXPORT HID_API_CALL hid_exit();
+
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
View
@@ -69,6 +69,7 @@ int main(int argc, char* argv[])
handle = hid_open(0x4d8, 0x3f, NULL);
if (!handle) {
printf("unable to open device\n");
+ hid_exit();
return 1;
}
@@ -182,5 +183,8 @@ int main(int argc, char* argv[])
system("pause");
#endif
+ hid_close(handle);
+ hid_exit();
+
return 0;
}
View
@@ -378,6 +378,14 @@ static char *make_path(libusb_device *dev, int interface_number)
return strdup(str);
}
+void HID_API_EXPORT hid_exit()
+{
+ if (initialized) {
+ libusb_exit(NULL);
+ initialized = 0;
+ }
+}
+
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
libusb_device **devs;
View
@@ -193,6 +193,10 @@ static int get_device_string(hid_device *dev, const char *key, wchar_t *string,
return ret;
}
+void HID_API_EXPORT hid_exit()
+{
+ // Nothing to do (As far as i know)
+}
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
View
@@ -288,6 +288,10 @@ static void init_hid_manager(void)
IOHIDManagerOpen(hid_mgr, kIOHIDOptionsTypeNone);
}
+void HID_API_EXPORT hid_exit()
+{
+ // TODO: Implement hid cleanup
+}
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
View
@@ -184,6 +184,13 @@ static void lookup_functions()
}
#endif
+
+void HID_API_EXPORT hid_exit()
+{
+ // TODO: Keep an handle on hid.dll
+ // and call FreeLibrary(lib);
+}
+
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
BOOL res;

0 comments on commit 4467a20

Please sign in to comment.