lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

Here's something for embedded hardware people...

I have a preliminary binding for hidapi[1] working (on WinXP). hidapi is a cross-platform library for working with USB HID devices and on Win32, it allows for convenient driverless interfacing -- enough for low data rate stuff and simple to use versus the alternatives.[2]

All hidapi API calls are (mostly) implemented. However, things like Unicode strings are currently truncated to ASCII, so a proper "nice-and-sane" release still needs work. The binding code is already all non-platform-specific, I think.

I don't think I want to maintain a repository in the long term and do releases, so if anyone wants to play with it or incorporate it into a relevant codebase, I'm more than happy to shovel it to you. The usual Lua-like license can be used.

Not all of the binding has been tested, but enumeration works, sending and receiving reports using a PIC18 with a vendor-defined USB HID works.

Sample (edited) snippets from test script:
==========================================

local hid = require "luahidapi"

hid.init()
local dev = hid.open(DEVICE_VID, DEVICE_PID)

local mstr = dev:getstring("manufacturer")
print("Manufacturer String: "..mstr)
local pstr = dev:getstring("product")
print("Product String: "..pstr)

local tx = "ABCD" -- write default report 0
local result = dev:write(tx)
print("Writing "..tx.." to device")

local rx -- read default report 0
dev:set("noblock")
for i = 1, 10 do
  rx = dev:read(4)
  if rx == "" then print("Waiting...")
  else break end
  for j = 1,200000 do end -- delay
end
print("Read "..rx.." from device")

dev:close()
hid.exit()

[1] http://www.signal11.us/oss/hidapi/
[2] WinUSB, libusb-win32, libusbx-win, ...

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia