blob: dfe12da80109db16919b5fec8c2206e5da7c99ee (
plain)
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
|
import { ChildProcess, spawn } from 'child_process';
export type LampColor = [number, number, number, number];
export default class Lamp {
#color: LampColor;
private subpr: ChildProcess;
constructor(public addr: string) {
this.subpr = spawn('python3', ['./main.py', addr]);
}
set color(newColor: LampColor) {
this.#color = newColor.map(c => Math.floor(c)) as LampColor;
this.subpr.stdin.write(this.colorToString() + '\n');
}
get color() {
return this.#color;
}
private colorToString() {
return this.color.map(i => i.toString(16).padStart(2, '0')).join('');
}
}
|