diff options
Diffstat (limited to 'lamp.ts')
-rw-r--r-- | lamp.ts | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,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(''); + } +} |