Loading files
import type { RobotLed } from 'capabilities'
export type RuntimeLightingConstructorParam = {
led?: Record<string, RobotLed>
}
export class StackchanRuntimeLighting {
#led: Record<string, RobotLed>
constructor(params: RuntimeLightingConstructorParam) {
this.#led = params.led ?? {}
}
get led() {
return this.#led
}
lightOn(ledName: string, r: number, g: number, b: number, duration?: number, index?: number, count?: number) {
const led = this.#led[ledName]
if (led) {
led.on(r, g, b, duration, index, count)
}
}
lightOff(ledName: string, index?: number, count?: number) {
const led = this.#led[ledName]
if (led) {
led.off(index, count)
}
}
lightBlink(ledName: string, r: number, g: number, b: number, duration: number, index?: number, count?: number) {
const led = this.#led[ledName]
if (led) {
led.blink(r, g, b, duration, index, count)
}
}
lightRainbow(ledName: string, index?: number, count?: number) {
const led = this.#led[ledName]
if (led) {
led.rainbow(index, count)
}
}
close(): void {
for (const led of Object.values(this.#led)) {
try {
led.off()
} catch {
// best-effort shutdown: keep turning off the remaining LEDs
}
}
}
}
5e4094a64This file is pinned to the selected release. Download the original to open it in your design tool.