node-red-contrib-bean
Version:
Node-red node for the LightBlue Bean
227 lines (216 loc) • 9.98 kB
HTML
<!--
The MIT License (MIT)
Copyright (c) 2015 Geoffrey Arnold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<script type="text/x-red" data-template-name="read scratch">
<div class="form-row">
<label for="node-input-bean"><i class="fa fa-cog"></i> Bean</label>
<input type="text" id="node-input-bean">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<input type="checkbox" id="node-input-readOne" style="display: inline-block; width: auto; vertical-align: middle;">
<label for="node-input-readOne">Scratch 1</label>
msg.<input type="text" id="node-input-property1" placeholder="scratch1" style="display: inline-block; width: auto; vertical-align: middle;">
<select id="node-input-type1" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="string">String</option>
<option value="number">Number</option>
<option value="buffer">Buffer</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-readTwo" style="display: inline-block; width: auto; vertical-align: middle;">
<label for="node-input-readTwo">Scratch 2</label>
msg.<input type="text" id="node-input-property2" placeholder="scratch2" style="display: inline-block; width: auto; vertical-align: middle;">
<select id="node-input-type2" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="string">String</option>
<option value="number">Number</option>
<option value="buffer">Buffer</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-readThree" style="display: inline-block; width: auto; vertical-align: middle;">
<label for="node-input-readThree">Scratch 3</label>
msg.<input type="text" id="node-input-property3" placeholder="scratch3" style="display: inline-block; width: auto; vertical-align: middle;">
<select id="node-input-type3" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="string">String</option>
<option value="number">Number</option>
<option value="buffer">Buffer</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-readFour" style="display: inline-block; width: auto; vertical-align: middle;">
<label for="node-input-readFour">Scratch 4</label>
msg.<input type="text" id="node-input-property4" placeholder="scratch4" style="display: inline-block; width: auto; vertical-align: middle;">
<select id="node-input-type4" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="string">String</option>
<option value="number">Number</option>
<option value="buffer">Buffer</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-readFive" style="display: inline-block; width: auto; vertical-align: middle;">
<label for="node-input-readFive">Scratch 5</label>
msg.<input type="text" id="node-input-property5" placeholder="scratch5" style="display: inline-block; width: auto; vertical-align: middle;">
<select id="node-input-type5" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="string">String</option>
<option value="number">Number</option>
<option value="buffer">Buffer</option>
</select>
</div>
</script>
<script type="text/x-red" data-template-name="write scratch">
<div class="form-row">
<label for="node-input-bean"><i class="fa fa-cog"></i> Bean</label>
<input type="text" id="node-input-bean">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-msgProperty"><i class="fa fa-code"></i> Write</label>
msg.<input type="text" id="node-input-msgProperty" placeholder="payload" style="display: inline-block; width: auto; vertical-align: middle;">
</div>
<div class="form-row">
<label for="node-input-writeMethod"><i class="fa fa-random"></i> to</label>
<select id="node-input-writeMethod" style="display: inline-block; width: auto; vertical-align: middle;">
<option value="writeOne">Scratch 1</option>
<option value="writeTwo">Scratch 2</option>
<option value="writeThree">Scratch 3</option>
<option value="writeFour">Scratch 4</option>
<option value="writeFive">Scratch 5</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="read scratch">
<p>A Node-RED node to read <a href="http://punchthrough.com/bean/arduino-users-guide/#scratch_characteristics" target="_blank">scratch characteristics</a> from a <a href="https://punchthrough.com/bean/" target="_blank">LightBlue Bean</a>.</p>
<p>Sending any message to this node will trigger a request to read a Bean's scratch characteristics. By default, the value of scratch characteristic 1 will be converted to a <code>String</code> and set as property <code>msg.payload</code>.</p>
<p>You can configure which characteristics to read, as well as their corresponding <code>msg</code> property names and types, in the node template.</p>
</script>
<script type="text/x-red" data-help-name="write scratch">
<p>A Node-RED node to write <a href="http://punchthrough.com/bean/arduino-users-guide/#scratch_characteristics" target="_blank">scratch characteristics</a> on a <a href="https://punchthrough.com/bean/" target="_blank">LightBlue Bean</a>.</p>
<p>This node can be connected to the output of any node, and will write the specified <code>msg</code> property to the selected scratch characteristic. The <code>msg</code> property can be a <code>Buffer</code>, <code>Number</code>, or <code>String</code>. By default, the value of <code>msg.payload</code> will be written to scratch characteristic 1.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('read scratch', {
category: 'LightBlue Bean-input',
color: '#3FADB5',
defaults: {
bean: {
value: '',
required: true,
type: 'bean'
},
name: {
value: ''
},
readOne: {
value: true
},
property1: {
value: 'payload'
},
type1: {
value: 'string'
},
readTwo: {
value: false
},
property2: {
value: ''
},
type2: {
value: ''
},
readThree: {
value: false
},
property3: {
value: ''
},
type3: {
value: ''
},
readFour: {
value: false
},
property4: {
value: ''
},
type4: {
value: ''
},
readFive: {
value: false
},
property5: {
value: ''
},
type5: {
value: ''
}
},
inputs: 1,
outputs: 1,
icon: 'scratch.png',
paletteLabel: "read scratch",
label: function() {
var bean = RED.nodes.node(this.bean);
return this.name || ((bean ? bean.label() : 'Bean') + ' read scratch');
},
labelStyle: function() {
return this.name ? 'node_label_italic' : '';
}
});
RED.nodes.registerType('write scratch', {
category: 'LightBlue Bean-output',
color: '#3FADB5',
defaults: {
bean: {
value: '',
required: true,
type: 'bean'
},
name: {
value: ''
},
msgProperty: {
value: 'payload'
},
writeMethod: {
value: 'writeOne'
}
},
inputs: 1,
outputs: 0,
icon: 'scratch.png',
paletteLabel: "write scratch",
label: function() {
var bean = RED.nodes.node(this.bean);
return this.name || ((bean ? bean.label() : 'Bean') + ' write scratch');
},
labelStyle: function() {
return this.name ? 'node_label_italic' : '';
},
align: 'right'
});
</script>