Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alinanova21/node-gadget
Node.js library and utility to manage Configfs USB Gadgets
https://github.com/alinanova21/node-gadget
Last synced: about 1 month ago
JSON representation
Node.js library and utility to manage Configfs USB Gadgets
- Host: GitHub
- URL: https://github.com/alinanova21/node-gadget
- Owner: AlinaNova21
- Created: 2016-06-15T18:03:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T14:11:12.000Z (almost 2 years ago)
- Last Synced: 2024-05-02T01:31:43.431Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 125 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node project for managing OTG USB gadgets
## Requirements
* Recent kernel with configfs support 4.0 or higher recommended
* libcomposite module loaded
* A supported device with a OTG port## Supported devices:
### Tested
* CHIP (Requires building a kernel with USB gadgets set to use configfs)
* Pi Zero
* Pi4### Untested
* Any SoC with OTG and a recent kernel supporting configfs## Installation
### CLI
`npm install -g ags131/node-gadget`### Module
`npm install ags131/node-gadget`## Usage
### CLI
```
Usage: gadget argslibcomposite module MUST be loaded.
sudo modprobe libcompositeOptions:
-h --help this help
-c --create jsonfile create gadget
-r --remove id remove gadget
-e --enable id enable gadget
-d --disable id disable gadgetTypes:
jsonfile file containing gadget config
id id of gadget
udc name of udc device (Automatic if omitted)
```### Module API
#### Gadget class
`const { Gadget } = require('node-gadget')`##### Gadget(config)
config is a JSON object. See Examples for example jsons#### Methods
##### create(cb)
Creates the gadget on the system
Does not enable the gadget##### remove(cb)
Removes the gadget##### enable(udc,cb)
enables the gadget with the provided udc
udc can be left undefined to automatically select the default udc##### disable(cb)
Disables the gadget
This does not remove it from the system#### Static Methods
##### create(config,cb)
Creates the gadget on the system from the config
Does not enable the gadget##### remove(id,cb)
Removes the gadget##### enable(id,udc,cb)
enables the gadget using the provided udc
udc can be left undefined to automatically select the default udc##### disable(id,cb)
Disables the gadget
This does not remove it from the system##### getHIDStream(name || index)
returns a Duplex stream for the HID Device.
NOTE: this assumes linux creates the /dev/hidg* devices in the right order,
more than one HID device may screw with this.