]> err.no Git - yubiyubo/commitdiff
Add initial libhid framework
authorTollef Fog Heen <tfheen@err.no>
Sun, 28 Dec 2008 19:40:46 +0000 (20:40 +0100)
committerTollef Fog Heen <tfheen@err.no>
Sun, 28 Dec 2008 19:40:46 +0000 (20:40 +0100)
src/yubiyubo.c [new file with mode: 0644]

diff --git a/src/yubiyubo.c b/src/yubiyubo.c
new file mode 100644 (file)
index 0000000..e01e492
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2008, Tollef Fog Heen <tfheen@err.no>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License.  You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Main functions for yubiyubo
+ */
+
+#include <hid.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+int main(int argc, char **argv)
+{
+       HIDInterface* hid;
+       hid_return ret;
+       char buf[128];
+       int path[2] = {0x00010006, 0xff000020};
+       int i;
+       bool reset = false;
+       HIDInterfaceMatcher matcher = { 0x1050, 0x0010, NULL, NULL, 0 };
+
+       ret = hid_init();
+       if (ret != HID_RET_SUCCESS) {
+               fprintf(stderr, "hid_init failed with return code %d\n", ret);
+               exit(1);
+       }
+
+       hid = hid_new_HIDInterface();
+       if (hid == NULL) {
+               fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
+               exit(1);
+       }
+
+       ret = hid_force_open(hid, 0, &matcher, 3);
+       if (ret != HID_RET_SUCCESS) {
+               fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
+               exit(1);
+       }
+
+       /* Do stuff with hid here */
+
+       ret = hid_close(hid);
+       if (ret != HID_RET_SUCCESS) {
+               fprintf(stderr, "hid_close failed with return code %d\n", ret);
+               exit(1);
+       }
+
+       hid_delete_HIDInterface(&hid);
+
+       ret = hid_cleanup();
+       if (ret != HID_RET_SUCCESS) {
+               fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
+               exit(1);
+       }
+
+       return 0;
+}
+
+
+}