diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-08-05 17:42:06 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-08-05 17:42:06 +0200 |
commit | c2920dbb3a80d7f46bc968864987cf12587d546b (patch) | |
tree | 41d43a45916302c1813b64788fc542d01799fcda /lamp.ts | |
parent | 34144332104dbbb2c1243ccfac79a8f81516e53d (diff) |
less jankyness
Diffstat (limited to 'lamp.ts')
-rw-r--r-- | lamp.ts | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -7,6 +7,7 @@ export type LampColor = [number, number, number, number]; export default class Lamp { #color: LampColor; private subpr: ChildProcess; + private last: string; constructor(public addr: string, public log: Logger) { this.subpr = spawn(join(__dirname, '/venv/bin/python3'), [join(__dirname, './main.py'), addr]); @@ -18,7 +19,11 @@ export default class Lamp { set color(newColor: LampColor) { this.#color = newColor.map(c => Math.floor(c)) as LampColor; - this.subpr.stdin.write(this.colorToString() + '\n'); + var message = this.colorToString(); + if (this.last == message) return; // prevent duplicate messages + this.log.info(message); + this.subpr.stdin.write(message + '\n'); + this.last = message; } get color() { |