SenseHAT: accept number payload as text message

This commit is contained in:
Nick O'Leary 2016-03-04 17:26:21 +00:00
parent a2915b9a97
commit a3e2365ab9
3 changed files with 34 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-sense-hat",
"version" : "0.0.3",
"version" : "0.0.4",
"description" : "A Node-RED node to interact with a Raspberry Pi Sense HAT",
"repository" : {
"type":"git",

View File

@ -231,12 +231,38 @@ module.exports = function(RED) {
node.on("close", function(done) {
HAT.close(this,done);
});
var handleTextMessage = function(line,msg) {
var textCol = colours.getRGB(msg.color);
var backCol = colours.getRGB(msg.background);
var speed = null;
if (!isNaN(msg.speed)) {
speed = msg.speed;
}
var command = "T";
if (textCol) {
command += textCol;
if (backCol) {
command += ","+backCol;
}
}
if (speed) {
var s = parseInt(speed);
if (s >= 1 && s <= 5) {
s = 0.1 + (3-s)*0.03;
}
command = command + ((command.length === 1)?"":",") + s;
}
command += ":" + line;
return command;
}
node.on("input",function(msg) {
var command;
var parts;
var col;
if (typeof msg.payload === 'string') {
if (typeof msg.payload === 'number') {
HAT.send(handleTextMessage(""+msg.payload,msg));
} else if (typeof msg.payload === 'string') {
var lines = msg.payload.split("\n");
lines.forEach(function(line) {
command = null;
@ -300,27 +326,7 @@ module.exports = function(RED) {
} else if (/^F(H|V)$/i.test(line)) {
command = line.toUpperCase();
} else {
var textCol = colours.getRGB(msg.color);
var backCol = colours.getRGB(msg.background);
var speed = null;
if (!isNaN(msg.speed)) {
speed = msg.speed;
}
command = "T";
if (textCol) {
command += textCol;
if (backCol) {
command += ","+backCol;
}
}
if (speed) {
var s = parseInt(speed);
if (s >= 1 && s <= 5) {
s = 0.1 + (3-s)*0.03;
}
command = command + ((command.length === 1)?"":",") + s;
}
command += ":" + line;
command = handleTextMessage(line,msg);
}
}
if (command) {

View File

@ -89,9 +89,11 @@ class ScrollThread(threading.Thread):
try:
SH.show_message(self.message,text_colour=self.fcol,back_colour=self.bcol,scroll_speed=self.speed)
except:
SH.set_rotation(old_rotation,False)
SH.clear(self.bcol);
pass
try:
SH.set_rotation(old_rotation,False)
SH.clear(self.bcol);
except:
pass
def interrupt(self):
if not self.isAlive():