This repository was archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextToVideoStripController.ts
74 lines (64 loc) · 1.89 KB
/
TextToVideoStripController.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { IStripController } from "./IStripController";
import {createWriteStream, existsSync, statSync, Stats } from "fs";
interface IColor {
r: number;
g: number;
b: number;
a: number;
}
class Led {
color: IColor;
constructor(color: IColor) {
this.color = color;
}
}
export default class TextToVideoStripController implements IStripController {
leds: Array<Led> = [];
stripSize: number;
fileStream: NodeJS.WritableStream;
/**
* Controller that outputs into a textfile. This file can later be interpretet with a python script.
* This Controller is just used for local developement
* @param params Params Array from main Application
*/
constructor(params: Array<string>) {
this.stripSize = params["ledcount"];
for(let i: number = 0; i < this.stripSize; i++) {
this.leds.push(new Led({r: 0, g: 0, b: 0, a: 0}));
}
let animationFilePath = params["animout"] || "./animation.txt";
this.fileStream = createWriteStream(animationFilePath, {encoding: "UTF8"});
console.log('TextToVideoStripcontroller initialized');
}
all(r: number, g: number, b: number, a: number): void {
for(let i: number = 0; i < this.stripSize; i++) {
this.leds[i] = new Led({r: r, g: g, b: b, a: a});
}
}
set(led: number, r: number, g: number, b: number, a: number): void {
if (led >= 0 && led < this.stripSize) {
this.leds[led] = new Led({r: r, g: g, b: b, a: a});
}
}
sync(): void {
for (const led of this.leds) {
this.fileStream.write(`${led.color.r},${led.color.g},${led.color.b},${led.color.a};`);
/*
{r,g,b,a}{r,g,b,a}
*/
}
this.fileStream.write("\n");
}
clear(): void {
this.all(0, 0, 0, 0);
}
off(): void {
// just dont do anythingF
}
shutdown(callback : () => void): void {
this.fileStream.end(callback);
}
getLength(): number {
return this.stripSize;
}
}