-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
559 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,3 +86,5 @@ typings/ | |
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
dist/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IPattern } from "../patterns/IPattern"; | ||
import { IBlyncDevice } from "../lib/IBlyncDevice"; | ||
import Bluebird from "bluebird"; | ||
import { Color } from "../patterns/Color"; | ||
import { IPatternEngine } from "./IPatternEngine"; | ||
|
||
export class FixedDelayPatternProcessor implements IPatternEngine { | ||
private _createCommand([red, green, blue]: Color) { | ||
return { | ||
red, | ||
green, | ||
blue, | ||
blink: 0 as 0 | 1 | 2 | 3, | ||
dim: false | ||
}; | ||
} | ||
async process({ colors, delay, loop }: IPattern, device: IBlyncDevice) { | ||
if (typeof colors === "function") | ||
throw new Error("`colors` must be an array of colors"); | ||
|
||
let index = 0; | ||
while (true) { | ||
if (index === colors.length) { | ||
if (loop) index = 0; | ||
else break; | ||
} | ||
await device.sendCommand(this._createCommand(colors[index])); | ||
await Bluebird.delay(delay); | ||
index++; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Color } from "../patterns/Color"; | ||
import { IPattern } from "../patterns/IPattern"; | ||
import { IBlyncDevice } from "../lib/IBlyncDevice"; | ||
import Bluebird from "bluebird"; | ||
import { CommandFactory } from "../util/commandFactory"; | ||
import { IPatternEngine } from "./IPatternEngine"; | ||
|
||
export class FunctionPatternProcessor implements IPatternEngine { | ||
private _current: Color = [0, 0, 0]; | ||
|
||
async process(pattern: IPattern, device: IBlyncDevice): Promise<number> { | ||
if (Array.isArray(pattern.colors)) | ||
throw new Error("`colors` must be a function!"); | ||
while (this._current !== null) { | ||
this._current = pattern.colors(this._current); | ||
const command = CommandFactory.fromColor(this._current); | ||
await Bluebird.delay(pattern.delay); | ||
await device.sendCommand(command); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IBlyncDevice } from "../lib/IBlyncDevice"; | ||
import { IPattern } from "../patterns/IPattern"; | ||
|
||
export interface IPatternEngine { | ||
process(pattern: IPattern, device: IBlyncDevice): Promise<number>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { HID, devices } from "node-hid"; | ||
import { BlyncWireless } from "./BlyncWireless"; | ||
|
||
class BlyncStatic { | ||
static getDevices() { | ||
const hidDevices = devices(); | ||
|
||
const blyncs = hidDevices | ||
.filter( | ||
({ vendorId, productId, path }) => | ||
vendorId === 11277 && productId === 11 && path | ||
) | ||
.map(x => ({ ...x, path: x.path ? x.path : "" })) | ||
.map(({ path }) => new BlyncWireless(new HID(path))); | ||
|
||
return blyncs; | ||
} | ||
static getDevice(index: number) { | ||
index = +index || 0; | ||
|
||
const devices = this.getDevices(); | ||
if (index < 0) { | ||
throw new Error("Invalid device index"); | ||
} | ||
if (index >= devices.length) { | ||
throw new Error("Device index #" + index + " not found"); | ||
} | ||
|
||
return devices[index]; | ||
} | ||
} | ||
|
||
export { BlyncStatic }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { HID } from "node-hid"; | ||
import { IBlyncCommand } from "./IBlyncCommand"; | ||
import { IBlyncDevice } from "./IBlyncDevice"; | ||
|
||
class BlyncWireless implements IBlyncDevice { | ||
constructor(private hidDevice: HID) {} | ||
|
||
private _createBuffer({ | ||
red, | ||
green, | ||
blue, | ||
dim, | ||
blink | ||
}: IBlyncCommand): Array<number> { | ||
let lightControl = 0b000000; | ||
// Bit0: 0 - Light On, 1 - Light Off | ||
// Bit1: 0 - No Dim (Full Brightness), 1 - Dim by 50% | ||
if (dim) { | ||
lightControl += 0b000010; | ||
} | ||
// Bit2: 0 - No Flash, 1- Start Flash (Blink) | ||
// Bit5-Bit3 - Flash speed - 001 - slow, 010 - medium, 100- fast | ||
switch (blink) { | ||
case 0: | ||
// no blink | ||
break; | ||
case 1: // slow | ||
lightControl += 0b001100; | ||
break; | ||
case 2: // medium | ||
lightControl += 0b010100; | ||
break; | ||
case 3: // slow | ||
lightControl += 0b100100; | ||
break; | ||
} | ||
|
||
const buffer = [ | ||
0x00, | ||
red, | ||
blue, | ||
green, | ||
lightControl, | ||
0x00, | ||
0x80, | ||
0xff, | ||
0x22 | ||
]; | ||
|
||
return buffer; | ||
} | ||
|
||
sendCommand = async (command: IBlyncCommand) => { | ||
const buffer = this._createBuffer(command); | ||
return this.hidDevice.write(buffer); | ||
} | ||
} | ||
|
||
export { BlyncWireless }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface IBlyncCommand { | ||
red: number; | ||
green: number; | ||
blue: number; | ||
dim: boolean; | ||
blink: 0 | 1 | 2 | 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IBlyncCommand } from "./IBlyncCommand"; | ||
|
||
export interface IBlyncDevice { | ||
sendCommand(command: IBlyncCommand): Promise<number>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.