;; in's are 0x80
;; out's are 0x90
(bind-func xhid_open
(lambda (vendor_id:i64 product_id:i64 interface:i32)
(let ((stdout (fdopen 0 "w"))
(stderr (fdopen 1 "w"))
(hid:HIDInterface* null)
(ret:hid_return 0)
;; (vendor_id #x046d)
;; (product_id #xc408)
(iface_num interface)
(matcher (HIDInterfaceMatcher (convert vendor_id)
(convert product_id)
null null 0)))
(hid_set_debug (convert (bor #x1 #x2)))
(hid_set_debug_stream stderr)
(println "vendor id:" vendor_id "product id:" product_id)
(set! ret (hid_init))
(if (<> ret 0) (printf "%d,%s\n" ret (hid_strerror ret)))
(set! hid (hid_new_HIDInterface))
(printf "HID: %p\n" hid)
(set! ret (hid_force_open hid iface_num matcher 3))
(if (<> ret 0) (printf "%d,%s\n" ret (hid_strerror ret)))
(set! ret (hid_write_identification stdout hid))
(if (<> ret 0) (printf "%s\n" (hid_strerror ret)))
(set! ret (hid_dump_tree stdout hid))
(if (<> ret 0) (printf "%s\n" (hid_strerror ret)))
hid)))