Comparing version 0.0.22 to 0.0.23
@@ -22,4 +22,6 @@ (function () { | ||
} catch (e) { | ||
console.error(e); | ||
console.log(e); | ||
console.log("`bleat` module not loaded - no node.js Bluetooth Low Energy"); | ||
Espruino.Config.BLUETOOTH_LOW_ENERGY = false; | ||
callback("No 'bleat' module"); | ||
return; | ||
@@ -26,0 +28,0 @@ } |
@@ -5,2 +5,7 @@ /* | ||
(function() { | ||
// Are we on nw.js with chrome.serial? No need for serialport then! | ||
if (typeof chrome !== 'undefined' && chrome.serial) { | ||
console.log("We have chrome.serial - not using 'serialport' module"); | ||
return; | ||
} | ||
if (typeof require === 'undefined') return; | ||
@@ -34,3 +39,3 @@ var serialport = require('serialport'); | ||
// return (e.vendorId === '0x0483' && e.productId === '0x5740'); | ||
// }) | ||
// }) | ||
.map(function(port) { | ||
@@ -49,3 +54,3 @@ // port.pnpId could be handy | ||
}; | ||
var openSerial=function(serialPort, openCallback, receiveCallback, disconnectCallback) { | ||
@@ -62,3 +67,3 @@ // https://github.com/voodootikigod/node-serialport#reference-guide | ||
var a = new Uint8Array(data.length); | ||
for (var i=0;i<data.length;i++) | ||
for (var i=0;i<data.length;i++) | ||
a[i] = data[i]; | ||
@@ -77,3 +82,3 @@ receiveCallback(a.buffer); | ||
}; | ||
var writeSerial = function(data, callback) { | ||
@@ -88,3 +93,3 @@ // convert to an array - if we put a string into | ||
}; | ||
// ---------------------------------------------------------- | ||
@@ -91,0 +96,0 @@ Espruino.Core.Serial.devices.push({ |
@@ -9,2 +9,3 @@ /* | ||
var ws; | ||
var dataWrittenCallbacks = []; | ||
@@ -31,5 +32,6 @@ var str2ab=function(str) { | ||
}; | ||
var openSerial=function(serialPort, openCallback, receiveCallback, disconnectCallback) { | ||
ws = new WebSocket("ws://" + location.host + "/" + serialPort, "serial"); | ||
dataWrittenCallbacks = []; | ||
ws.onerror = function(event) { | ||
@@ -44,5 +46,11 @@ connectCallback(undefined); | ||
ws.onerror = undefined; | ||
ws.onmessage = function (event) { | ||
console.log("MSG:"+event.data); | ||
receiveCallback(str2ab(event.data)); | ||
ws.onmessage = function (event) { | ||
//console.log("MSG:"+event.data); | ||
if (event.data[0]=="R") { | ||
receiveCallback(str2ab(event.data.substr(1))); | ||
} else { | ||
// if it's a data written callback, execute it | ||
var c = dataWrittenCallbacks.shift(); | ||
if (c) c(); | ||
} | ||
}; | ||
@@ -65,8 +73,8 @@ ws.onclose = function(event) { | ||
}; | ||
var writeSerial = function(data, callback) { | ||
dataWrittenCallbacks.push(callback); | ||
if (ws) ws.send(data); | ||
callback(); | ||
}; | ||
// ---------------------------------------------------------- | ||
@@ -73,0 +81,0 @@ Espruino.Core.Serial.devices.push({ |
@@ -13,5 +13,6 @@ /** | ||
"use strict"; | ||
(function(){ | ||
if(typeof process !== "undefined" && | ||
!process.__node_webkit && | ||
!process.versions.nw && | ||
!process.versions.electron) | ||
@@ -18,0 +19,0 @@ return; // don't load this in std NodeJS |
{ | ||
"name": "espruino", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "Command Line Interface and library for Communications with Espruino JavaScript Microcontrollers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,3 +8,3 @@ /** | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
------------------------------------------------------------------ | ||
@@ -18,3 +18,3 @@ Wrap whole code in `onInit` function before send and save() it | ||
(function(){ | ||
function init() { | ||
@@ -25,5 +25,8 @@ Espruino.Core.Config.add("SAVE_ON_SEND", { | ||
description : "Save the code after sending so that everything is executed again when the board restarts. Not as memory efficient, but more Arduino-like.", | ||
type : "boolean", | ||
defaultValue : false | ||
}); | ||
type : { | ||
0: "No", | ||
1: "Yes", | ||
2: "Yes, execute even after 'reset()'"}, | ||
defaultValue : 0 | ||
}); | ||
@@ -41,3 +44,6 @@ Espruino.addProcessor("transformForEspruino", function(code, callback) { | ||
newCode.push(JSON.stringify(code)); | ||
newCode.push(");"); | ||
if (Espruino.Config.SAVE_ON_SEND==2) | ||
newCode.push(", true);"); | ||
else | ||
newCode.push(");"); | ||
newCode.push("load();\n"); | ||
@@ -49,3 +55,3 @@ newCode = newCode.join(''); | ||
} | ||
Espruino.Plugins.SaveOnSend = { | ||
@@ -52,0 +58,0 @@ init : init, |
@@ -8,3 +8,3 @@ /** | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
------------------------------------------------------------------ | ||
@@ -28,3 +28,4 @@ Escape non-ASCII characters into \xHH UTF-8 sequences before send | ||
for (var i = 0; i < code.length; ++i) { | ||
if (code.charCodeAt(i) >= 128) { | ||
var ch = code.charCodeAt(i); | ||
if (ch >= 128 && ch!=172/*¬*/ && ch!=163/*£*/) { | ||
newCode.push(code.substring(idx, i)); | ||
@@ -31,0 +32,0 @@ newCode.push(escapeChar(code[i])); |
754764
18498