Skip to content

Commit c6249db

Browse files
committed
Merge branch 'master' of https://github.com/rikkuness/EspruinoTools into typescript
2 parents 0df46eb + faf5fc9 commit c6249db

File tree

12 files changed

+69
-74
lines changed

12 files changed

+69
-74
lines changed

core/flasher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
console.log("Downloaded "+binary.byteLength+" bytes");
363363
flashBinaryToDevice(binary, flashOffset, callback, statusCallback);
364364
});
365-
};
365+
}
366366

367367

368368
function resetDevice(callback) {

core/flasherESP8266.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(function(){
1414

1515
const BLOCK_SIZE = 0x400;
16-
var uart;
16+
// var uart;
1717
var uartLine = "";
1818
var packetHandler;
1919

@@ -180,7 +180,7 @@ function unsetupEspruino(options) {
180180
function cmdSync(options) {
181181
console.log("Syncing...");
182182
return new Promise((resolve,reject)=>{
183-
var success = false;
183+
// var success = false;
184184
var interval;
185185
packetHandler = function(d) {
186186
if (d.cmd==8) {

core/modules.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@
126126
console.log("loadModule("+fullModuleName+")");
127127

128128
var urls = []; // Array of where to look for this module
129-
var modName; // Simple name of the module
129+
// var modName; // Simple name of the module
130130
if(Espruino.Core.Utils.isURL(fullModuleName)) {
131-
modName = fullModuleName.substr(fullModuleName.lastIndexOf("/") + 1).split(".")[0];
131+
// modName = fullModuleName.substr(fullModuleName.lastIndexOf("/") + 1).split(".")[0];
132132
urls = [ fullModuleName ];
133133
} else {
134-
modName = fullModuleName;
134+
// modName = fullModuleName;
135135
Espruino.Config.MODULE_URL.split("|").forEach(function (url) {
136136
url = url.trim();
137137
if (url.length!=0)
138138
Espruino.Config.MODULE_EXTENSIONS.split("|").forEach(function (extension) {
139139
urls.push(url + "/" + fullModuleName + extension);
140140
})
141141
});
142-
};
142+
}
143143

144144
// Recursively go through all the urls
145145
(function download(urls) {
@@ -234,7 +234,7 @@
234234
callback(loadedModuleData.join("\n") + "\n" + code);
235235
});
236236
}
237-
};
237+
}
238238

239239

240240
Espruino.Core.Modules = {

core/serial.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,6 @@ To add a new serial device, you must add an object to
268268
});
269269
};
270270

271-
var str2ab=function(str) {
272-
var buf=new ArrayBuffer(str.length);
273-
var bufView=new Uint8Array(buf);
274-
for (var i=0; i<str.length; i++) {
275-
var ch = str.charCodeAt(i);
276-
if (ch>=256) {
277-
console.warn("serial> Attempted to send non-8 bit character - code "+ch);
278-
ch = "?".charCodeAt(0);
279-
}
280-
bufView[i] = ch;
281-
}
282-
return buf;
283-
};
284-
285271
var closeSerial=function() {
286272
if (currentDevice) {
287273
currentDevice.close();

core/serial_chrome_serial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Author: Gordon Williams ([email protected])
3030
}
3131

3232
var connectionInfo;
33-
var connectedPort; // unused?
33+
// var connectedPort; // unused?
3434
var connectionDisconnectCallback;
3535
var connectionReadCallback;
3636

@@ -65,7 +65,7 @@ Author: Gordon Williams ([email protected])
6565
openCallback(undefined);
6666
} else {
6767
connectionInfo = cInfo;
68-
connectedPort = serialPort;
68+
// connectedPort = serialPort;
6969
console.log(cInfo);
7070
openCallback(cInfo);
7171
}

core/serial_web_serial.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@
109109
flowControl: "none",
110110
rtscts: false });
111111
}).then(function () {
112+
var getReaderSuccess = false;
112113
function readLoop() {
113114
serialPortReader = serialPort.readable.getReader();
114115
serialPortReader.read().then(function ({ value, done }) {
116+
getReaderSuccess = true;
115117
serialPortReader.releaseLock();
116118
serialPortReader = undefined;
117119
if (value) {
@@ -130,8 +132,19 @@
130132
readLoop();
131133
}
132134
}).catch(function(e) {
133-
serialPortReader.releaseLock();
134-
console.log("Serial> serialPortReader rejected", e);
135+
if (getReaderSuccess == false && e == "BreakError: Break received") {
136+
// This fixes a longstanding issue (since 2017) that affected ESP32 devices.
137+
// Espruino Web IDE, sometimes did not connect to an ESP32 device, especially the first time you tried.
138+
// The workaround was to use another tool to connect to the ESP32, like minicom or cutecom
139+
// and once connected using one of these tools, you tried again using Espruino Web IDE.
140+
console.log("Condition break received and ignored");
141+
console.log("Retrying the read loop...");
142+
getReaderSuccess = true;
143+
readLoop();
144+
} else {
145+
serialPortReader.releaseLock();
146+
console.log("Serial> serialPortReader rejected", e);
147+
}
135148
});
136149
}
137150
serialPort.addEventListener("disconnect", (event) => {

core/terminal.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
callback(data);
335335
});
336336

337-
};
337+
}
338338

339339
/* check for any terminal-inline-image and if they are still BMP
340340
then convert them to PNG using canvas */
@@ -429,7 +429,7 @@
429429
if (i in elements)
430430
elements[i].remove();
431431
// now write this to the screen
432-
var t = [];
432+
// var t = [];
433433
for (var y in termText) {
434434
var line = termText[y];
435435
if (y == termCursorY) {
@@ -484,7 +484,7 @@
484484
var x = Math.min(pos.left, terminal.offsetWidth);
485485
var y = Math.min(pos.top-tPos.top, terminal.height-terminalfocus.offsetHeight);
486486
terminalfocus.style.left=x+"px";
487-
terminalfocus.style.top=(pos.top-tPos.top)+"px";
487+
terminalfocus.style.top=y+"px";
488488
}
489489
};
490490

@@ -494,8 +494,6 @@
494494
return str.substr(0,s+1);
495495
}
496496

497-
498-
499497
var handleReceivedCharacter = function (/*char*/ch) {
500498
function isUTF8StartChar(ch) {
501499
return (ch>=0xC2) && (ch<=0xF4);
@@ -611,7 +609,7 @@
611609
var old = onInputData;
612610
onInputData = callback;
613611
return old;
614-
};
612+
}
615613

616614
/// Called when data comes OUT of Espruino INTO the terminal
617615
function outputDataHandler(readData) {
@@ -631,7 +629,7 @@
631629
displayData = [];
632630
displayTimeout = null;
633631
}, 50);
634-
};
632+
}
635633

636634
var receivedData = "";
637635
function searchData(bytes){
@@ -659,36 +657,36 @@
659657
});
660658
// Ensure that data from Espruino goes to this terminal
661659
Espruino.Core.Serial.startListening(Espruino.Core.Terminal.outputDataHandler);
662-
};
660+
}
663661

664662
/// Get the current terminal line that we're on
665663
function getCurrentLine() {
666664
return termText.length-1;
667-
};
665+
}
668666

669667
/// Set extra text to display before a certain terminal line
670668
function setExtraText(line, text) {
671669
if (termExtraText[line] != text) {
672670
termExtraText[line] = text;
673671
updateTerminal();
674672
}
675-
};
673+
}
676674

677675
/// Clear all extra text that is to be displayed
678676
function clearExtraText() {
679677
termExtraText = {};
680678
updateTerminal();
681-
};
679+
}
682680

683681
/// Does the terminal have focus?
684682
function hasFocus() {
685683
return document.querySelector("#terminal").classList.contains("focus");
686-
};
684+
}
687685

688686
/// Give the terminal focus
689687
function focus() {
690688
document.getElementById("terminalfocus").focus();
691-
};
689+
}
692690

693691
// Is the terminal actually visible, or is it so small it can't be seen?
694692
function isVisible() {
@@ -711,15 +709,15 @@
711709
while (line < termText.length && termText[line].substr(0,1)==":")
712710
text += "\n"+termText[line++].substr(1);
713711
return { line : startLine, text : text };
714-
};
712+
}
715713

716714
/** Get the Nth from latest line of text in the terminal (unlike getInputLine) */
717715
function getTerminalLine(n) {
718716
if (n===undefined) n=0;
719717
var line = termText.length-(1+n);
720718
if (line<0) return undefined;
721719
return termText[line];
722-
};
720+
}
723721

724722
/** Add a notification to the terminal (as HTML). If options.buttonclick is set
725723
then the first <button> inside the notification text

core/utils.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919

2020
}
2121

22-
function decodeBase64(d) {
23-
return Buffer.from(d,'base64').toString('binary');
24-
}
25-
26-
function encodeBase64(d) {
27-
return Buffer.from(d,'binary').toString('base64');
28-
}
29-
3022
function isWindows() {
3123
return (typeof navigator!="undefined") && navigator.userAgent.indexOf("Windows")>=0;
3224
}
@@ -244,7 +236,7 @@
244236
if (ch=="\\") { // handle escape characters
245237
nextCh();
246238
var escape = '\\'+ch;
247-
var escapeExtra = 0;
239+
// var escapeExtra = 0;
248240
if (ch=="x") {
249241
nextCh();escape += ch;
250242
nextCh();escape += ch;
@@ -268,7 +260,7 @@
268260
value += ch;
269261
}
270262
nextCh();
271-
};
263+
}
272264
if (ch!==undefined) s+=ch;
273265
nextCh();
274266
}
@@ -907,10 +899,10 @@ while (d!==undefined) {console.log(btoa(d));d=f.read(${CHUNKSIZE});}
907899
}
908900

909901
/**
910-
* @param {string} str
902+
* @param {string} dv
911903
* @returns {ArrayBuffer}
912904
*/
913-
function dataViewToArrayBuffer(str) {
905+
function dataViewToArrayBuffer(dv) {
914906
var bufView = new Uint8Array(dv.byteLength);
915907
for (var i = 0; i < bufView.length; i++) {
916908
bufView[i] = dv.getUint8(i);

plugins/assembler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@
480480
code;
481481
}
482482
callback(code);
483-
};
483+
}
484484

485485

486486
Espruino.Plugins.Assembler = {

plugins/compiler.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,33 @@
4949
});
5050
}
5151

52-
/* Replace this node with the given text, and
53-
update node start/end positions of other nodes
54-
we're interested in */
55-
function replaceNode(node, newCode) {
56-
code = code.substr(0,node.start) + newCode + code.substr(node.end);
57-
var offs = newCode.length - (node.end-node.start); // offset for future code snippets
58-
for (var i in tasks)
59-
if (tasks[i].node.start > node.start) {
60-
tasks[i].node.start += offs;
61-
tasks[i].node.end += offs;
62-
}
63-
}
64-
52+
/** Given a string containing code, this parses it using acorn
53+
* then attempts to find functions with the string "compiled"
54+
* in them and sends them off to the compiler.
55+
*/
6556
function compileCode(code, description, callback) {
57+
var tasks = [];
58+
59+
/* Replace this node with the given text, and
60+
update node start/end positions of other nodes
61+
we're interested in */
62+
function replaceNode(node, newCode) {
63+
code = code.substr(0,node.start) + newCode + code.substr(node.end);
64+
var offs = newCode.length - (node.end-node.start); // offset for future code snippets
65+
for (var i in tasks)
66+
if (tasks[i].node.start > node.start) {
67+
tasks[i].node.start += offs;
68+
tasks[i].node.end += offs;
69+
}
70+
}
71+
6672
if (!Espruino.Config.COMPILATION)
6773
return callback(code);
6874

6975
var board = Espruino.Core.Env.getBoardData();
70-
var tasks = 0;
7176
try {
72-
var ast = acorn.parse(code);
73-
var tasks = [];
77+
var ast = acorn.parse(code, {ecmaVersion: 2020});
78+
tasks = [];
7479
// function xyz() { "compiled" ... }
7580
ast.body.forEach(function(node) {
7681
if (node.type=="FunctionDeclaration") {

0 commit comments

Comments
 (0)