-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusbtest.lua
More file actions
37 lines (24 loc) · 931 Bytes
/
usbtest.lua
File metadata and controls
37 lines (24 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local ffi = require'ffi'
local usb = require'ljusb'
local sched = require'lumen.sched'
local printf = function(...) io.write(string.format(...)) io.flush() end
local dev = usb:libusb_open_device_with_vid_pid(0x6444, 0x0001)
assert(dev ~= nil, "unable to open device")
--data transfer direction: device to host, class request, recipient: other
local main = function()
local v = usb.libusb_get_version()
printf("libusb v%i.%i.%i.%i\n", v.major, v.minor, v.micro, v.nano)
local bmRequestType_d2h = (0x80 + 0x20 + 0x03)
local trf = usb.Transfer()
local trf_waitd = {trf:event_any()}
trf:control_setup(
bmRequestType_d2h, 0, 0, 0, 2
):submit(dev)
printf("transfer submitted: %s\n", trf)
usb:start_event_handler():set_as_attached()
sched.wait(trf_waitd)
printf("setting count: %i\n", tonumber(ffi.cast('uint16_t *', trf.buffer + 8)[0]))
end
sched.run(main)
sched.loop()
--usb:libusb_exit()