This commit is contained in:
peli 2020-06-24 23:15:45 -07:00
Родитель c57ad54b66
Коммит 75d825139e
3 изменённых файлов: 19 добавлений и 6 удалений

Просмотреть файл

@ -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}`;
}
</script>
</body>

Просмотреть файл

@ -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

Просмотреть файл

@ -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 {