Added Griffin PowerMate node

This commit is contained in:
Ben Hardill 2014-06-20 09:58:41 +01:00
parent 42ad8920cb
commit 876284cb7c
4 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,74 @@
<!--
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.
-->
<!-- First, the content of the edit dialog is defined. -->
<script type="text/x-red" data-template-name="powerMate">
<!-- data-template-name identifies the node type this is for -->
<!-- Each of the following divs creates a field in the edit dialog. -->
<!-- Generally, there should be an input for each property of the node. -->
<!-- The for and id attributes identify the corresponding property -->
<!-- (with the 'node-input-' prefix). -->
<!-- The available icon classes are defined in Twitter Bootstrap -->
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. -->
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-tag"></i> Topic</label>
<input type="text" id="node-input-topic" >
</div>
</script>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="powerMate">
<!-- data-help-name identifies the node type this help is for -->
<!-- This content appears in the Info sidebar when a node is selected -->
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
<!-- node in the palette. -->
<p>Input node for the <a href="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">Griffin Powermate</a></p>
<p>The topic setting is a prefix that will be pre-pended to button or wheel. e.g. <i>powermate/button</i> or <i>powermate/wheel</i></p>
<p>For wheel inputs the payload will be +ve for clockwise and -ve for anti-clockwise.</p>
<p>For button inputs the payload will be 'up' or 'down'</p>
</script>
<!-- Finally, the node type is registered along with all of its properties -->
<!-- The example below shows a small subset of the properties that can be set-->
<script type="text/javascript">
RED.nodes.registerType('powerMate',{
category: 'advanced-function', // the palette category
color:"GoldenRod",
defaults: { // defines the editable properties of the node
name: {value:"powermate"}, // along with default values.
topic: {value:"powermate"}
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "powermate.png", // set the icon (held in public/icons)
label: function() { // sets the default label contents
return this.name||this.topic||"powermate";
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
}
});
</script>

View File

@ -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);
}

View File

@ -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'

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B