{"id":18779414,"url":"https://github.com/zostay/raku-device-hidapi","last_synced_at":"2025-12-18T00:30:19.468Z","repository":{"id":66558040,"uuid":"199888972","full_name":"zostay/raku-Device-HIDAPI","owner":"zostay","description":"Low-level interface to hidapi from Perl 6","archived":false,"fork":false,"pushed_at":"2020-02-08T16:30:48.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T10:29:20.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zostay.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-31T16:06:56.000Z","updated_at":"2021-05-14T15:57:56.000Z","dependencies_parsed_at":"2023-04-06T08:06:11.979Z","dependency_job_id":null,"html_url":"https://github.com/zostay/raku-Device-HIDAPI","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-Device-HIDAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-Device-HIDAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-Device-HIDAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-Device-HIDAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zostay","download_url":"https://codeload.github.com/zostay/raku-Device-HIDAPI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239690606,"owners_count":19681130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:20:00.328Z","updated_at":"2025-12-18T00:30:19.418Z","avatar_url":"https://github.com/zostay.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"class Device::HIDAPI::InternalDeviceInfo\n----------------------------------------\n\nhidapi info structure from C\n\nclass Device::HIDAPI::DeviceInfo\n--------------------------------\n\nThe hidapi device info structure provided to Perl 6 callers\n\n### sub hid_exit\n\n```perl6\nsub hid_exit() returns int32\n```\n\nInitialize the HIDAPI library.\n\n### sub hid_enumerate\n\n```perl6\nsub hid_enumerate(\n    uint16 $vendor-id,\n    uint16 $product-id\n) returns NativeCall::Types::Pointer[Device::HIDAPI::InternalDeviceInfo]\n```\n\nEnumerate the HID Devices\n\n### sub hid_free_enumeration\n\n```perl6\nsub hid_free_enumeration(\n    NativeCall::Types::Pointer[Device::HIDAPI::InternalDeviceInfo] $devs\n) returns Mu\n```\n\nFree an enumeration Linked List\n\n### sub hid_open\n\n```perl6\nsub hid_open(\n    uint16 $vendor-id,\n    uint16 $product-id,\n    Str $serial-number\n) returns Device::HIDAPI\n```\n\nOpen a HID device using a Vendor ID (VID, Product ID (PID) and optionally a serial number.\n\n### sub hid_open_path\n\n```perl6\nsub hid_open_path(\n    Str $path\n) returns Device::HIDAPI\n```\n\nOpen a HID device by its path name.\n\n### sub hid_write\n\n```perl6\nsub hid_write(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[uint8] $data,\n    NativeCall::Types::size_t $length\n) returns int32\n```\n\nWrite an Output report to a HID device.\n\n### sub hid_read_timeout\n\n```perl6\nsub hid_read_timeout(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[uint8] $data,\n    NativeCall::Types::size_t $length,\n    uint32 $milliseconds\n) returns int32\n```\n\nRead an Input report from a HID device with timeout.\n\n### sub hid_read\n\n```perl6\nsub hid_read(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[uint8] $data,\n    NativeCall::Types::size_t $length\n) returns int32\n```\n\nRead an Input report from a HID device.\n\n### sub hid_set_nonblocking\n\n```perl6\nsub hid_set_nonblocking(\n    Device::HIDAPI $dev,\n    int32 $nonblock\n) returns int32\n```\n\nSet the device handle to be non-blocking.\n\n### sub hid_send_feature_report\n\n```perl6\nsub hid_send_feature_report(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[uint8] $data,\n    NativeCall::Types::size_t $length\n) returns int32\n```\n\nSend a Feature report to the device.\n\n### sub hid_get_feature_report\n\n```perl6\nsub hid_get_feature_report(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[uint8] $data,\n    NativeCall::Types::size_t $length\n) returns int32\n```\n\nGet a feature report from a HID device.\n\n### sub hid_close\n\n```perl6\nsub hid_close(\n    Device::HIDAPI $dev\n) returns Mu\n```\n\nClose a HID device.\n\n### sub hid_get_manufacturer_string\n\n```perl6\nsub hid_get_manufacturer_string(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[int32] $string,\n    NativeCall::Types::size_t $maxlen\n) returns int32\n```\n\nGet The Manufacturer String from a HID device.\n\n### sub hid_get_product_string\n\n```perl6\nsub hid_get_product_string(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[int32] $string,\n    NativeCall::Types::size_t $maxlen\n) returns int32\n```\n\nGet The Product String from a HID device.\n\n### sub hid_get_serial_number_string\n\n```perl6\nsub hid_get_serial_number_string(\n    Device::HIDAPI $dev,\n    NativeCall::Types::CArray[int32] $string,\n    NativeCall::Types::size_t $maxlen\n) returns int32\n```\n\nGet The Serial Number String from a HID device.\n\n### sub hid_get_indexed_string\n\n```perl6\nsub hid_get_indexed_string(\n    Device::HIDAPI $dev,\n    int32 $string-index,\n    NativeCall::Types::CArray[int32] $string,\n    NativeCall::Types::size_t $maxlen\n) returns int32\n```\n\nGet a string from a HID device, based on its string index.\n\n### sub hid_error\n\n```perl6\nsub hid_error(\n    Device::HIDAPI $dev\n) returns Str\n```\n\nGet a string describing the last error which occurred.\n\nNAME\n====\n\nDevice::HIDAPI - low-level HID interface\n\nSYNOPSIS\n========\n\n    use Device::HIDAPI;\n\n    # Read the raw inputs from an XBox One controller\n    sub MAIN(Str $path) {\n\n        # $path is the device path\n        my $hid = Device::HIDAPI.new($path);\n\n        loop {\n            my $data = $dev.read;\n\n            # Read the positions of the left stick\n            my $lsx = $data.read-int16(6);\n            my $lsy = $data.read-int16(8);\n\n            say \"$lsx, $lsy\";\n        }\n    }\n\nDESCRIPTION\n===========\n\nIf you need to perform low-level interfacing with a HID (device implementing the Human Interface Device protocol), this library is for you. It depends on a C library named hidapi, which you can get from the libusb project (see INSTALLATION for details).\n\nThis is a low-level library, so if you want to interface with a keyboard, mouse, joystick or other standard equipment, there's probably a better way. However, if you have a HID that implements a custom protocol or you need to get to the raw device data for some reason, this library will get you there. It provides a binary interface to read and write data to HIDs.\n\nCLASSES\n=======\n\nDevice::HIDAPI\n--------------\n\nThis class is the primary interface for enumerating devices, All the methods defined under METHODS below belong to this class.\n\nDevice::HIDAPI::Config\n----------------------\n\nThis is a special compile-time generated class that configures the library to use. You should never need to do anythign with this yourself.\n\nDevice::HIDAPI::DeviceInfo\n--------------------------\n\nObjects of this type are returned by the device enumeration method. It provides the following read-only attributes about each device:\n\nPod::Defn\u003c140187063716320\u003e\n\nPod::Defn\u003c140187063716264\u003e\n\nPod::Defn\u003c140187063716208\u003e\n\nPod::Defn\u003c140187063716096\u003e\n\nPod::Defn\u003c140187071420720\u003e\n\nPod::Defn\u003c140187071420664\u003e\n\nPod::Defn\u003c140187071420608\u003e\n\nPod::Defn\u003c140187071420552\u003e\n\nPod::Defn\u003c140187071420496\u003e\n\nPod::Defn\u003c140187071420440\u003e\n\nX::Device::HIDAPI\n-----------------\n\nThis is the exception object used whenever a wrapped `hidapi` function returns an error. It provides two attributes:\n\nPod::Defn\u003c140187071420272\u003e\n\nPod::Defn\u003c140187071420216\u003e\n\nMETHODS\n=======\n\nmethod enumerate\n----------------\n\n    method enumerate(Device::HIDAPI:_:\n        UInt $vendor-id = 0,\n        UInt $product-id = 0,\n        --\u003e Seq\n    )\n\nThis method is used to enumerate the devices known to the system.\n\n    # list all the VIDs and PIDs\n    for Device::HIDAPI.enumerate -\u003e $dev {\n        say \"$dev.vendor-id():$dev.product-id() \"\n          ~ \"- $dev.manufacturer-string(): \"\n          ~ \"$dev.product-string()\";\n    }\n\nThe `$vendor-id` and `$product-id` can be set to specific numbers to list only devices matching those IDs. A value of 0 (the default) matches all IDs (i.e., list all).\n\nmethod new\n----------\n\n    multi method new(Device::HIDAPI:U:\n        UInt :$vendor-id!,\n        UInt :$product-id!,\n        Str :$serial-number,\n        --\u003e Device::HIDAPI:D\n    )\n\n    multi method new(Device::HIDAPI:U:\n        Str:D :$path!\n        --\u003e Device::HIDAPI:D\n    )\n\nThese constructors return an instance of `Device::HIDAPI`, which can be used to read from and write to the device. You may construct the object either using the `$vendor-id` and the `$product-id` or the `$path` to the device. It is possible to have multiple of the same device connected, in which case you may also want to provide the `$serial-number` when using the VID and PID.\n\nmethod write\n------------\n\n    method write(Device::HIDAPI:D: blob8 $data --\u003e UInt:D)\n\nWrites the given blob to the device. Returns the number of bytes actually written.\n\nmethod read-timeout\n-------------------\n\n    method read-timeout(Device::HIDAPI:D: UInt:D $millis --\u003e blob8:D)\n\nReads data from the device or fails with an exception. If the device does not return anything within `$millis` milliseconds it returns an empty `Blob`.\n\nThrows an exception if there's an error during the read.\n\nmethod read\n-----------\n\n    method read(Device::HIDAPI:D: --\u003e blob8:D)\n\nReads data from the device. Unless the object has been set to use non-blocking operations, this operation will block until data becomes available. If non-blocking has been set, then this will return data if any is waiting or return an empty `Blob` immediately if none is currently ready to read.\n\nThrows an exception if there's an error during the read.\n\nmethod set-nonblocking\n----------------------\n\n    method set-nonblocking(Device::HIDAPI:D: Bool:D $nonblock)\n\nSets the device as non-blocking or not based on the value of `$nonblock`. If the object is set to non-blocking, then calls to [/method read](/method read) will not block.\n\nMay throw an exception if an error occurs making a change to the device object.\n\nmethod send-feature-report\n--------------------------\n\n    method send-feature-report(Device::HIDAPI:D: blob8 $data --\u003e UInt:D)\n\nSends a feature rreport to the device. Returns the number of bytes written.\n\nThrows an exception if there is an error performing the write.\n\nmethod get-feature-report\n-------------------------\n\n    method get-feature-report(Device::HIDAPI:D: --\u003e blob8:D)\n\nRetrieve a feature report from the device.\n\nThrows an exception if there is an error performing the read.\n\nmethod close\n------------\n\n    method close(Device::HIDAPI:D:)\n\nCloses the device and frees up associated resources. You should call this manually after creating the object if you want to make sure resources are freed before the garbage collector gets around to freeing memory:\n\n    # You can make calling this automatic when the variable goes out of scope\n    # like this...\n    my Device::HIDAPI:D $dev is leave({ .close }) .= new($path);\n\nThrows an error if there is a problem releasing the object.\n\nmethod get-manufacturer-string\n------------------------------\n\n    method get-manufacturer-string(Device::HIDAPI:D: --\u003e Str:D)\n\nRetrieves the manufacturer string from the device.\n\nThrows an error if there's a problem getting the data from the device.\n\nmethod get-product-string\n-------------------------\n\n    method get-product-string(Device::HIDAPI:D: --\u003e Str:D)\n\nRetrieves the product string from the device.\n\nThrows an error if there's a problem getting the data from the device.\n\nmethod get-serial-number-string\n-------------------------------\n\n    method get-serial-number-string(Device::HIDAPI:D: --\u003e Str:D)\n\nRetrieves the serial number string from the device.\n\nThrows an error if there's a problem getting the data from the device.\n\nmethod get-indexed-string\n-------------------------\n\n    method get-indexed-string(Device::HIDAPI:D: Int:D: $index --\u003e Str)\n\nGiven an index, returns the indexed string from the device.\n\nThrows an error if there's a problem getting the data from the device.\n\nDIAGNOSTICS\n===========\n\nAll exceptions generated by the wrapped hidapi library will be thrown using the `X::Device::HIDAPI` class. The error string set by the `hidapi` library can be found in the `hid-error` attribute (which may be undefined in certain cases, which will show up as \"unknown error\" in the exception message). The `where` attribute on the exception will name the `hidapi` function that was called that caused the error.\n\nMORE INFORMATION\n================\n\nIf you want more detail regarding how each of the methods in this interface work. You should see the documentation of the wrapped library here:\n\n  * [https://github.com/libusb/hidapi](https://github.com/libusb/hidapi)\n\nThe methods of this interface all map into functions in the original C library with one-to-one correspondance. It should be clear which methods call which function.\n\nINSTALLATION\n============\n\nTo install this library, you will first need to install the C library. See the latest instructions at the hidapi project page here:\n\n  * [https://github.com/libusb/hidapi](https://github.com/libusb/hidapi)\n\nIf you install a pre-packaged binary, make sure it's a development package that includes all the headers as well as the libraries (on Debian-type Linuxes, this means the package iwth the `-dev` suffix).\n\nOnce installed, this can be installed like any other Perl 6 module:\n\n    zef install Device::HIDAPI\n\nThat should work on Linux, Mac, and Windows.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-device-hidapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzostay%2Fraku-device-hidapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-device-hidapi/lists"}