Skip to content
This repository was archived by the owner on Sep 18, 2021. It is now read-only.

Commit b8ca45c

Browse files
committed
Initial commit
1 parent 622d974 commit b8ca45c

12 files changed

+280
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
3+
\.vs/
4+
5+
animation.txt

IStripController.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface IStripController {
2+
all(r: number, g: number, b: number, a: number): void
3+
set(led: number, r: number, g: number, b: number, a: number): void
4+
sync(): void
5+
clear(): void
6+
off(): void
7+
8+
shutdown(callback: Function): void
9+
getLength(): number
10+
}

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TextToVideoStripController,
2+
3+
is a StripController that is mainly used for developement of [LED-Controller](https://github.com/led-controller/LEDController). It generates a textfile that contains the animation.
4+
5+
That file can be interpreted using the python-script. It is used for testing and the default Controller.

TextToVideoStripController.ts

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

dist/IStripController.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface IStripController {
2+
all(r: number, g: number, b: number, a: number): void;
3+
set(led: number, r: number, g: number, b: number, a: number): void;
4+
sync(): void;
5+
clear(): void;
6+
off(): void;
7+
shutdown(callback: Function): void;
8+
getLength(): number;
9+
}

dist/IStripController.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

dist/TextToVideoStripController.d.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference types="node" />
2+
import { IStripController } from "./IStripController";
3+
interface IColor {
4+
r: number;
5+
g: number;
6+
b: number;
7+
a: number;
8+
}
9+
declare class Led {
10+
color: IColor;
11+
constructor(color: IColor);
12+
}
13+
export default class TextToVideoStripController implements IStripController {
14+
leds: Array<Led>;
15+
stripSize: number;
16+
fileStream: NodeJS.WritableStream;
17+
/**
18+
* Controller that outputs into a textfile. This file can later be interpretet with a python script.
19+
* This Controller is just used for local developement
20+
* @param params Params Array from main Application
21+
*/
22+
constructor(params: Array<string>);
23+
all(r: number, g: number, b: number, a: number): void;
24+
set(led: number, r: number, g: number, b: number, a: number): void;
25+
sync(): void;
26+
clear(): void;
27+
off(): void;
28+
shutdown(callback: () => void): void;
29+
getLength(): number;
30+
}
31+
export {};

dist/TextToVideoStripController.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const fs_1 = require("fs");
4+
class Led {
5+
constructor(color) {
6+
this.color = color;
7+
}
8+
}
9+
class TextToVideoStripController {
10+
/**
11+
* Controller that outputs into a textfile. This file can later be interpretet with a python script.
12+
* This Controller is just used for local developement
13+
* @param params Params Array from main Application
14+
*/
15+
constructor(params) {
16+
this.leds = [];
17+
this.stripSize = params["ledcount"];
18+
for (let i = 0; i < this.stripSize; i++) {
19+
this.leds.push(new Led({ r: 0, g: 0, b: 0, a: 0 }));
20+
}
21+
let animationFilePath = params["animationPath"] || "./animation.txt";
22+
this.fileStream = fs_1.createWriteStream(animationFilePath, { encoding: "UTF8" });
23+
console.log('TextToVideoStripcontroller initialized');
24+
}
25+
all(r, g, b, a) {
26+
for (let i = 0; i < this.stripSize; i++) {
27+
this.leds[i] = new Led({ r: r, g: g, b: b, a: a });
28+
}
29+
}
30+
set(led, r, g, b, a) {
31+
if (led >= 0 && led < this.stripSize) {
32+
this.leds[led] = new Led({ r: r, g: g, b: b, a: a });
33+
}
34+
}
35+
sync() {
36+
for (const led of this.leds) {
37+
this.fileStream.write(`${led.color.r},${led.color.g},${led.color.b},${led.color.a};`);
38+
/*
39+
{r,g,b,a}{r,g,b,a}
40+
*/
41+
}
42+
this.fileStream.write("\n");
43+
}
44+
clear() {
45+
this.all(0, 0, 0, 0);
46+
}
47+
off() {
48+
// just dont do anythingF
49+
}
50+
shutdown(callback) {
51+
this.fileStream.end(callback);
52+
}
53+
getLength() {
54+
return this.stripSize;
55+
}
56+
}
57+
exports.default = TextToVideoStripController;

package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "texttovideostripcontroller",
3+
"version": "0.3.0",
4+
"description": "Controller for LED-Controller, that creates a text file based on the current Animation. After that it can be interpreted using a python script, showing the Animation.",
5+
"main": "dist/TextToVideoStripController.js",
6+
"types": "dist/TextToVideoStripController.d.ts",
7+
"scripts": {
8+
"build": "tsc"
9+
},
10+
"author": "Lukas St",
11+
"license": "ISC",
12+
"dependencies": {
13+
"typescript": "^3.7.5"
14+
},
15+
"devDependencies": {
16+
"@types/node": "^11.15.7"
17+
}
18+
}

parseAnimation.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import time
2+
from tkinter import Canvas, Tk
3+
4+
print("Hello");
5+
6+
rawAnimation = open("./animation.txt", mode="r", encoding="UTF8");
7+
line = rawAnimation.readline()
8+
9+
cellW = 10
10+
cellH = 10
11+
12+
if line:
13+
gui = Tk()
14+
canvas = Canvas(gui, bg="white", height=100, width=1800)
15+
canvas.pack()
16+
17+
while line:
18+
curLed = 0
19+
leds = line.split(";")
20+
21+
canvas.delete("all")
22+
for led in leds:
23+
if led and not led == "\n":
24+
led = led.split(",")
25+
26+
#print(led)
27+
color = "#" + "{:02x}".format(round(float(led[0]))) + "{:02x}".format(round(float(led[1]))) + "{:02x}".format(round(float(led[2])))
28+
#print(color)
29+
30+
canvas.create_rectangle(curLed * cellW * 2, 60, curLed * cellW * 2 + cellW, 60 + cellH, fill=color)
31+
curLed += 1
32+
33+
gui.update()
34+
line = rawAnimation.readline()
35+
time.sleep(.05)
36+
gui.mainloop()
37+
38+
print("Done")

tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"declaration": true,
6+
"outDir": "./dist"
7+
},
8+
"exclude": [
9+
"node_modules",
10+
"dist"
11+
]
12+
}

0 commit comments

Comments
 (0)