blob: 83e6d8c977d53a01819293f72b41f89d5c2827c4 (
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
26
|
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('./venv/bin/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('');
}
}
|