node-red-contrib-periph-memory 1.1.0 → 1.2.1

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.
package/README.md CHANGED
@@ -2,15 +2,24 @@
2
2
 
3
3
  Node-RED nodes for memory chips — part of the [Periph](https://github.com/tuhde/Periph) library.
4
4
 
5
- > **Coming soon.** Nodes will be added as chips in this category are implemented.
6
-
7
5
  ## Install
8
6
 
7
+ Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-memory`.
8
+
9
+ Or from the command line in your Node-RED user directory:
10
+
9
11
  ```sh
10
12
  npm install node-red-contrib-periph-memory
11
13
  ```
12
14
 
15
+ ## Nodes
16
+
17
+ | Node | Kind | Description |
18
+ |------|------|-------------|
19
+ | `24aa02uid-device` | config | I²C bus and address for a 24AA02UID |
20
+ | `24aa02uid` | input | Reads the factory-programmed 32-bit unique serial number from a 24AA02UID EEPROM, or reads / writes user EEPROM bytes, over I²C. |
21
+
13
22
  ## Links
14
23
 
15
24
  - [GitHub](https://github.com/tuhde/Periph)
16
- - [All supported chips](https://github.com/tuhde/Periph#supported-chips)
25
+ - [periph JS driver](https://www.npmjs.com/package/periph)
@@ -32,7 +32,7 @@
32
32
  <script type="text/javascript">
33
33
  RED.nodes.registerType('24aa02uid', {
34
34
  category: 'Peripheral',
35
- color: '#a6bbcf',
35
+ color: '#C084FC',
36
36
  defaults: {
37
37
  name: { value: '' },
38
38
  device: { value: '', type: '24aa02uid-device', required: true }
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = function(RED) {
4
- const { I2CTransport } = require('periph/src/transport/i2c');
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { EEPROM24AA02UIDFull } = require('periph/src/chips/memory/_24aa02uid');
6
6
 
7
7
  function Eeprom24AA02UIDDeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
11
- const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
12
- node.driver = new EEPROM24AA02UIDFull(transport);
13
- node.transport = transport;
11
+ const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.driver = new EEPROM24AA02UIDFull(connection);
13
+ node.connection = connection;
14
14
  } catch (e) {
15
15
  node.error('24AA02UID init failed: ' + e.message);
16
16
  }
17
17
  node.on('close', function() {
18
- if (node.transport) node.transport.close();
18
+ if (node.connection) node.connection.close();
19
19
  });
20
20
  }
21
21
  RED.nodes.registerType('24aa02uid-device', Eeprom24AA02UIDDeviceNode);
@@ -25,7 +25,7 @@ module.exports = function(RED) {
25
25
  const node = this;
26
26
  node.device = RED.nodes.getNode(config.device);
27
27
 
28
- node.on('input', function(msg, send, done) {
28
+ node.on('input', async function(msg, send, done) {
29
29
  if (!node.device || !node.device.driver) {
30
30
  node.error('No 24AA02UID device configured', msg);
31
31
  done();
@@ -35,7 +35,7 @@ module.exports = function(RED) {
35
35
  const d = node.device.driver;
36
36
  const op = (msg.op || config.op || 'read_uid');
37
37
  if (op === 'read_uid') {
38
- const uid = d.readUid();
38
+ const uid = await d.readUid();
39
39
  msg.payload = {
40
40
  uid: uid.toString('hex').toUpperCase(),
41
41
  uid_int: uid.readUInt32BE(0)
@@ -43,12 +43,12 @@ module.exports = function(RED) {
43
43
  } else if (op === 'read') {
44
44
  const address = (msg.address != null) ? msg.address : 0;
45
45
  const length = (msg.length != null) ? msg.length : 4;
46
- const data = d.read(address, length);
46
+ const data = await d.read(address, length);
47
47
  msg.payload = { data: Array.from(data) };
48
48
  } else if (op === 'write') {
49
49
  const address = (msg.address != null) ? msg.address : 0;
50
50
  const data = (msg.data != null) ? msg.data : [];
51
- d.write(address, Buffer.from(data));
51
+ await d.write(address, Buffer.from(data));
52
52
  msg.payload = { ok: true };
53
53
  } else {
54
54
  node.error('Unknown op: ' + op, msg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-memory",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Node-RED nodes for memory chips",
5
5
  "keywords": [
6
6
  "node-red",