Skip to content

Commit e892f68

Browse files
authored
Merge pull request #63 from halemmerich/emulator
Allow more callbacks for incoming data from the emulator
2 parents 7e90950 + be09dc4 commit e892f68

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/emulator.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ var factoryFlashMemory;
1313
// Log of messages from app
1414
var appLog = "";
1515
var lastOutputLine = "";
16+
var consoleOutputCallback;
1617

1718
function onConsoleOutput(txt) {
1819
appLog += txt + "\n";
1920
lastOutputLine = txt;
21+
if (consoleOutputCallback)
22+
consoleOutputCallback(txt);
23+
else
24+
console.log("EMSCRIPTEN:", txt);
2025
}
2126

27+
/* Initialise the emulator,
28+
29+
options = {
30+
EMULATOR : "banglejs"/"banglejs2"
31+
DEVICEID : "BANGLEJS"/"BANGLEJS2"
32+
rxCallback : function(int) - called every time a character received
33+
consoleOutputCallback : function(str) - called when a while line is received
34+
}
35+
*/
2236
exports.init = function(options) {
2337
if (options.EMULATOR)
2438
EMULATOR = options.EMULATOR;
@@ -29,8 +43,10 @@ exports.init = function(options) {
2943
eval(require("fs").readFileSync(DIR_IDE + "/emu/emu_"+EMULATOR+".js").toString());
3044
eval(require("fs").readFileSync(DIR_IDE + "/emu/common.js").toString()/*.replace('console.log("EMSCRIPTEN:"', '//console.log("EMSCRIPTEN:"')*/);
3145

32-
jsRXCallback = function() {};
46+
jsRXCallback = options.rxCallback ? options.rxCallback : function() {};
3347
jsUpdateGfx = function() {};
48+
if (options.consoleOutputCallback)
49+
consoleOutputCallback = options.consoleOutputCallback;
3450

3551
factoryFlashMemory = new Uint8Array(FLASH_SIZE);
3652
factoryFlashMemory.fill(255);

0 commit comments

Comments
 (0)