Skip to content

Commit

Permalink
Get the node executing defined strings
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmtracey committed Jan 12, 2018
1 parent 95e9fb2 commit 72ddc7e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,5 @@ node_modules/*
*.pyc
*.pycache
notes.md
.vscode
.vscode
*.cache
14 changes: 9 additions & 5 deletions execute.py
@@ -1,7 +1,11 @@
import sys
# import microbit
import sys, os
os.chdir(sys.argv[1])

FUNCTION = sys.argv[1]
VALUE = sys.argv[2]
import microbit

print(FUNCTION, VALUE)
FUNCTION = sys.argv[2]
VALUE = sys.argv[3]

print(FUNCTION, VALUE)

microbit.display.scroll(VALUE)
Binary file added icons/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions index.html
@@ -0,0 +1,32 @@
<script type="text/javascript">
RED.nodes.registerType('bitio-wrapper',{
category: 'function',
color: '#34b6ff',
defaults: {
name: {value:""}
},
inputs:1,
outputs:0,
icon: "icon.png",
label: function() {
return this.name||"bitio-wrapper";
}
});
</script>

<script type="text/x-red" data-template-name="bitio-wrapper">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>

<div class="form-row">
<label for="node-input-serialport"><i class="icon-tag"></i>Microbit Serial Port</label>
<input type="text" id="node-input-serialport" placeholder="/dev/tty.usbmodemXXXX">
</div>

</script>

<script type="text/x-red" data-help-name="bitio-wrapper">
<p>A wrapper for the <a href="https://github.com/whaleygeek/bitio/">Bitio Python library</a> written by <a href="https://twitter.com/whaleygeek">David Whale</a>.</p>
</script>
31 changes: 20 additions & 11 deletions index.js
@@ -1,16 +1,19 @@
const debug = require('debug');
const debug = require('debug')('node-red-contrib-bitio-wrapper');
const { spawn } = require('child_process');

function executeMicrobitCommand(command, options){
function executeMicrobitCommand(wordsToSay){

return new Promise( (resolve, reject) => {

const arguments = [
'execute.py',
`${__dirname}/execute.py`,
__dirname,
`scrolling-text`,
"Hello!"
wordsToSay
];

console.log(arguments);

const microbitProcess = spawn('python', arguments);

microbitProcess.stdout.on('data', (data) => {
Expand Down Expand Up @@ -43,16 +46,22 @@ module.exports = function(RED) {
RED.nodes.createNode(this, config);

var node = this;

node.on('input', function(msg) {
/*msg.payload = msg.payload.toLowerCase();
node.send(msg);*/

console.log('INPUT:', msg);
executeMicrobitCommand(msg.payload.toString())
.then(d => {
console.log(d);
node.send(msg);
})
.catch(e => console.log('err:', e))
;

});

}

RED.nodes.registerType("bitio", bitio);

}
RED.nodes.registerType("bitio-wrapper", bitio);

executeMicrobitCommand();
}
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -27,7 +27,6 @@
}
},
"dependencies": {
"debug": "^3.1.0",
"escape-string-regexp": "^1.0.5"
"debug": "^3.1.0"
}
}

0 comments on commit 72ddc7e

Please sign in to comment.