Skip to content

Commit

Permalink
support serial input
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Marinacci committed Jun 30, 2014
1 parent 1d66f18 commit ac961f7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
15 changes: 15 additions & 0 deletions electron.js
Expand Up @@ -313,6 +313,21 @@ app.post('/serial/close', function(req,res) {
});
});

app.post('/serial/send', function(req,res) {
if(!req.body.port) {
res.send(JSON.stringify({status:'error', message:'missing serial port'}));
res.end();
return;
}
if(!SERIAL.open) {
res.end(JSON.stringify({status:'error', message:'serial port not open'}));
return;
}
serial.send(req.body.message, function(err, results) {
res.end(JSON.stringify({status:'okay', message:'sent message'}));
})
});

var server = app.listen(54329,function() {
console.log('open your browser to http://localhost:'+server.address().port+'/');
});
Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Expand Up @@ -207,8 +207,8 @@ <h3>Sketches</h3>
</div>
<div class='row'>
<div class='col-xs-12'>
<input type='text' class='input-control'></input>
<button class='btn btn-default'>send</button>
<input type='text' class='input-control' id='serial-input-text'></input>
<button class='btn btn-default' id='serial-send-button'>send</button>
</div>
</div>

Expand Down
9 changes: 9 additions & 0 deletions public/js/electronIDE.js
Expand Up @@ -278,6 +278,15 @@ var ElectronIDE = (function() {
e.preventDefault();
setRate($(this).attr('data-speed'));
});
$("#serial-send-button").click(function(e) {
e.preventDefault();
post('/serial/send', {
port: STATE.port,
message: $("#serial-input-text").val(),
}, function(resp) {
console.log("resp is", resp);
});
})

monitor.onopen = function(e) {
console.log("opened the websocket for ", wsurl);
Expand Down
8 changes: 8 additions & 0 deletions serial.js
Expand Up @@ -30,3 +30,11 @@ exports.close = function(port, cb) {
if(cb) cb();
});
}

exports.send = function(message, cb) {
sp.write(message+'\n',function(err, results) {
console.log('err', err);
console.log('results',results);
if(cb)cb(err,results);
});
}

0 comments on commit ac961f7

Please sign in to comment.