node-red-contrib-periph-adc-dac 1.3.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { Mcp4xxxFull } = require('periph/src/chips/adc_dac/mcp4xxx');
6
+ const { GpioOutputPin } = require('periph/src/connection/output_pin');
7
+
8
+ function Mcp4xxxDeviceNode(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+ try {
12
+ const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
13
+ let hvc = null;
14
+ if (config.hvcPin !== undefined && config.hvcPin !== '') {
15
+ // opengpio is only needed when a high-voltage control pin is configured.
16
+ const { Default } = require('opengpio');
17
+ hvc = new GpioOutputPin(Default.output({ chip: parseInt(config.gpioChip || 0), line: parseInt(config.hvcPin) }));
18
+ }
19
+ node.driver = new Mcp4xxxFull(connection, config.part || 'MCP4532',
20
+ parseFloat(config.rab || '10000'), parseFloat(config.rwiper || '75'), hvc);
21
+ node.connection = connection;
22
+ node.driver.init().catch(function(e) { node.error('MCP4XXX init failed: ' + e.message); });
23
+ } catch (e) {
24
+ node.error('MCP4XXX init failed: ' + e.message);
25
+ }
26
+ node.on('close', function() {
27
+ if (node.connection) node.connection.close();
28
+ });
29
+ }
30
+ RED.nodes.registerType('mcp4xxx-device', Mcp4xxxDeviceNode);
31
+
32
+ async function snapshot(d, channel) {
33
+ return {
34
+ channel: channel,
35
+ code: await d.getWiper(channel),
36
+ resistance: await d.getResistance(channel)
37
+ };
38
+ }
39
+
40
+ function Mcp4xxxNode(config) {
41
+ RED.nodes.createNode(this, config);
42
+ const node = this;
43
+ node.device = RED.nodes.getNode(config.device);
44
+
45
+ node.on('input', async function(msg, send, done) {
46
+ if (!node.device || !node.device.driver) {
47
+ node.error('No MCP4XXX device configured', msg);
48
+ done();
49
+ return;
50
+ }
51
+ try {
52
+ const d = node.device.driver;
53
+ const p = msg.payload;
54
+ if (p && typeof p === 'object' && p.data !== undefined) {
55
+ const index = parseInt(p.data.index);
56
+ if (p.data.value !== undefined) await d.writeData(index, parseInt(p.data.value));
57
+ msg.payload = { index: index, value: await d.readData(index) };
58
+ } else if (p && typeof p === 'object' && (p.code !== undefined || p.ohms !== undefined ||
59
+ p.ratio !== undefined || p.step !== undefined || p.shutdown !== undefined ||
60
+ p.store !== undefined)) {
61
+ const channel = p.channel !== undefined ? parseInt(p.channel) : 0;
62
+ if (p.code !== undefined) {
63
+ await d.setWiper(parseInt(p.code), channel);
64
+ } else if (p.ohms !== undefined) {
65
+ await d.setResistance(parseFloat(p.ohms), channel);
66
+ } else if (p.ratio !== undefined) {
67
+ await d.setRatio(parseFloat(p.ratio), channel);
68
+ } else if (p.step !== undefined) {
69
+ const n = parseInt(p.step);
70
+ if (n >= 0) await d.increment(n, channel); else await d.decrement(-n, channel);
71
+ } else if (p.shutdown !== undefined) {
72
+ if (p.shutdown) await d.shutdown(channel); else await d.resume(channel);
73
+ }
74
+ const out = await snapshot(d, channel);
75
+ if (p.shutdown !== undefined) out.shutdown = await d.isShutdown(channel);
76
+ if (p.store) out.stored = await d.storeWiper(channel);
77
+ msg.payload = out;
78
+ } else {
79
+ const wiper = [];
80
+ const resistance = [];
81
+ for (let c = 0; c < d.channels(); c++) {
82
+ wiper.push(await d.getWiper(c));
83
+ resistance.push(await d.getResistance(c));
84
+ }
85
+ msg.payload = { wiper: wiper, resistance: resistance };
86
+ if (d.isNonvolatile()) msg.payload.status = await d.readStatus();
87
+ }
88
+ send(msg);
89
+ done();
90
+ } catch (e) {
91
+ done(e);
92
+ }
93
+ });
94
+ }
95
+ RED.nodes.registerType('periph-mcp4xxx', Mcp4xxxNode);
96
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-adc-dac",
3
- "version": "1.3.3",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for ADC and DAC chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -14,6 +14,8 @@
14
14
  "nodes": {
15
15
  "ad5243": "nodes/ad5243/ad5243.js",
16
16
  "ad5248": "nodes/ad5248/ad5248.js",
17
+ "ad5251": "nodes/ad5251/ad5251.js",
18
+ "ad5252": "nodes/ad5252/ad5252.js",
17
19
  "ad7705": "nodes/ad7705/ad7705.js",
18
20
  "ad7706": "nodes/ad7706/ad7706.js",
19
21
  "ads1013": "nodes/ads1013/ads1013.js",
@@ -21,12 +23,20 @@
21
23
  "ads1113": "nodes/ads1113/ads1113.js",
22
24
  "ads1114": "nodes/ads1114/ads1114.js",
23
25
  "ads1115": "nodes/ads1115/ads1115.js",
26
+ "ads7828": "nodes/ads7828/ads7828.js",
27
+ "cat5171": "nodes/cat5171/cat5171.js",
28
+ "cs43l22": "nodes/cs43l22/cs43l22.js",
29
+ "ds1881": "nodes/ds1881/ds1881.js",
30
+ "ds3502": "nodes/ds3502/ds3502.js",
31
+ "es8311": "nodes/es8311/es8311.js",
24
32
  "hx710a": "nodes/hx710a/hx710a.js",
25
33
  "hx710b": "nodes/hx710b/hx710b.js",
26
34
  "hx711": "nodes/hx711/hx711.js",
27
35
  "hy3131": "nodes/hy3131/hy3131.js",
36
+ "mcp3422": "nodes/mcp3422/mcp3422.js",
28
37
  "mcp4725": "nodes/mcp4725/mcp4725.js",
29
38
  "mcp4728": "nodes/mcp4728/mcp4728.js",
39
+ "mcp4xxx": "nodes/mcp4xxx/mcp4xxx.js",
30
40
  "pcf8591": "nodes/pcf8591/pcf8591.js"
31
41
  }
32
42
  },