Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
*.log
*.swp
*.swo
8 changes: 2 additions & 6 deletions examples/balls/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Rect } from '@laser-dac/draw';
import { Ball } from './Ball';

const NUMBER_OF_BALLS = 4;

(async () => {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());
await dac.start();

const balls: Ball[] = [];
Expand Down
8 changes: 2 additions & 6 deletions examples/font/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, HersheyFont, loadHersheyFont, Timeline } from '@laser-dac/draw';
import * as path from 'path';

Expand Down Expand Up @@ -38,10 +37,7 @@ const textAnimation = new Timeline({

(async () => {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());
await dac.start();

const scene = new Scene();
Expand Down
8 changes: 2 additions & 6 deletions examples/ilda-animation/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Ilda, loadIldaFile } from '@laser-dac/draw';
import * as path from 'path';

const boeing = loadIldaFile(path.resolve(__dirname, './boeing.ild'));

(async () => {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());
await dac.start();

const scene = new Scene();
Expand Down
8 changes: 2 additions & 6 deletions examples/pong/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Rect } from '@laser-dac/draw';
import { Player } from './Player';
import { Ball } from './Ball';
Expand All @@ -27,10 +26,7 @@ export class Renderer {

async start() {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());
await dac.start();

const ball = new Ball({
Expand Down
8 changes: 2 additions & 6 deletions examples/square-interactive/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Rect, loadIldaFile, Ilda } from '@laser-dac/draw';
import * as path from 'path';

Expand Down Expand Up @@ -48,10 +47,7 @@ export class Renderer {

async start() {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());
await dac.start();

const scene = new Scene();
Expand Down
8 changes: 2 additions & 6 deletions examples/static-shapes/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { Helios } from '@laser-dac/helios';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Rect, Path, Line } from '@laser-dac/draw';

(async () => {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new Helios());
}
dac.useAll(await getDevices());
await dac.start();

const scene = new Scene({
Expand Down
9 changes: 3 additions & 6 deletions examples/svg-path/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { DAC } from '@laser-dac/core';
import { Simulator } from '@laser-dac/simulator';
import { EtherDream } from '@laser-dac/ether-dream';
import { getDevices } from '@laser-dac/device-selector';
import { Scene, Svg, loadSvgFile } from '@laser-dac/draw';
import * as path from 'path';

const logoFile = loadSvgFile(path.resolve(__dirname, './logo.svg'));

(async () => {
const dac = new DAC();
dac.use(new Simulator());
if (process.env.DEVICE) {
dac.use(new EtherDream());
}
dac.useAll(await getDevices());

await dac.start();

const scene = new Scene({
Expand Down
5 changes: 4 additions & 1 deletion packages/beyond/src/BeyondLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const libPath = path
// dont'get placed inside the "app.asar" bundle, but instead get placed in a separate directory called "app.asar.unpacked"
.replace('app.asar', 'app.asar.unpacked');

const BeyondLib = ffi.Library(libPath, {
// Even Windows 64-bit is called win32 here.
const isSupported = process.platform === "win32";

const BeyondLib = isSupported && ffi.Library(libPath, {
ldbCreate: ['int', []],
ldbDestroy: ['int', []],
ldbBeyondExeReady: ['int', []],
Expand Down
7 changes: 7 additions & 0 deletions packages/beyond/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class Beyond extends Device {
private started = false;

async start() {
if (!this.isSupported()) {
return false;
}
this.stop();
beyondLib.ldbCreate();
this.started = true;
Expand All @@ -37,6 +40,10 @@ export class Beyond extends Device {
}
}

isSupported(): boolean {
return process.platform === "win32";
}

private convertPoint(p: Point) {
return {
x: relativeToPosition(p.x),
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export abstract class Device {
abstract start(): Promise<boolean>;
abstract stop(): void;
abstract stream(scene: Scene, pointsRate: number, fps: number): void;

isSupported(): boolean {
return true;
};
}

export class DAC {
Expand All @@ -26,6 +30,10 @@ export class DAC {
this.devices.push(device);
}

useAll(devices: Device[]) {
devices.forEach((device) => this.use(device));
}

remove(device: Device) {
const index = this.devices.indexOf(device);
if (index) {
Expand Down
35 changes: 35 additions & 0 deletions packages/device-selector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# @laser-dac/device-selector

This package is an easy adapter for multiple devices.

```
yarn add @laser-dac/device-selector
npm i @laser-dac/device-selector
```

## Usage

```js
import { DAC } from '@laser-dac/core';
import { getDevices } from '@laser-dac/device-selector';

const dac = new DAC();
// Automatically select a supported device and a Simulator.
dac.useAll(await getDevices());
const started = await dac.start();
if (started) {
const pps = 30000; // points per second
const fps = 120; // frames per second
// draw a horizontal red line from left to right in the center
// @laser-dac/draw can help you with drawing points!
const scene = {
points: [
{ x: 0.1, y: 0.5, r: 1, g: 0, b: 0 },
{ x: 0.9, y: 0.5, r: 1, g: 0, b: 0 }
]
};
dac.stream(scene, pps, fps);
}
```

See for more usage info and examples the [Laser DAC project on GitHub](https://github.com/Volst/laser-dac).
35 changes: 35 additions & 0 deletions packages/device-selector/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@laser-dac/device-selector",
"version": "0.4.1",
"description": "Device-selecting adapter for laser-dac",
"license": "MIT",
"author": "Sterling Hirsh <sterling@sterlinghirsh.com>",
"repository": "Volst/laser-dac",
"keywords": [
"laser"
],
"engines": {
"node": ">=8.0"
},
"main": "dist/index.js",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"dependencies": {
"@laser-dac/core": "^0.4.1",
"@laser-dac/beyond": "^0.3.0",
"@laser-dac/easylase": "^0.2.0",
"@laser-dac/ether-dream": "^0.4.1",
"@laser-dac/helios": "^0.3.0",
"@laser-dac/laserdock": "^0.4.0",
"@laser-dac/simulator": "^0.3.3"
},
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.build.json",
"watch": "tsc -p tsconfig.build.json --watch",
"prepublishOnly": "npm run -s build"
}
}
52 changes: 52 additions & 0 deletions packages/device-selector/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Device } from '@laser-dac/core';

import { Simulator } from '@laser-dac/simulator';

import { Beyond } from '@laser-dac/beyond';
import { Easylase } from '@laser-dac/easylase';
import { EtherDream } from '@laser-dac/ether-dream';
import { Helios } from '@laser-dac/helios';
import { Laserdock } from '@laser-dac/laserdock';

const apis: Record<string, {new (): Device}> = {
helios: Helios,
laserdock: Laserdock,
beyond: Beyond,
easylase: Easylase,
'ether-dream': EtherDream // This one is a bit slower to check.
};

// Get the first DAC that works.
export async function autoSelect(): Promise<Device|null> {
console.log("Searching for DAC in " + Object.keys(apis).join(', '));
for (const api in apis) {
const dac = new apis[api]();
if (await dac.start()) {
console.log("Auto Selected DAC " + api);
await dac.stop();
return dac;
}
}
console.log("No DAC found");
return null;
}

// Get a Simulator and the first autodetected device.
// TODO: Get multiple devices instead of just the first?
export async function getDevices(): Promise<Device[]> {
const devices: Device[] = [new Simulator()];
const requestedDevice = process.env.DEVICE;

if (requestedDevice) {
if (requestedDevice in apis) {
devices.push(new apis[requestedDevice]());
} else {
const autoSelected = await autoSelect();
if (autoSelected) {
devices.push(autoSelected);
}
}
}

return devices;
}
8 changes: 8 additions & 0 deletions packages/device-selector/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": ["src/index.ts"]
}
5 changes: 4 additions & 1 deletion packages/easylase/src/EasylaseLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const libPath = path
// dont'get placed inside the "app.asar" bundle, but instead get placed in a separate directory called "app.asar.unpacked"
.replace('app.asar', 'app.asar.unpacked');

const EasylaseLib = ffi.Library(libPath, {
// Even Windows 64-bit is called win32 here.
const isSupported = process.platform === "win32";

const EasylaseLib = isSupported && ffi.Library(libPath, {
jmLaserEnumerateDevices: ['int', []],
jmLaserStopOutput: ['int', ['int']],
jmLaserCloseDevice: ['int', ['int']],
Expand Down
8 changes: 8 additions & 0 deletions packages/easylase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class Easylase extends Device {
deviceHandle?: number;

async start() {
if (!this.isSupported()) {
return false;
}

this.stop();
const cards = easylaseLib.enumerateDevices();
if (cards) {
Expand All @@ -32,6 +36,10 @@ export class Easylase extends Device {
}
}

isSupported(): boolean {
return process.platform === "win32";
}

private convertPoint(p: Point) {
return {
x: relativeToPosition(p.x),
Expand Down