Skip to content

Commit df9e6da

Browse files
authored
Merge pull request #59 from PropGit/Fix_CrOS_DL_Failures
Fix cr os dl failures
2 parents f9e4f8d + 98b8c19 commit df9e6da

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
<td>Verbose Logging:</td>
4747
<td colspan="2"><input type="checkbox" id="bpc-trace"/></td>
4848
</tr>
49+
<tr>
50+
<td>Experimental Timing:</td>
51+
<td colspan="2"><input type="checkbox" id="exp-timing"/></td>
52+
</tr>
4953
<tr>
5054
<td colspan="3"><div id="log" class="con"></div></td>
5155
</tr>

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ var portLister = [];
104104
// Is verbose loggin turned on?
105105
var verboseLogging = false;
106106

107+
// Is experimental timing turned on?
108+
var experimentalTiming = false;
107109

108110
document.addEventListener('DOMContentLoaded', function() {
109111

@@ -182,7 +184,11 @@ document.addEventListener('DOMContentLoaded', function() {
182184
$('bpc-trace').onclick = function() {
183185
verboseLogging = $('bpc-trace').checked;
184186
};
185-
187+
188+
$('exp-timing').onclick = function() {
189+
experimentalTiming = $('exp-timing').checked;
190+
};
191+
186192
$('wx-allow').onclick = function() {
187193
var wx_enabled = $('wx-allow').checked;
188194
if(wx_enabled) {

loader.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,12 @@ function loadPropeller(sock, portPath, action, payload, debug) {
138138

139139
if (port.isWired) {
140140
//Set postResetDelay based on platform; ideal Post-Reset Delay = 100 ms; adjust downward according to typically-busy operating systems
141-
postResetDelay = (platform === pfWin) ? 60 : 100;
141+
postResetDelay = ((platform === pfWin) && (!experimentalTiming)) ? 60 : 100;
142142
if (port.connId) {
143-
// Connection exists, prep to close it first (to reset it), then open it (fresh)
144-
originalBaudrate = initialBaudrate;
145-
connect = function() {return closePort(port).then(function() {return openPort(sock, portPath, initialBaudrate, "programming")}).catch(function(e) {return Promise.reject(e)})}
146-
// The following temporarily removed (and replaced above) to intentionally close and reopen port in hopes it eliminates the CrOS v67+ failed download problem
147-
// // Connection exists, prep to reuse it
148-
// originalBaudrate = port.baud;
149-
// updatePort(port, {mode: "programming", bSocket: sock});
150-
// connect = function() {return changeBaudrate(port, initialBaudrate)}
143+
// Connection exists, prep to reuse it
144+
originalBaudrate = port.baud;
145+
updatePort(port, {mode: "programming", bSocket: sock});
146+
connect = function() {return changeBaudrate(port, initialBaudrate)}
151147
} else {
152148
// No connection yet, prep to create one
153149
originalBaudrate = initialBaudrate;
@@ -261,6 +257,14 @@ function clearPropCommTimer() {
261257
}
262258
}
263259

260+
function wait(ms) {
261+
/* Actively delay for ms milliseconds.
262+
This should only be used for time-critical delays as it doesn't release to the task queue but instead consumes CPU time until finished.
263+
*/
264+
let Done = Date.now() + ms;
265+
while (Date.now() < Done){}
266+
}
267+
264268
function talkToProp(sock, port, binImage, toEEPROM) {
265269
/* Return promise to deliver Propeller Application (binImage) to Propeller
266270
sock is the websocket to direct mUser messages at
@@ -283,7 +287,8 @@ function talkToProp(sock, port, binImage, toEEPROM) {
283287

284288
function sendMBL() {
285289
return new Promise(function(resolve, reject) {
286-
setTimeout(function() {
290+
291+
function txmit() {
287292
//Prep for expected packetID:transmissionId response (Micro-Boot-Loader's "Ready" signal)
288293
propComm.mblEPacketId[0] = packetId;
289294
propComm.mblETransId[0] = 0; //MBL transmission's Id is always 0
@@ -295,9 +300,16 @@ function talkToProp(sock, port, binImage, toEEPROM) {
295300
.then(function() {log(notice(000, ["Found Propeller"]), mUser+mDbug, sock)}) //Succeeded!
296301
.then(function() {return resolve()})
297302
.catch(function(e) {return reject(e)}); //Failed!
298-
}, postResetDelay);
303+
}
304+
305+
if (!experimentalTiming) {
306+
setTimeout(txmit, postResetDelay);
307+
} else {
308+
wait(postResetDelay);
309+
txmit();
310+
}
299311
});
300-
};
312+
}
301313

302314
Promise.resolve()
303315
.then(function() { resetPropComm(port, mblDeliveryTime, null, null, true);}) //Reset propComm object

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "BlocklyProp Launcher",
33
"description": "A Chrome application that connects your Propeller-Powered Hardware to the BlocklyProp website.",
4-
"version": "0.9.4",
4+
"version": "0.9.5",
55
"manifest_version": 2,
66
"minimum_chrome_version": "45",
77

serial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function closePort(port, command) {
140140
log("Closed port " + port.path + " (id " + port.connId + ")", mDbug);
141141
// Clear connection id to indicate port is closed
142142
updatePort(port, {connId: null});
143-
setTimeout(resolve, 250); //Delay resolve() to prevent future openPort() calls from arriving too soon to accommodate
143+
resolve();
144144
} else {
145145
log("Could not close port " + port.path + " (id " + port.connId + ")", mDbug);
146146
reject(Error(notice(neCanNotClosePort, [port.path])));

0 commit comments

Comments
 (0)