From 61759b13c9cac9af9e5b8a9c94942d38de716d62 Mon Sep 17 00:00:00 2001 From: Varkonyi Kornel Date: Thu, 7 Sep 2023 19:27:28 +0200 Subject: [PATCH] Added option to use raw dmx values --- readme.md | 4 ++-- src/packet.ts | 18 +++++++++++++++++- src/sender.ts | 5 ++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 3cd0c12..5e6b9e0 100644 --- a/readme.md +++ b/readme.md @@ -100,7 +100,7 @@ const sACNServer = new Sender({ async function main() { await sACNServer.send({ - payload: { // required. object with the percentages for each DMX channel + payload: { // required. object with the percentages for each DMX channel (or set `useRawDmxValues` per packet or in the `defaultPacketOptions` for the Sender to use raw DMX values) 1: 100, 2: 50, 3: 0, @@ -123,7 +123,7 @@ main(); // wrapped in a main() function so that we can `await` the promise | `universe` | `number` | Required. The universes to listen to. Must be within 1-63999 | `[]` | | `port` | `number` | Optional. The multicast port to use. All professional consoles broadcast to the default port. | `5568` | | `reuseAddr` | `boolean` | Optional. Allow multiple programs on your computer to send to the same sACN universe. | -| `defaultPacketOptions` | `object` | Optional. You can specify options like `sourceName`, `cid`, and `priority` here instead of on every packet | +| `defaultPacketOptions` | `object` | Optional. You can specify options like `sourceName`, `cid`, `priority` and `useRawDmxValues` here instead of on every packet | | `iface` | `string` | Optional. Specifies the IPv4 address of the network interface/card to use. | OS default interface (=active internet connection) | `useUnicastDestination`| `string` | Optional. Setting this attribute to an IPv4 address will cause data to be sent directly to that device, instead of broadcasting to the whole LAN. | diff --git a/src/packet.ts b/src/packet.ts index b95d745..147bc3e 100644 --- a/src/packet.ts +++ b/src/packet.ts @@ -19,6 +19,12 @@ export interface Options { sourceName?: Packet['sourceName']; priority?: Packet['priority']; cid?: Packet['cid']; + /** + * Whether to use 0-100 or 0-255 scale when creating the packet + * false (default): 0-100 + * true: 0-255 + */ + useRawDmxValues?: Packet['useRawDmxValues']; } /** @@ -58,6 +64,8 @@ export class Packet { /* eslint-enable lines-between-class-members */ + private readonly useRawDmxValues: boolean = false; + public constructor( input: Buffer | Options, public readonly sourceAddress?: string, @@ -121,6 +129,10 @@ export class Packet { this.propertyValueCount = 0x0201; // "Indicates 1+ the number of slots in packet" // We set the highest possible value (1+512) so that channels with zero values are // treated as deliberately 0 (cf. undefined) + + if (options.useRawDmxValues) { + this.useRawDmxValues = true; + } } } @@ -168,7 +180,11 @@ export class Packet { for (const ch in this.payload) { if (+ch >= 1 && +ch <= 512) { - n[125 + +ch] = inRange(this.payload[ch]! * 2.55); + if (this.useRawDmxValues) { + n[125 + +ch] = inRange(this.payload[ch]!); + } else { + n[125 + +ch] = inRange(this.payload[ch]! * 2.55); + } } } diff --git a/src/sender.ts b/src/sender.ts index 5136344..d9a652f 100644 --- a/src/sender.ts +++ b/src/sender.ts @@ -16,7 +16,10 @@ export interface SenderProps { minRefreshRate?: number; /** some options can be sepecified when you instantiate the sender, instead of sepecifying them on every packet */ - defaultPacketOptions?: Pick; + defaultPacketOptions?: Pick< + Options, + 'cid' | 'sourceName' | 'priority' | 'useRawDmxValues' + >; // IPv4 address of the network interface iface?: string;