UNPKG

node-red-contrib-ledmatrix

Version:

Contains the nodes used in TimeSquAir to use the LEDMatrix library

77 lines (69 loc) 2.87 kB
/** Copyright © 2015 Digital Airways (www.DigitalAirways.com) This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net for more details. **/ module.exports = function(RED) { "use strict"; var Mustache = require("mustache"); //var CMD = "ppmlabel -color \"{{{color}}}\" -size {{size}} -x {{x}} -y {{y}} -t \"{{{text}}}\" {{{src}}} 2> {{{log}}} "; var CMD = "convert -size 1000x16 -font {{{font}}} canvas:black -pointsize {{size}} -channel RGBA -fill \"{{{color}}}\" -draw \"text {{x}},{{y}} \\\"{{{text}}}\\\"\" png8:{{{srcPng}}} 2> {{{log}}}"; CMD += "\nconvert {{{srcPng}}} -compress none {{{src}}} 2> {{{log}}}"; CMD += "\npnmcrop -right {{{src}}}"; CMD += "{{#intensity}} | ppmbrighten -v -{{intensity}} 2> {{{log}}} {{/intensity}}" CMD += " > tmp;" CMD += "\nif [ -e {{{dest}}} ]\n"; CMD += "then\n"; CMD += "\tif [ {{cat}} -eq 0 ]\n"; CMD += "\tthen\n"; CMD += "\t\tpnmcat -l {{{dest}}} /root/thethingbox/rpi-rgb-led-matrix-sh/col.ppm tmp > tmp2;\n"; CMD += "\telse\n"; CMD += "\t\tpnmcat -l {{{dest}}} tmp > tmp2;\n"; CMD += "\tfi\n"; CMD += "\tmv -f tmp2 {{{dest}}};\n\trm tmp;\n"; CMD += "else\n"; CMD += "\tmv -f tmp {{{dest}}}\n"; CMD += "fi\n"; function ledtext(n) { RED.nodes.createNode(this,n); this.text = n.text; var node = this; var size = 3; this.on('input', function (msg) { if(typeof(msg.textsize) != "undefined"){size = msg.textsize}; if (size < 1){ size = 1; } if (size > 5){ size = 5; } var text = ""//default text if(typeof(node.text) != "undefined"){text = node.text}; if(typeof(msg.payload) != "undefined"){text = msg.payload}; size = parseInt(size, 10) + 10; // +5 var params = { cat: msg.alongside || 0, color: msg.color || "white", text: text, intensity: msg.intensity ? 100 - msg.intensity : 60, size: size||11, // 6 font: msg.font || "Roboto-Medium", x: typeof msg.x == "undefined" || msg.x == null ? 0 : msg.x, y: typeof msg.y == "undefined" || msg.y == null ? 12 : msg.y, src: "/root/thethingbox/rpi-rgb-led-matrix-sh/bg.ppm", srcPng: "/root/thethingbox/rpi-rgb-led-matrix-sh/bg.png", dest: "{{{finalppm}}}", log: "/root/userdir/ledmatrix/log.txt" } var cmd = Mustache.render(CMD, params); if(typeof msg.cmd != "string") { msg.cmd = ""; } msg.cmd += cmd; node.send(msg); }); } RED.nodes.registerType("ledtext", ledtext); }