From 92f9b40fc0f9d8ec37acba2e7fcdb8cf42b4c1d1 Mon Sep 17 00:00:00 2001 From: cTn Date: Sun, 8 Jun 2014 20:26:28 +0200 Subject: [PATCH] implementing openDevice and claimInterface --- js/stm32dfu.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/js/stm32dfu.js b/js/stm32dfu.js index ce2c7e89..ea4874c7 100644 --- a/js/stm32dfu.js +++ b/js/stm32dfu.js @@ -58,15 +58,36 @@ var STM32DFU_protocol = function() { STM32DFU_protocol.prototype.connect = function(hex) { var self = this; self.hex = hex; + + chrome.usb.getDevices(usbDevices.STM32DFU, function(result) { + if (result.length) { + console.log('USB DFU detected with ID: ' + result[0].device); + + self.openDevice(result[0]); + } else { + // TODO: throw some error + } + }); }; -STM32DFU_protocol.prototype.openDevice = function(callback) { +STM32DFU_protocol.prototype.openDevice = function(device) { + var self = this; + + chrome.usb.openDevice(device, function(handle) { + self.handle = handle; + + console.log('Handle ID: ' + handle.handle); + self.claimInterface(0); + }); }; STM32DFU_protocol.prototype.closeDevice = function(callback) { }; -STM32DFU_protocol.prototype.claimInterface = function(callback) { +STM32DFU_protocol.prototype.claimInterface = function(interfaceNumber) { + chrome.usb.claimInterface(this.handle, interfaceNumber, function claimed() { + console.log('Claimed interface: ' + interfaceNumber); + }); }; STM32DFU_protocol.prototype.releaseInterface = function(callback) {