diff --git a/docs/tools/streaming.html b/docs/tools/streaming.html index 325a0c05a..59af66d77 100644 --- a/docs/tools/streaming.html +++ b/docs/tools/streaming.html @@ -39,11 +39,10 @@ console.log('starting') let bus = await jacdac.requestUSBBus(); bus.on('deviceannounce', d => { - // if the device is a sensor, start streaming - const sensors = jacdac.sensorsFromDevice(d, jacdac.SRV_SLIDER); - if (sensors.length) { - console.log(`start streaming ${d} (${sensors.length}): ${jacdac.printServices(d)}`) - sensors.forEach(sensor => sensor.setStreamingAsync(true)); + // tell all services to start streaming, ignored if not supported + for (let i = 1; i < d.serviceLength; ++i) { + const sensor = new jacdac.SensorClient(d, i) + sensor.setStreamingAsync(true); } }) bus.on('packetsend', pkt => { @@ -86,7 +85,8 @@ el.value = v; const lbl = document.getElementById(el.id + ":label"); - lbl.innerText = `${pkt.dev.shortId}: ${v}`; + const serviceClass = pkt.dev.serviceClassAt(pkt.service_number); + lbl.innerText = `${pkt.dev.shortId}/${jacdac.serviceName(serviceClass)}: ${v}`; } diff --git a/src/device.ts b/src/device.ts index c18777c59..20b55f39a 100644 --- a/src/device.ts +++ b/src/device.ts @@ -51,6 +51,14 @@ export class Device { return read32(this.services, idx) } + get serviceClasses(): number[] { + const r = []; + const n = this.serviceLength; + for (let i = 0; i < n; ++i) + r.push(this.serviceClassAt(i)) + return r; + } + sendCtrlCommand(cmd: number, payload: Buffer = null) { const pkt = !payload ? Packet.onlyHeader(cmd) : Packet.from(cmd, payload) pkt.service_number = JD_SERVICE_NUMBER_CTRL diff --git a/src/pretty.ts b/src/pretty.ts index 3526a5864..2de4bbfe3 100644 --- a/src/pretty.ts +++ b/src/pretty.ts @@ -89,6 +89,11 @@ const serv_decoders: U.SMap<(p: Packet) => string> = { } }, SLIDER: decodeIntSensorData, + THERMOMETER: decodeIntSensorData, + POWER: decodeIntSensorData, + BUTTON: decodeIntSensorData, + ROTARY_ENCODER: decodeIntSensorData, + BATTERY: decodeIntSensorData, } export function decodePacketData(pkt: Packet): string {