mirror of
https://github.com/moritzruth/node-enttec-open-dmx-usb.git
synced 2025-04-21 07:41:22 +02:00
No longer use @pika/pack and remove some events
This commit is contained in:
parent
8c0eefb9a4
commit
dc0e83c14c
8 changed files with 141 additions and 2739 deletions
|
@ -1,12 +1,3 @@
|
||||||
{
|
{
|
||||||
"extends": "awzzm-ts",
|
"extends": ["awzzm-ts", "awzzm-node"]
|
||||||
"env": {
|
|
||||||
"node": true,
|
|
||||||
"es6": true
|
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"sourceType": "module",
|
|
||||||
"ecmaVersion": 10,
|
|
||||||
"project": "tsconfig.json"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
pkg/
|
dist/
|
||||||
|
.idea/
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 Moritz Ruth
|
Copyright (c) 2019-2021 Moritz Ruth
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
30
README.md
30
README.md
|
@ -1,9 +1,16 @@
|
||||||
# node-enttec-open-dmx-usb
|
# node-enttec-open-dmx-usb 🔌
|
||||||
> A Node.js library for interacting with the
|
> A Node.js library for interacting with the
|
||||||
> [Enttec Open DMX USB Interface](https://www.enttec.co.uk/en/product/controls/dmx-usb-interfaces/open-dmx-usb/)
|
> [Enttec Open DMX USB Interface](https://www.enttec.co.uk/en/product/controls/dmx-usb-interfaces/open-dmx-usb/)
|
||||||
|
|
||||||
## Installation
|
Only tested on Windows, but as it uses `serialport` under the hood, it should also work in
|
||||||
```shell script
|
[these environments](https://serialport.io/docs/guide-platform-support#supported-platforms-and-architectures).
|
||||||
|
|
||||||
|
## Install
|
||||||
|

|
||||||
|
|
||||||
|
Minimum required Node.js version is `v14.0.0`.
|
||||||
|
|
||||||
|
```sh
|
||||||
yarn add enttec-open-dmx-usb
|
yarn add enttec-open-dmx-usb
|
||||||
# or
|
# or
|
||||||
npm install enttec-open-dmx-usb
|
npm install enttec-open-dmx-usb
|
||||||
|
@ -12,23 +19,26 @@ npm install enttec-open-dmx-usb
|
||||||
## Usage
|
## Usage
|
||||||
[**View documentation on jsdocs.io**](https://www.jsdocs.io/package/enttec-open-dmx-usb#EnttecOpenDMXUSBDevice)
|
[**View documentation on jsdocs.io**](https://www.jsdocs.io/package/enttec-open-dmx-usb#EnttecOpenDMXUSBDevice)
|
||||||
|
|
||||||
All functions are documented and the code is easy to understand, so feel free to [explore it](src/index.ts).
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { EnttecOpenDMXUSBDevice as DMXDevice } from "enttec-open-dmx-usb";
|
import { EnttecOpenDMXUSBDevice as DMXDevice } from "enttec-open-dmx-usb";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const device = new DMXDevice(await DMXDevice.getFirstAvailableDevice());
|
const device = new DMXDevice(await DMXDevice.getFirstAvailableDevice())
|
||||||
|
|
||||||
device.setChannels({
|
device.setChannels({
|
||||||
1: 0xFF,
|
1: 0xFF,
|
||||||
2: 0x44
|
2: 0x44
|
||||||
});
|
})
|
||||||
|
|
||||||
// same as
|
// same as
|
||||||
device.setChannels([0xFF, 0x44]);
|
device.setChannels([0xFF, 0x44])
|
||||||
|
|
||||||
// same as
|
// same as
|
||||||
device.setChannels(Buffer.from([0xFF, 0x44]));
|
device.setChannels(Buffer.from([0xFF, 0x44]))
|
||||||
})();
|
})()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Events
|
||||||
|
`ready` - `startSending` can be called.
|
||||||
|
|
||||||
|
`error` - An error occurred.
|
||||||
|
|
38
package.json
38
package.json
|
@ -5,39 +5,33 @@
|
||||||
"repository": "https://github.com/moritzruth/node-enttec-open-dmx-usb.git",
|
"repository": "https://github.com/moritzruth/node-enttec-open-dmx-usb.git",
|
||||||
"author": "Moritz Ruth <dev@moritzruth.de>",
|
"author": "Moritz Ruth <dev@moritzruth.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"dmx",
|
"dmx",
|
||||||
"enttec",
|
"enttec",
|
||||||
"usb"
|
"usb"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pika build",
|
"build": "tsc",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src"
|
||||||
"version": "yarn build",
|
|
||||||
"test": "echo There are no tests",
|
|
||||||
"pub": "pika publish"
|
|
||||||
},
|
},
|
||||||
"@pika/pack": {
|
"files": [
|
||||||
"pipeline": [
|
"dist"
|
||||||
[
|
],
|
||||||
"@pika/plugin-ts-standard-pkg"
|
"engines": {
|
||||||
],
|
"node": ">=14.0.0"
|
||||||
[
|
|
||||||
"@pika/plugin-build-node"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@pika/pack": "^0.5.0",
|
"@types/node": "^14.14.31",
|
||||||
"@pika/plugin-build-node": "^0.9.2",
|
|
||||||
"@pika/plugin-ts-standard-pkg": "^0.9.2",
|
|
||||||
"@types/node": "^14.0.27",
|
|
||||||
"@types/serialport": "^8.0.1",
|
"@types/serialport": "^8.0.1",
|
||||||
"eslint": "^7.6.0",
|
"eslint": "^7.20.0",
|
||||||
"eslint-config-awzzm-ts": "^1.0.1",
|
"eslint-config-awzzm-node": "^1.5.0",
|
||||||
"typescript": "^4.0.2"
|
"eslint-config-awzzm-ts": "^1.5.2",
|
||||||
|
"typescript": "~4.1.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"serialport": "^9.0.0"
|
"eventemitter3": "^4.0.7",
|
||||||
|
"serialport": "^9.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
src/index.ts
15
src/index.ts
|
@ -1,12 +1,17 @@
|
||||||
import { EventEmitter } from "events"
|
import { EventEmitter } from "eventemitter3"
|
||||||
import SerialPort from "serialport"
|
import SerialPort from "serialport"
|
||||||
|
|
||||||
export const VENDOR_ID = "0403" // Enttec
|
export const VENDOR_ID = "0403" // Enttec
|
||||||
export const PRODUCT_ID = "6001" // Open DMX USB
|
export const PRODUCT_ID = "6001" // Open DMX USB
|
||||||
|
|
||||||
export class EnttecOpenDMXUSBDevice extends EventEmitter {
|
interface Events {
|
||||||
|
ready: []
|
||||||
|
error: [Error]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EnttecOpenDMXUSBDevice extends EventEmitter<Events> {
|
||||||
private shouldBeSending = false
|
private shouldBeSending = false
|
||||||
private sendTimeout: NodeJS.Timeout | null = null
|
private sendTimeout: ReturnType<typeof setTimeout> | null = null
|
||||||
private buffer = Buffer.alloc(513)
|
private buffer = Buffer.alloc(513)
|
||||||
private readonly port: SerialPort
|
private readonly port: SerialPort
|
||||||
|
|
||||||
|
@ -40,7 +45,6 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
|
||||||
startSending(interval = 0) {
|
startSending(interval = 0) {
|
||||||
if (!this.port.isOpen) throw new Error("The device is not ready yet. Wait for the 'ready' event.")
|
if (!this.port.isOpen) throw new Error("The device is not ready yet. Wait for the 'ready' event.")
|
||||||
|
|
||||||
this.emit("sending-started", interval)
|
|
||||||
this.shouldBeSending = true
|
this.shouldBeSending = true
|
||||||
|
|
||||||
// eslint-disable-next-line unicorn/consistent-function-scoping
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||||
|
@ -61,7 +65,6 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
|
||||||
* Stops sending.
|
* Stops sending.
|
||||||
*/
|
*/
|
||||||
stopSending() {
|
stopSending() {
|
||||||
this.emit("sending-stopped")
|
|
||||||
this.shouldBeSending = false
|
this.shouldBeSending = false
|
||||||
|
|
||||||
if (this.sendTimeout !== null) clearTimeout(this.sendTimeout)
|
if (this.sendTimeout !== null) clearTimeout(this.sendTimeout)
|
||||||
|
@ -74,7 +77,7 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
|
||||||
* @param {Buffer|Object|Array} channels
|
* @param {Buffer|Object|Array} channels
|
||||||
* @param {boolean} [clear=false] Whether all previously assigned channels should be set to 0
|
* @param {boolean} [clear=false] Whether all previously assigned channels should be set to 0
|
||||||
*/
|
*/
|
||||||
setChannels(channels: Buffer | number[] | { [key: number]: number }, clear = false) {
|
setChannels(channels: Buffer | number[] | Record<number, number>, clear = false) {
|
||||||
if (clear) {
|
if (clear) {
|
||||||
this.buffer = Buffer.alloc(513)
|
this.buffer = Buffer.alloc(513)
|
||||||
this.buffer[0] = 0
|
this.buffer[0] = 0
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "es2019",
|
||||||
"module": "ESNext",
|
"module": "commonjs",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "node",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"declaration": true,
|
||||||
|
"types": ["@types/node"],
|
||||||
|
"lib": ["es2019"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue