1

I am working on a project that need notification alert via browser using Blink(1) mk2 device. I have tried the following code for connection to the usb using WEBUSB API.

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);
});

I am able to connect to usb after setting the permissions popup. After that above code opens it, selectConfiguration, claimInterface also worked fine and when I call controlTransferOut it also sends out the command and return the result as:

USBOutTransferResult {bytesWritten: 8, status: "ok"}

But blinking or color change on the USB does not reflected.

Am I missing something or is there any other configuration I need to use in order to get the light up on USB?

Yasir Ali
  • 21
  • 2
  • Note, the tag "blink" has nothing to do with what you want. Nor, technically, WebUSB as it's a different API.. – Xan Sep 07 '17 at 13:49

1 Answers1

0

I ran this code myself and found that when I set requestType to "standard" I got a "stall" but if I set it to "class" (which is correct since this is the HID class control transfer SET_REPORT) then I get "ok" and the color of the LED on my blink(1) mk2 changes.

Note, the RGB values in your snippet above are set randomly so you may be getting a very dim color.

Reilly Grant
  • 5,590
  • 1
  • 13
  • 23
  • I have tried the changes you suggested but it did not work for me...I have a chrome version 62.0.3202.89 (Official Build) (64-bit)...here is the video of what I am experiencing: https://www.screencast.com/t/1reAHN86nzlm ... Changed the color to show red only so that random pick color should not take effect, changed request type to "class" but the request is sending in to blink USB... I also do have blink(1) mk2 as you can see in video. – Yasir Ali Nov 14 '17 at 15:36