Skip to content

Instantly share code, notes, and snippets.

@Efimero
Created May 5, 2022 19:31
Show Gist options
  • Save Efimero/488e8ac5b165643a875e8ed97c1d9389 to your computer and use it in GitHub Desktop.
Save Efimero/488e8ac5b165643a875e8ed97c1d9389 to your computer and use it in GitHub Desktop.
hidapi-test
#lang racket
(require hidapi
racket/future)
(hid-init)
(define devices (hid-enumerate))
(displayln (map hid-device-info-path devices))
(flush-output)
(map touch
(for/async [(device-info (in-list devices))]
(let [(device (hid-open-path (hid-device-info-path device-info)))]
(when device
(printf "Opened: ~a\n" (hid-device-info-path device-info))
(let [(repb (list->bytes (list* 1 0 (make-list 64 0))))]
(printf "~a: ~v\n" (bytes-length repb) repb)
(printf "Report:\n~a\n"
(begin
(hid-get-feature-report device repb (bytes-length repb))
(bytes->list repb))))
(flush-output)
(let loop [(data (hid-read-bytes/timeout device 64 300))]
(when (not (bytes=? #"" data))
(printf "~a\n" (bytes->list data))
(flush-output))
(sleep 1/60)
(loop (hid-read-bytes/timeout device 64 300)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment