Skip to content

Commit

Permalink
tweak wording & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Mar 11, 2024
1 parent 61759b1 commit 9acb846
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 5 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ const sACNServer = new Sender({

async function main() {
await sACNServer.send({
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)
payload: {
// Required. An object with the percentages (0-100) for each DMX channel.
// You can use 0-255 instead of 0-100 by setting `useRawDmxValues: true`
// per packet, or in the `defaultPacketOptions`.
1: 100,
2: 50,
3: 0,
Expand All @@ -113,7 +116,6 @@ async function main() {
}

main(); // wrapped in a main() function so that we can `await` the promise

```

### Table 3 - Options for Sender
Expand Down Expand Up @@ -147,6 +149,7 @@ The Architecture for Control Networks (ACN) and derived protocols are created by
- RDMNet is defined in [ANSI E1.33](./docs/E1.33-2019.pdf)

---

<small id="footnote1">

1&shy;. Unicast is also supported by default, but this is not how sACN normally works. See [_Table 3_](#table-3---options-for-sender) for how to send data directly to a unicast address. [](#footnote-source1)
Expand Down
4 changes: 2 additions & 2 deletions src/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface Options {
cid?: Packet['cid'];
/**
* Whether to use 0-100 or 0-255 scale when creating the packet
* false (default): 0-100
* true: 0-255
* - `false` (default): 0-100
* - `true`: 0-255
*/
useRawDmxValues?: Packet['useRawDmxValues'];
}
Expand Down
25 changes: 25 additions & 0 deletions test/packet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,29 @@ describe('Simple Packet', () => {
// double wrapped so that it converts to buffer and back
assert.deepStrictEqual(new Packet(packet.buffer).payload, {});
});

it('correctly sets channel values from the [0-100] range', () => {
const packet = new Packet({
universe: 1,
payload: { 1: 91.76, 2: 100, 4: 100 },
sequence: 172,
});
assert.deepStrictEqual(
packet.buffer.slice(126, 130), // first 4 channel values
Buffer.from([0xea, 0xff, 0, 0xff]),
);
});

it('correctly sets channel values from the [0-255] range', () => {
const packet = new Packet({
universe: 1,
payload: { 1: 234, 2: 255, 4: 255 },
sequence: 172,
useRawDmxValues: true,
});
assert.deepStrictEqual(
packet.buffer.slice(126, 130), // first 4 channel values
Buffer.from([0xea, 0xff, 0, 0xff]),
);
});
});

0 comments on commit 9acb846

Please sign in to comment.