我正在使用Blink(1)mk2设备通过浏览器浏览需要通知提醒的项目。 我已经尝试使用WEBUSB API连接到USB的以下代码。Blink1 mk2通过WEBUSB API进行Chrome浏览器连接Light Blink问题
const VENDOR_ID = 0x27b8;
navigator.usb.requestDevice({
filters: [{
vendorId: VENDOR_ID
}]
}).then(selectedDevice => {
device = selectedDevice;
console.log("open")
var tOpen = device.open();
console.log("opened")
return tOpen;
}).then(() => {
console.log("selectConfiguration")
return device.selectConfiguration(1);
}).then(() => {
console.log("claimInterface")
return device.claimInterface(0);
}).then(() => {
console.log("controlTransferOut")
const r = Math.floor((Math.random() * 255) + 0);
const g = Math.floor((Math.random() * 255) + 0);
const b = Math.floor((Math.random() * 255) + 0);
// not entirely sure what is going on below...
const fadeMillis = 500;
const th = (fadeMillis/10) >> 8;
const tl = (fadeMillis/10) & 0xff;
const data = new Uint8Array([0x01, 0x63, r, g, b, th, tl, 0x00, 0x00]).buffer;
var rgb = new Uint8Array(3);
rgb[0] = r;
rgb[1] = g;
rgb[2] = b;
return device.controlTransferOut({
requestType: 'standard',
recipient: 'interface',
request: 0x09,
value: 1,
index: 0
},data);
}).then(result => {
console.log(result);
}).catch(error => {
console.log(error);
});
我可以在设置权限弹出后连接到USB。之后,上面的代码打开它,selectConfiguration,claimInterface也工作得很好,当我打电话controlTransferOut也发出命令并返回结果为:
USBOutTransferResult {bytesWritten: 8, status: "ok"}
但闪烁或USB上的颜色变化也没有体现出来。
我是否错过了一些东西,或者是否有任何其他配置需要使用才能使USB亮起来?
请注意,标签“眨眼睛”与您想要的无关。从技术上讲,WebUSB,因为它是一个不同的API .. – Xan