From 6bdadd8534e6c9da141d7f25010da09a3a328384 Mon Sep 17 00:00:00 2001 From: RogerHardiman Date: Wed, 27 Jul 2016 17:49:10 +0000 Subject: [PATCH] Check if USB device found and ignore commands if no device is found --- tenx_driver.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tenx_driver.js b/tenx_driver.js index 3cf136a..3760bff 100644 --- a/tenx_driver.js +++ b/tenx_driver.js @@ -50,6 +50,8 @@ function TenxDriver() { TenxDriver.prototype.open = function() { // Find and Open this.launcher = usb.findByIds(0x1130,0x202); + if (!this.launcher) return; + this.launcher.open(); // Detach Kernel Driver @@ -63,6 +65,8 @@ TenxDriver.prototype.open = function() { } TenxDriver.prototype.close = function() { + if (!this.launcher) return; + if (!this.launcher.interfaces[0].isKernelDriverActive()) { this.launcher.interfaces[0].attachKernelDriver(); } @@ -157,6 +161,8 @@ TenxDriver.prototype.send_command = function(command) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + if (!this.launcher) return; + this.launcher.controlTransfer(0x21,0x09,0x02,0x01,header_1); this.launcher.controlTransfer(0x21,0x09,0x02,0x01,header_2); if (command == CMD.LEFT) this.launcher.controlTransfer(0x21,0x09,0x02,0x00, left_msg);