1
0
Fork 0
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:
Moritz Ruth 2021-02-26 10:40:18 +01:00
parent 8c0eefb9a4
commit dc0e83c14c
No known key found for this signature in database
GPG key ID: AFD57E23E753841B
8 changed files with 141 additions and 2739 deletions

View file

@ -1,12 +1,3 @@
{
"extends": "awzzm-ts",
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 10,
"project": "tsconfig.json"
}
"extends": ["awzzm-ts", "awzzm-node"]
}

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
node_modules/
pkg/
dist/
.idea/

View file

@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

View file

@ -1,9 +1,16 @@
# node-enttec-open-dmx-usb
# node-enttec-open-dmx-usb 🔌
> 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/)
## Installation
```shell script
Only tested on Windows, but as it uses `serialport` under the hood, it should also work in
[these environments](https://serialport.io/docs/guide-platform-support#supported-platforms-and-architectures).
## Install
![npm](https://img.shields.io/npm/v/enttec-open-dmx-usb?style=flat-square)
Minimum required Node.js version is `v14.0.0`.
```sh
yarn add enttec-open-dmx-usb
# or
npm install enttec-open-dmx-usb
@ -12,23 +19,26 @@ npm install enttec-open-dmx-usb
## Usage
[**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
import { EnttecOpenDMXUSBDevice as DMXDevice } from "enttec-open-dmx-usb";
(async () => {
const device = new DMXDevice(await DMXDevice.getFirstAvailableDevice());
const device = new DMXDevice(await DMXDevice.getFirstAvailableDevice())
device.setChannels({
1: 0xFF,
2: 0x44
});
})
// same as
device.setChannels([0xFF, 0x44]);
device.setChannels([0xFF, 0x44])
// same as
device.setChannels(Buffer.from([0xFF, 0x44]));
})();
device.setChannels(Buffer.from([0xFF, 0x44]))
})()
```
## Events
`ready` - `startSending` can be called.
`error` - An error occurred.

View file

@ -5,39 +5,33 @@
"repository": "https://github.com/moritzruth/node-enttec-open-dmx-usb.git",
"author": "Moritz Ruth <dev@moritzruth.de>",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"keywords": [
"dmx",
"enttec",
"usb"
],
"scripts": {
"build": "pika build",
"lint": "eslint src",
"version": "yarn build",
"test": "echo There are no tests",
"pub": "pika publish"
"build": "tsc",
"lint": "eslint src"
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
"files": [
"dist"
],
[
"@pika/plugin-build-node"
]
]
"engines": {
"node": ">=14.0.0"
},
"devDependencies": {
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.9.2",
"@pika/plugin-ts-standard-pkg": "^0.9.2",
"@types/node": "^14.0.27",
"@types/node": "^14.14.31",
"@types/serialport": "^8.0.1",
"eslint": "^7.6.0",
"eslint-config-awzzm-ts": "^1.0.1",
"typescript": "^4.0.2"
"eslint": "^7.20.0",
"eslint-config-awzzm-node": "^1.5.0",
"eslint-config-awzzm-ts": "^1.5.2",
"typescript": "~4.1.5"
},
"dependencies": {
"serialport": "^9.0.0"
"eventemitter3": "^4.0.7",
"serialport": "^9.0.7"
}
}

View file

@ -1,12 +1,17 @@
import { EventEmitter } from "events"
import { EventEmitter } from "eventemitter3"
import SerialPort from "serialport"
export const VENDOR_ID = "0403" // Enttec
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 sendTimeout: NodeJS.Timeout | null = null
private sendTimeout: ReturnType<typeof setTimeout> | null = null
private buffer = Buffer.alloc(513)
private readonly port: SerialPort
@ -40,7 +45,6 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
startSending(interval = 0) {
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
// eslint-disable-next-line unicorn/consistent-function-scoping
@ -61,7 +65,6 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
* Stops sending.
*/
stopSending() {
this.emit("sending-stopped")
this.shouldBeSending = false
if (this.sendTimeout !== null) clearTimeout(this.sendTimeout)
@ -74,7 +77,7 @@ export class EnttecOpenDMXUSBDevice extends EventEmitter {
* @param {Buffer|Object|Array} channels
* @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) {
this.buffer = Buffer.alloc(513)
this.buffer[0] = 0

View file

@ -1,9 +1,13 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "Node",
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true
"esModuleInterop": true,
"outDir": "dist",
"declaration": true,
"types": ["@types/node"],
"lib": ["es2019"]
}
}

2769
yarn.lock

File diff suppressed because it is too large Load diff