aboutsummaryrefslogtreecommitdiff
path: root/lamp.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lamp.ts')
-rw-r--r--lamp.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/lamp.ts b/lamp.ts
new file mode 100644
index 0000000..dfe12da
--- /dev/null
+++ b/lamp.ts
@@ -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('');
+ }
+}