UNPKG

node-red-contrib-pitft

Version:
40 lines 1.35 kB
module.exports = function(RED) { var pitft = require("pitft"); var vm = require('vm'); function PiTftOutNode(config) { var node = this; RED.nodes.createNode(this, config); this.device = config.device || "/dev/fb1"; this.script = vm.createScript(config.script || ""); this.fb = pitft(this.device); var sandbox = { fb: this.fb, log: this.log, warn: this.warn, error: this.error, status: this.status, context: { global:RED.settings.functionGlobalContext || {} }, setTimeout: setTimeout, clearTimeout: clearTimeout }; var context = vm.createContext(sandbox); try { this.script.runInContext(context); if (context.update != undefined) { this.on("input", function(msg) { context.update(msg); }); } if (context.close != undefined) { this.on("close", context.close); } } catch(err) { // eg SyntaxError - which v8 doesn't include line number information // so we can't do better than this this.error(err); } } RED.nodes.registerType("pitft out", PiTftOutNode); };