+/*
+ *
+ * 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.
+ *
+ */
+
+#include <stdbool.h>
+#include "ykusb.h"
+
+#define CYPAK_VID 0x1050
+#define YK_PID 0x0010
+#define FEATURE_RPT_SIZE 9
+
+HIDInterface *yk_open()
+{
+ HIDInterface* hid;
+ HIDInterfaceMatcher matcher = { CYPAK_VID, YK_PID, NULL, NULL, 0 };
+ hid_return ret;
+
+ ret = hid_init();
+ if (ret != HID_RET_SUCCESS) {
+ fprintf(stderr, "hid_init failed with return code %d\n", ret);
+ return NULL;
+ }
+
+ hid = hid_new_HIDInterface();
+ if (hid == NULL) {
+ fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
+ return NULL;
+ }
+
+ 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);
+ return NULL;
+ }
+
+}
+void yk_close(HIDInterface *hid)
+{
+ hid_return ret;
+
+ 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);
+ }
+}
+
+bool yk_send(HIDInterface *hid, char slot, char *data, size_t length)
+{
+
+ char buf[FEATURE_RPT_SIZE], sbuf[FEATURE_RPT_SIZE],
+ usbdata[(FEATURE_RPT_SIZE + 1 * 10)];
+ int i, j;
+ unsigned short crc;
+
+ if (length > 64) {
+ return false;
+ }
+
+ memset(usbdata, 0, sizeof(usbdata));
+ memcpy(usbdata, data, length);
+ crc = crc_get_full(usbdata, 64, false);
+
+ data[64] = slot;
+ data[65] = (crc & 0xff);
+ data[66] = (crc >> 8);
+
+
+}
+
+bool yk_get_status(HIDInterface *hid, STATUS *status, bool force_update);