From 0a4b2a4876dd0eb68e3a56586e1d06017e8da3d0 Mon Sep 17 00:00:00 2001 From: Sean Bedford Date: Fri, 14 Mar 2014 17:49:30 +0000 Subject: [PATCH] Added duino support for RC switches and added error handling to heatmiser --- hardware/duino/97-duino.html | 48 ++++++++++++++++++++++++ hardware/duino/97-duino.js | 58 +++++++++++++++++++++++++++++ hardware/heatmiser/100-heatmiser.js | 4 +- 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 hardware/duino/97-duino.html create mode 100644 hardware/duino/97-duino.js diff --git a/hardware/duino/97-duino.html b/hardware/duino/97-duino.html new file mode 100644 index 00000000..4bfa9126 --- /dev/null +++ b/hardware/duino/97-duino.html @@ -0,0 +1,48 @@ + + + + + + + diff --git a/hardware/duino/97-duino.js b/hardware/duino/97-duino.js new file mode 100644 index 00000000..33c380b8 --- /dev/null +++ b/hardware/duino/97-duino.js @@ -0,0 +1,58 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + +var duino = require("duino"); +var util = require('util'); + +function DuinoNode(n) { + var DEBUG = true; + RED.nodes.createNode(this,n); + this.pin = n.pin || "10"; + node = this; + this.board = new duino.Board(); + + + this.on("input", function(message) { + if (typeof(message.payload) == "string") { + message.payload = JSON.parse(message.payload); + } + // Send message as RC triState + if (message.payload.inputType === "RC") { + var rcCode = message.payload.rcCode; + util.log("RCCode = "+ rcCode); + if (rcCode.length != 8) { + util.log("[duino] - Error, code : "+rcCode+ "was not 8 digits long!"); + return; + } + var rcRef = new duino.RC({ + board: node.board, + pin: parseInt(node.pin, 10) + }); + + if (message.payload.on) { + rcRef.triState(message.payload.rcCode + "FFFF"); + } + else { + rcRef.triState(message.payload.rcCode + "FFF0"); + } + } + + }); + +} +RED.nodes.registerType("duino",DuinoNode); diff --git a/hardware/heatmiser/100-heatmiser.js b/hardware/heatmiser/100-heatmiser.js index 9d86b0e3..432d5e65 100644 --- a/hardware/heatmiser/100-heatmiser.js +++ b/hardware/heatmiser/100-heatmiser.js @@ -50,7 +50,9 @@ function HeatmiserNode(n) { }); this.read = function() { - node.hm.read_device(); + if (node.hm) { + node.hm.read_device(); + } }; if (!this.currentStatus) {