From 876284cb7c84738c28f29680305da4acb72afd9d Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 20 Jun 2014 09:58:41 +0100 Subject: [PATCH] Added Griffin PowerMate node --- hardware/powermate/79-powermate.html | 74 +++++++++++++++++++++++++ hardware/powermate/79-powermate.js | 66 ++++++++++++++++++++++ hardware/powermate/README.md | 23 ++++++++ hardware/powermate/icons/powermate.png | Bin 0 -> 247 bytes 4 files changed, 163 insertions(+) create mode 100644 hardware/powermate/79-powermate.html create mode 100644 hardware/powermate/79-powermate.js create mode 100644 hardware/powermate/README.md create mode 100644 hardware/powermate/icons/powermate.png diff --git a/hardware/powermate/79-powermate.html b/hardware/powermate/79-powermate.html new file mode 100644 index 00000000..b63d1d40 --- /dev/null +++ b/hardware/powermate/79-powermate.html @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + diff --git a/hardware/powermate/79-powermate.js b/hardware/powermate/79-powermate.js new file mode 100644 index 00000000..95c9e4e6 --- /dev/null +++ b/hardware/powermate/79-powermate.js @@ -0,0 +1,66 @@ +/** + * 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. + **/ + +// Require main module +//var RED = require(process.env.NODE_RED_HOME+"/red/red"); +module.exports = function(RED) { + +var PowerMate = require('node-powermate'); +var pm; + +// The main node definition - most things happen in here +function powerMateNode(n) { + RED.nodes.createNode(this,n); + this.name = n.name; + this.topic = n.topic; + + var node = this; + + pm = new PowerMate(); + + pm.on('buttonDown', function() { + var msg = {}; + msg.topic = node.topic + '/button'; + msg.payload = 'down'; + node.send(msg); + }); + + pm.on('buttonUp', function() { + var msg = {}; + msg.topic = node.topic + '/button'; + msg.payload = 'up'; + node.send(msg); + }); + + + pm.on('wheelTurn', function(delta) { + var msg = {}; + msg.topic = node.topic + '/wheel'; + msg.payload = delta; + node.send(msg); + }); + + node.on('close', function(){ + try { + node.log('shutting down powerMate'); + } catch(err) { + node.error(err); + } + }); +} + +RED.nodes.registerType("powerMate",powerMateNode); +} diff --git a/hardware/powermate/README.md b/hardware/powermate/README.md new file mode 100644 index 00000000..efae74b9 --- /dev/null +++ b/hardware/powermate/README.md @@ -0,0 +1,23 @@ +PowerMate +========= +A Node-Red node to read from the [Griffin PowerMate] (http://www.amazon.co.uk/gp/product/B003VWU2WA/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B003VWU2WA&linkCode=as2&tag=bespl-21) + +Install +------- + +This module depends on the node-powermate node so you will need to run + + npm install node-powermate + +Usage +----- + +This node outputs messages for 3 different events + + + Button down + + Button up + + Wheel rotation + +For the first 2 the message payload of 'up' or 'down' respectively is published to the topic + '/button'. For the wheel rotation the message payload is +ve for clockwise and -ve for anti-clockwise on the topic + '/wheel' + + diff --git a/hardware/powermate/icons/powermate.png b/hardware/powermate/icons/powermate.png new file mode 100644 index 0000000000000000000000000000000000000000..7c3a64e3f2edd4cba12b6972c66c80ffa9df43c7 GIT binary patch literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIY)RhkER!@6$ic-57qsy8+?wvG;!9w g_OGS6wM+M3;GFee+HA?xOmmR^p00i_>zopr0MYPI%>V!Z literal 0 HcmV?d00001