mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
mraa gpio din features (#929)
* mraa-gpio-din: add iot2050 board This patch adds iot2050 board in possible list of boards. Signed-off-by: zengchao <chao.zeng@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add cleanup on close Required as nodejs will only lazily delete the node objects, and we may race with the next user requesting the resources. ISR thread release. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: extend GPIO lines Signed-off-by: zengchao <chao.zeng@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add configurable GPIO mode for DIN GPIO mode wasn't set correctly, it was set from Pinmuxes modes instead of GPIO. Add way to control GPIO modes on DINs from Node-RED with possible values from mraa : Strong, Hiz, Pull-down, Pull-up. Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com> * mraa-gpio-din: add support for initial message from digital input This allows to send out an initial message with the current digital pin state on startup, simplifying initializations of certain flows. Based on siemens/meta-iot2000@5fc2bbe patch 0003. Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>
This commit is contained in:
parent
0b3b918528
commit
983dafff13
@ -1,13 +1,15 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mraa-gpio-din',{
|
||||
category: 'Intel gpio',
|
||||
category: 'GPIO',
|
||||
color: '#a6bbcf',
|
||||
paletteLabel: 'digital',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
pin: {value:"", required: true},
|
||||
interrupt: {value:"", required: true}
|
||||
interrupt: {value:"", required: true},
|
||||
mode: {value:"", required: true},
|
||||
initial: {value: false}
|
||||
},
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
@ -30,6 +32,7 @@
|
||||
if (data === 5) { t = "Raspberry Pi"; }
|
||||
if (data === 6) { t = "Beaglebone"; }
|
||||
if (data === 7) { t = "Banana"; }
|
||||
if (data === 25) { t = "IOT2050"; }
|
||||
$('#type-tip').text(t);
|
||||
$('#node-input-pin').val(pinnow);
|
||||
});
|
||||
@ -59,6 +62,22 @@
|
||||
<option value="11">D11</option>
|
||||
<option value="12">D12</option>
|
||||
<option value="13">D13</option>
|
||||
<option value="14">D14</option>
|
||||
<option value="15">D15</option>
|
||||
<option value="16">D16</option>
|
||||
<option value="17">D17</option>
|
||||
<option value="18">D18</option>
|
||||
<option value="19">D19</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa-level-up"></i> Mode</label>
|
||||
<select type="text" id="node-input-mode" style="width: 250px;">
|
||||
<option value='' disabled selected style='display:none;'>select mode</option>
|
||||
<option value="0">Strong </option>
|
||||
<option value="1">Pull-up </option>
|
||||
<option value="2">Pull-down </option>
|
||||
<option value="3">Hiz </option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
@ -70,6 +89,11 @@
|
||||
<option value="b">Both </option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row" id="node-initial-tick">
|
||||
<label> </label>
|
||||
<input type="checkbox" id="node-input-initial" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-initial" style="width: 70%;">Send initial message with level of pin.</label>
|
||||
</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" placeholder="Name" style="width: 250px;">
|
||||
@ -78,7 +102,7 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mraa-gpio-din">
|
||||
<p>A digital input pin for an Intel Galileo or Edison board.</p>
|
||||
<p>A digital input pin for an Intel Galileo/Edison/Siemens IOT2050 board.</p>
|
||||
<p>The <code>msg.payload</code> contains the value (0 or 1), and <code>msg.topic</code>
|
||||
contains "{the_board_name}/D{the pin number}".</p>
|
||||
</script>
|
||||
|
@ -7,13 +7,16 @@ module.exports = function(RED) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.pin = n.pin;
|
||||
this.interrupt = n.interrupt;
|
||||
this.mode = n.mode;
|
||||
this.initialMsg = n.initial;
|
||||
this.x = new m.Gpio(parseInt(this.pin));
|
||||
this.board = m.getPlatformName();
|
||||
this.defaultTimeout = 100;
|
||||
var node = this;
|
||||
node.x.mode(m.PIN_GPIO);
|
||||
node.x.mode(parseInt(this.mode));
|
||||
node.x.dir(m.DIR_IN);
|
||||
node.x.isr(m.EDGE_BOTH, function() {
|
||||
var g = node.x.read();
|
||||
|
||||
var eventHandler = function(g) {
|
||||
var msg = { payload:g, topic:node.board+"/D"+node.pin };
|
||||
switch (g) {
|
||||
case 0: {
|
||||
@ -34,8 +37,15 @@ module.exports = function(RED) {
|
||||
node.status({fill:"grey",shape:"ring",text:"unknown"});
|
||||
}
|
||||
}
|
||||
});
|
||||
switch (node.x.read()) {
|
||||
}
|
||||
|
||||
var isrCallback = function() {
|
||||
eventHandler(node.x.read());
|
||||
}
|
||||
|
||||
node.x.isr(m.EDGE_BOTH, isrCallback);
|
||||
var initialState = node.x.read();
|
||||
switch (initialState) {
|
||||
case 0: {
|
||||
node.status({fill:"green",shape:"ring",text:"low"});
|
||||
break;
|
||||
@ -48,8 +58,17 @@ module.exports = function(RED) {
|
||||
node.status({});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.initialMsg) {
|
||||
setTimeout(() => {
|
||||
node.send( { payload: node.x.read(), topic:node.board+"/D"+node.pin } );
|
||||
}, this.defaultTimeout);
|
||||
}
|
||||
|
||||
this.on('close', function() {
|
||||
node.x.isr(m.EDGE_BOTH, null);
|
||||
node.x.isrExit();
|
||||
node.x.close();
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mraa-gpio-din", gpioDin);
|
||||
|
Loading…
Reference in New Issue
Block a user