From 6c8387da7292cb4117740f6a5c7cc5cce5b196ae Mon Sep 17 00:00:00 2001 From: Chris Willis-Ford Date: Fri, 24 Jul 2015 17:18:51 +0000 Subject: [PATCH] Update PicoBoard + WeDo extensions from main site This includes sync compatibility changes --- scratch_extensions/picoExtension.js | 17 +++++++++++++---- scratch_extensions/wedoExtension.js | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scratch_extensions/picoExtension.js b/scratch_extensions/picoExtension.js index face82d..5001f02 100644 --- a/scratch_extensions/picoExtension.js +++ b/scratch_extensions/picoExtension.js @@ -127,15 +127,24 @@ } } - var poller = null; - var watchdog = null; function tryNextDevice() { // If potentialDevices is empty, device will be undefined. // That will get us back here next time a device is connected. device = potentialDevices.shift(); - if (!device) return; - device.open({ stopBits: 0, bitRate: 38400, ctsFlowControl: 0 }); + if (device) { + device.open({ stopBits: 0, bitRate: 38400, ctsFlowControl: 0 }, deviceOpened); + } + } + + var poller = null; + var watchdog = null; + function deviceOpened(dev) { + if (!dev) { + // Opening the port failed. + tryNextDevice(); + return; + } device.set_receive_handler(function(data) { //console.log('Received: ' + data.byteLength); if(!rawData || rawData.byteLength == 18) rawData = new Uint8Array(data); diff --git a/scratch_extensions/wedoExtension.js b/scratch_extensions/wedoExtension.js index 4378bd2..fe9adfc 100644 --- a/scratch_extensions/wedoExtension.js +++ b/scratch_extensions/wedoExtension.js @@ -285,7 +285,9 @@ device = dev; device.open(); poller = setInterval(function() { - rawData = device.read(); + device.read(function(data) { + rawData = data; + }); }, 20); };