Comparing version 0.0.7 to 0.0.8
@@ -33,2 +33,7 @@ var Board, Promise, SerialPort, assert, events, rfcontrol, serialport, | ||
this._onData = __bind(this._onData, this); | ||
this.on('ready', (function(_this) { | ||
return function() { | ||
return _this.setupWatchdog(); | ||
}; | ||
})(this)); | ||
} | ||
@@ -43,2 +48,3 @@ | ||
} | ||
this.stopWatchdog(); | ||
return this.pendingConnect = (this.serialPort != null ? this.serialPort.closeAsync() : Promise.resolve())["finally"]((function(_this) { | ||
@@ -52,2 +58,5 @@ return function() { | ||
}, openImmediately = false); | ||
_this.serialPort.on('error', function(error) { | ||
return _this.emit('error', error); | ||
}); | ||
return _this.serialPort.openAsync().then(function() { | ||
@@ -58,2 +67,3 @@ var resolver; | ||
return new Promise(function(resolve, reject) { | ||
_this.serialPort.writeAsync("PING\n")["catch"](reject); | ||
resolver = resolve; | ||
@@ -87,2 +97,33 @@ return _this.once("ready", resolver); | ||
Board.prototype.setupWatchdog = function() { | ||
this.stopWatchdog(); | ||
return this._watchdogTimeout = setTimeout(((function(_this) { | ||
return function() { | ||
var now; | ||
now = new Date().getTime(); | ||
if (now - _this._lastDataTime < 10000) { | ||
_this.setupWatchdog(); | ||
return; | ||
} | ||
return _this.serialPort.writeAsync("PING\n").then(function() { | ||
return _this.setupWatchdog(); | ||
}).timeout(5000)["catch"](function(err) { | ||
_this.serialPort = null; | ||
_this.stopWatchdog(); | ||
_this.emit('reconnect', err); | ||
return Promise.delay(5000).then(function() { | ||
return _this.connect()["catch"](function(error) { | ||
_this.emit('reconnect', err); | ||
return _this.setupWatchdog(); | ||
}); | ||
}).done(); | ||
}).done(); | ||
}; | ||
})(this)), 10000); | ||
}; | ||
Board.prototype.stopWatchdog = function() { | ||
return clearTimeout(this._watchdogTimeout); | ||
}; | ||
Board.prototype._onData = function(_line) { | ||
@@ -98,4 +139,7 @@ var args, cmd, line; | ||
if (!this.ready) { | ||
return; | ||
this.serialPort.writeAsync("RESET\n")["catch"](function(error) { | ||
return this.emit("error", error); | ||
}); | ||
} | ||
this._lastDataTime = new Date().getTime(); | ||
args = line.split(" "); | ||
@@ -113,2 +157,4 @@ assert(args.length >= 1); | ||
return this._handleKeypad(cmd, args); | ||
case 'PING': | ||
break; | ||
default: | ||
@@ -115,0 +161,0 @@ return console.log("unknown message received: " + line); |
{ | ||
"name": "homeduino", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Node.js library for interfacing with the homeduino ardunio library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
57527
309