Dia antes primera install

This commit is contained in:
2025-12-08 15:20:28 -06:00
commit 1416478c9c
4130 changed files with 886376 additions and 0 deletions

20
node_modules/node-red-contrib-mcp23017chip/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 fivdi
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.

19
node_modules/node-red-contrib-mcp23017chip/README.md generated vendored Normal file
View File

@@ -0,0 +1,19 @@
Node-Red node for the MCP23017
Each pin (16 in total) can be selected to be an input or output
Inputs
The interval is used to determine how frequently the chip is polled
The bit number is 0 to 15 reflecting the pin
Pull Up engages the low power pull up
Invert engages the inver on the chip
Debounce is a timer where the state must remain at the new level for the debounce time for a change to get to the output
Uses the config node mcp23017chip for all reading and writing on i2c
Requires i2c-bus
To Do
1) Don't allow already selected bits to be selected again
2) When a node is deleted - remove from ids (array in chip)

View File

@@ -0,0 +1,153 @@
<!-- CHIP SECTION -->
<script type="text/javascript">
RED.nodes.registerType('mcp23017chip',{
category: 'config',
defaults: {
addr: {value:"0x20",required:true},
interval: {value:100,required:true},
},
label: function() {
return this.addr;
}
});
</script>
<script type="text/x-red" data-template-name="mcp23017chip">
<div class="form-row">
<label for="node-config-input-addr"><i class="icon-bookmark"></i> Address</label>
<select type="text" id="node-config-input-addr" style="width:70px;">
<option value="0x20">0x20</option>
<option value="0x21">0x21</option>
<option value="0x22">0x22</option>
<option value="0x23">0x23</option>
<option value="0x24">0x24</option>
<option value="0x25">0x25</option>
<option value="0x26">0x26</option>
<option value="0x27">0x27</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-interval"><i class="icon-bookmark"></i> Interval in ms</label>
<input type="number" id="node-config-input-interval">
</div>
</script>
<!-- INPUT SECTION -->
<script type="text/javascript">
RED.nodes.registerType('mcp23017input',{
category: 'input',
color: '#a6bbcf',
defaults: {
name: {value:""},
chip: {type:"mcp23017chip", required:true},
bitNum: {required:true},
pullUp: {value:true},
invert: {value:true},
debounce: {value:200},
onMsg: {value:true},
offMsg: {value:true}
},
inputs:0,
outputs:1,
icon: "file.png",
label: function() {
return this.name||"mcp23017input";
}
});
</script>
<script type="text/x-red" data-template-name="mcp23017input">
<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-chip"><i class="fa fa-globe"></i> Chip</label>
<input type="text" id="node-input-chip">
</div>
<div class="form-row">
<label for="node-input-bitNum"><i class="icon-tag"></i> Bit Number</label>
<input type="number" id="node-input-bitNum" placeholder="Bit Number">
</div>
<div class="form-row">
<label for="node-input-pullUp"><i class="icon-tag"></i> Pull Up</label>
<input type="checkbox" id="node-input-pullUp" placeholder="Pull Up">
</div>
<div class="form-row">
<label for="node-input-invert"><i class="icon-tag"></i> Invert</label>
<input type="checkbox" id="node-input-invert" placeholder="Invert">
</div>
<div class="form-row">
<label for="node-input-debounce"><i class="icon-tag"></i> Debounce Time</label>
<input type="number" id="node-input-debounce" placeholder="Debounce Time">
</div>
<div class="form-row">
<label for="node-input-onMsg"><i class="icon-tag"></i> On Msg</label>
<input type="checkbox" id="node-input-onMsg" placeholder="On Msg">
</div>
<div class="form-row">
<label for="node-input-offMsg"><i class="icon-tag"></i> Off Msg</label>
<input type="checkbox" id="node-input-offMsg" placeholder="Off Msg">
</div>
</script>
<script type="text/x-red" data-help-name="mcp23017input">
<p>MCP23017 has 16 pins - can be individually selected as in or out</p>
<p> The MCP23017Chip node manages the chip (all 16 i/o). This node has the interval to keep reading the input buffer</p>
<p> The Bit or pin individually can set the pull-up and inverton on the chip. The On/Off Msg checkboxs are used to allow messages on change. The status will change anyway regardless of the on/off msg </p>
<p> The debounce sets the time required for a state to be steady before changing the status and sending a message</p>
</script>
<!-- OUTPUT SECTION -->
<script type="text/javascript">
RED.nodes.registerType('mcp23017output',{
category: 'output',
color: '#a6bbcf',
defaults: {
name: {value:""},
chip: {type:"mcp23017chip", required:true},
bitNum: {required:true},
invert: {value:true}
},
inputs:1,
outputs:1,
icon: "file.png",
label: function() {
return this.name||"mcp23017output";
}
});
</script>
<script type="text/x-red" data-template-name="mcp23017output">
<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-chip"><i class="fa fa-globe"></i> Chip</label>
<input type="text" id="node-input-chip">
</div>
<div class="form-row">
<label for="node-input-bitNum"><i class="icon-tag"></i> Bit Number</label>
<input type="number" id="node-input-bitNum" placeholder="Bit Number">
</div>
<div class="form-row">
<label for="node-input-invert"><i class="icon-tag"></i> Invert</label>
<input type="checkbox" id="node-input-invert" placeholder="Invert">
</div>
</script>
<script type="text/x-red" data-help-name="mcp23017ouput">
<p>MCP23017 has 16 pins - can be individually selected as in or out</p>
<p> The MCP23017Chip node manages the chip (all 16 i/o) mainly for the input monitoring</p>
<p> The message to the output requires a payload. If the payload is true then it turns on</p>
<p> Topic (and any other part) is ignored</p>
</script>

View File

@@ -0,0 +1,144 @@
// CHIP SECTION - For inputs this reads the chip and fires the input module
module.exports = function(RED) {
var i2cBus = require("i2c-bus");
function mcp23017chipNode(n) {
RED.nodes.createNode(this,n);
this.addr = parseInt(n.addr, 16);
this.interval = n.interval;
this.isInputs = 0x0000;
this.pullUps = 0x0000;
this.inverts = 0x0000;
this.ids = new Array(16);
this.lastRead = 0x0000;
this.lastWrite = 0x0000;
this.i2c1 = i2cBus.openSync(1);
this.i2c1.writeByteSync(this.addr, 0x0A, 0x00); //set mode iocan bank
this.setBit = function(bitNum, isInput, pullUp, invert, id){
for (var i=0; i < 16; i++){//NEED TO REMOVE ANY OTHER REFERENCES TO THIS ID
if (this.ids[i] == id) {this.ids[i] = null;}
}
this.ids[bitNum] = id;
if (isInput) {this.isInputs = this.isInputs | (1<<bitNum)} else {this.isInputs = this.isInputs & ~(1<<bitNum)};
if (pullUp) {this.pullUps = this.pullUps | (1<<bitNum)} else {this.pullUps = this.pullUps & ~(1<<bitNum)};
if (invert) {this.inverts = this.inverts | (1<<bitNum)} else {this.inverts = this.inverts & ~(1<<bitNum)};
this.i2c1.writeByteSync(this.addr, 0x00, this.isInputs & 0xFF);//update in out mode A
this.i2c1.writeByteSync(this.addr, 0x01, (this.isInputs >> 8) & 0xFF);//update in out mode B
this.i2c1.writeByteSync(this.addr, 0x0C, this.pullUps & 0xFF); //update pull up A
this.i2c1.writeByteSync(this.addr, 0x0D, (this.pullUps >> 8) & 0xFF); //update pull up B
this.i2c1.writeByteSync(this.addr, 0x02, this.inverts & 0xFF); //update pull up A
this.i2c1.writeByteSync(this.addr, 0x03, (this.inverts >> 8) & 0xFF); //update pull up B
}
this.setOutput = function(bitNum, newState){
if (newState){
this.lastWrite = this.lastWrite | 1 << bitNum;
} else {
this.lastWrite = this.lastWrite & ~ (1 << bitNum);
}
if (bitNum < 8) {
this.i2c1.writeByteSync(this.addr, 0x14, this.lastWrite & 0xFF); //Set output A
} else {
this.i2c1.writeByteSync(this.addr, 0x15, (this.lastWrite >> 8) & 0xFF); //Set output B
}
}
var myVar = setInterval(myTimer, this.interval, this );
function myTimer(theChip) {
var ipA = theChip.i2c1.readByteSync(theChip.addr, 0x12);
var ipB = theChip.i2c1.readByteSync(theChip.addr, 0x13);
var ipAll = ipA + (ipB << 8);
if (ipAll != theChip.lastRead){
var diffWord = ipAll ^ theChip.lastRead;
for (var i=0; i < 16; i++){
if (diffWord & (1 << i)){
var newState = (((ipAll & (1 << i)) == 0) ? false : true)
var aBit = RED.nodes.getNode(theChip.ids[i]);
if (aBit != null && (theChip.isInputs & (1 << i)) > 0){ // check bit is used and is an input
aBit.changed(newState);
}
}
}
theChip.lastRead = ipAll;
}
}
this.on('close', function() {
this.i2c1.closeSync();
});
}
RED.nodes.registerType("mcp23017chip",mcp23017chipNode);
//INPUT SECTION
function mcp23017inputNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.addr = config.addr;
this.bitNum = config.bitNum;
this.pullUp = config.pullUp;
this.invert = config.invert;
this.debounce = config.debounce;
this.onMsg = config.onMsg;
this.offMsg = config.offMsg;
this.timerRunning = false;
this.timer = 0;
this.lastState = false;
this.myChip = RED.nodes.getNode(config.chip);
this.myChip.setBit(this.bitNum, true, this.pullUp, this.invert, this.id);
this.changed = function(state) {
if (this.timerRunning){
clearTimeout(this.timer);
}
this.timer = setTimeout(this.deBounceEnd, this.debounce, state, this);
this.timerRunning = true;
}
this.deBounceEnd = function(state, theBit){
theBit.timerRunning = false;
if (theBit.lastState != state){
var msg = {};
msg.payload = state;
if ((state && theBit.onMsg) || (! state && theBit.offMsg)){
node.send(msg);
}
theBit.lastState = state
if (state){
theBit.status({fill:"red",shape:"ring",text:"off"});
}else{
theBit.status({fill:"green",shape:"dot",text:"on"});
}
}
}
}
RED.nodes.registerType("mcp23017input",mcp23017inputNode);
//OUTPUT SECTION
function mcp23017outputNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.addr = config.addr;
this.bitNum = config.bitNum;
this.invert = config.invert;
this.myChip = RED.nodes.getNode(config.chip);
this.myChip.setBit(this.bitNum, false, this.pullUp, this.invert, this.id);
this.on('input', function(msg) {
this.myChip.setOutput(this.bitNum, msg.payload)
if (msg.payload){
this.status({fill:"red",shape:"ring",text:"off"});
}else{
this.status({fill:"green",shape:"dot",text:"on"});
}
});
}
RED.nodes.registerType("mcp23017output",mcp23017outputNode);
}

View File

@@ -0,0 +1,27 @@
{
"name": "node-red-contrib-mcp23017chip",
"version": "0.1.0",
"description": "node-red node for mcp23017 - input and output",
"dependencies": {
"i2c-bus": "~5.2.1"
},
"keywords": [
"node-red",
"mcp23017"
],
"node-red": {
"nodes": {
"mcp23017chip": "mcp23017chip/mcp23017chip.js"
}
},
"main": " ",
"scripts": {
"test": " "
},
"repository": {
"type": "git",
"url": " "
},
"author": "Mike Wilson",
"license": "MIT"
}