Skip to content

Commit

Permalink
move variables to fix load bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspesla committed Nov 12, 2015
1 parent e8f84e4 commit 2008ba2
Show file tree
Hide file tree
Showing 2 changed files with 1,065 additions and 27 deletions.
59 changes: 32 additions & 27 deletions ev3_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ var EV3ScratchAlreadyLoaded = EV3ScratchAlreadyLoaded || false;
var EV3Connected = EV3Connected || false;
var potentialEV3Devices = potentialEV3Devices || [];

var waitingCallbacks = waitingCallbacks || [[],[],[],[],[],[],[],[], []];
var waitingQueries = waitingQueries || [];
var global_sensor_result = global_sensor_result || [0, 0, 0, 0, 0, 0, 0, 0, 0];
var global_sensor_queried = global_sensor_queried || [0, 0, 0, 0, 0, 0, 0, 0, 0];

var connecting = connecting || false;
var notifyConnection = notifyConnection|| false;
var potentialDevices = potentialDevices || []; // copy of the list
var warnedAboutBattery = warnedAboutBattery || false;
var deviceTimeout = deviceTimeout || 0;
var counter = counter || 0;
var poller = poller || null;
var pingTimeout = pingTimeout || null;
var connectionTimeout = connectionTimeout || null;

var waitingForPing = waitingForPing || false;
var waitingForInitialConnection = waitingForInitialConnection || false;


(function(ext) {
// Cleanup function when the extension is unloaded

Expand All @@ -38,11 +57,6 @@ var potentialEV3Devices = potentialEV3Devices || [];
};


var connecting = false;
var notifyConnection = false;
var potentialDevices = []; // copy of the list
var warnedAboutBattery = false;
var deviceTimeout = 0;

ext._deviceConnected = function(dev)
{
Expand Down Expand Up @@ -73,13 +87,6 @@ var potentialEV3Devices = potentialEV3Devices || [];
// start recursive loop
tryNextDevice();
}

var poller = null;
var pingTimeout = null;
var connectionTimeout = null;

var waitingForPing = false;
var waitingForInitialConnection = false;

function clearSensorStatuses()
{
Expand All @@ -93,7 +100,6 @@ var potentialEV3Devices = potentialEV3Devices || [];
}
}

var counter = 0;

function tryToConnect()
{
Expand All @@ -107,7 +113,7 @@ function tryToConnect()
connecting = true;
testTheConnection(startupBatteryCheckCallback);
waitingForInitialConnection = true;
connectionTimeout = setTimeout(connectionTimeOutCallback, 3000);
connectionTimeout = setTimeout(connectionTimeOutCallback, 5000);
}

function startupBatteryCheckCallback(result)
Expand Down Expand Up @@ -259,7 +265,11 @@ function playStartUpTones()

ext._shutdown = function()
{
console.log(timeStamp() +' SHUTDOWN: ' + theEV3Device.id);
console.log(timeStamp() +' SHUTDOWN: ' + ((theEV3Device) ? theEV3Device.id : "null"));

// if (poller)
// clearInterval(poller);

/*
if (theEV3Device)
theEV3Device.close();
Expand Down Expand Up @@ -288,10 +298,7 @@ function playStartUpTones()
return result;
}

var waitingCallbacks = [[],[],[],[],[],[],[],[], []];
var waitingQueries = [];
var global_sensor_result = [0, 0, 0, 0, 0, 0, 0, 0, 0];
var global_sensor_queried = [0, 0, 0, 0, 0, 0, 0, 0, 0];


function receive_handler(data)
{
Expand Down Expand Up @@ -359,7 +366,7 @@ function playStartUpTones()
global_sensor_queried[this_is_from_port]--;
while(callback = waitingCallbacks[this_is_from_port].shift())
{
console.log("result: " + theResult);
console.log(timeStamp() + " result: " + theResult);
callback(theResult);
}
}
Expand Down Expand Up @@ -413,7 +420,7 @@ function playStartUpTones()
mess[(i / 2) + 4] = window.parseInt(str.substr(i, 2), 16);
}

console.log("sending: " + createHexString(mess));
console.log(timeStamp() + " sending: " + createHexString(mess));

return mess;
}
Expand Down Expand Up @@ -1021,13 +1028,11 @@ function howStopHex(how)
},
};

var serial_info = {type: 'serial'};

// should we even call register again if already loaded? seems to work.

ScratchExtensions.register('EV3 Control', descriptor, ext, serial_info);
var serial_info = {type: 'serial'};
ScratchExtensions.register('EV3 Control', descriptor, ext, serial_info);
console.log(timeStamp() + ' registered extension. theEV3Device:' + theEV3Device);

console.log("EV3ScratchAlreadyLoaded: " + EV3ScratchAlreadyLoaded);
EV3ScratchAlreadyLoaded = true;
console.log(timeStamp() + ' registered extension. theEV3Device:' + theEV3Device);
})({});

Loading

0 comments on commit 2008ba2

Please sign in to comment.