node-red-contrib-periph-motor 1.3.2 → 1.3.3

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
@@ -16,6 +16,7 @@ npm install node-red-contrib-periph-motor
16
16
 
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
19
+ | `periph-drv2605` | input | Plays haptic effects on an ERM or LRA vibration motor through a DRV2605 haptic driver over I²C (fixed address 0x5A). The EN pin must be high. |
19
20
  | `periph-drv8830` | input | Drives a brushed DC motor through a DRV8830 low-voltage H-bridge over I²C, and reports its fault status. The chip regulates the commanded voltage across the motor, so speed stays constant as the supply sags. |
20
21
 
21
22
  ## Links
@@ -0,0 +1,162 @@
1
+ [
2
+ {
3
+ "id": "tab-drv2605-demo",
4
+ "type": "tab",
5
+ "label": "DRV2605 Haptic Demo",
6
+ "disabled": false,
7
+ "info": "Haptic feedback on a vibration motor. The first Inject node sends a button-press effect ({effect: 7}, Soft Bump) on click; the second sends a notification sequence ({sequence: [47, [\"wait\", 200], 47]}, two buzzes 200 ms apart); the third sends {rtp: 0.6} for a constant 60 % buzz and, after 1 s, a Function node sends {stop: true}. Every reply from the periph-drv2605 node is shown in a Debug node. Demonstrates click, notification and constant-buzz haptics."
8
+ },
9
+ {
10
+ "id": "inj-click",
11
+ "type": "inject",
12
+ "name": "Button press",
13
+ "props": [
14
+ {
15
+ "p": "payload"
16
+ }
17
+ ],
18
+ "repeat": "",
19
+ "crontab": "",
20
+ "once": false,
21
+ "onceDelay": 0.1,
22
+ "topic": "",
23
+ "payload": "{\"effect\":7}",
24
+ "payloadType": "json",
25
+ "z": "tab-drv2605-demo",
26
+ "x": 150,
27
+ "y": 80,
28
+ "wires": [
29
+ [
30
+ "drv"
31
+ ]
32
+ ]
33
+ },
34
+ {
35
+ "id": "inj-notify",
36
+ "type": "inject",
37
+ "name": "Notification",
38
+ "props": [
39
+ {
40
+ "p": "payload"
41
+ }
42
+ ],
43
+ "repeat": "",
44
+ "crontab": "",
45
+ "once": false,
46
+ "onceDelay": 0.1,
47
+ "topic": "",
48
+ "payload": "{\"sequence\":[47,[\"wait\",200],47]}",
49
+ "payloadType": "json",
50
+ "z": "tab-drv2605-demo",
51
+ "x": 150,
52
+ "y": 140,
53
+ "wires": [
54
+ [
55
+ "drv"
56
+ ]
57
+ ]
58
+ },
59
+ {
60
+ "id": "inj-buzz",
61
+ "type": "inject",
62
+ "name": "Constant buzz",
63
+ "props": [
64
+ {
65
+ "p": "payload"
66
+ }
67
+ ],
68
+ "repeat": "",
69
+ "crontab": "",
70
+ "once": false,
71
+ "onceDelay": 0.1,
72
+ "topic": "",
73
+ "payload": "{\"rtp\":0.6}",
74
+ "payloadType": "json",
75
+ "z": "tab-drv2605-demo",
76
+ "x": 150,
77
+ "y": 200,
78
+ "wires": [
79
+ [
80
+ "drv",
81
+ "fn-stop"
82
+ ]
83
+ ]
84
+ },
85
+ {
86
+ "id": "fn-stop",
87
+ "type": "function",
88
+ "name": "stop after 1 s",
89
+ "func": "setTimeout(function() {\n node.send({ payload: { stop: true } });\n}, 1000);\nreturn null;",
90
+ "outputs": 1,
91
+ "noerr": 0,
92
+ "initialize": "",
93
+ "finalize": "",
94
+ "libs": [],
95
+ "z": "tab-drv2605-demo",
96
+ "x": 400,
97
+ "y": 240,
98
+ "wires": [
99
+ [
100
+ "drv"
101
+ ]
102
+ ]
103
+ },
104
+ {
105
+ "id": "inj-status",
106
+ "type": "inject",
107
+ "name": "Read status",
108
+ "props": [
109
+ {
110
+ "p": "payload"
111
+ }
112
+ ],
113
+ "repeat": "",
114
+ "crontab": "",
115
+ "once": false,
116
+ "onceDelay": 0.1,
117
+ "topic": "",
118
+ "payload": "{\"status\":true}",
119
+ "payloadType": "json",
120
+ "z": "tab-drv2605-demo",
121
+ "x": 150,
122
+ "y": 280,
123
+ "wires": [
124
+ [
125
+ "drv"
126
+ ]
127
+ ]
128
+ },
129
+ {
130
+ "id": "drv",
131
+ "type": "periph-drv2605",
132
+ "name": "",
133
+ "bus": "1",
134
+ "actuator": "erm",
135
+ "library": "A",
136
+ "z": "tab-drv2605-demo",
137
+ "x": 640,
138
+ "y": 140,
139
+ "wires": [
140
+ [
141
+ "dbg"
142
+ ]
143
+ ]
144
+ },
145
+ {
146
+ "id": "dbg",
147
+ "type": "debug",
148
+ "name": "reply",
149
+ "active": true,
150
+ "tosidebar": true,
151
+ "console": false,
152
+ "tostatus": false,
153
+ "complete": "payload",
154
+ "targetType": "msg",
155
+ "statusVal": "",
156
+ "statusType": "auto",
157
+ "z": "tab-drv2605-demo",
158
+ "x": 850,
159
+ "y": 140,
160
+ "wires": []
161
+ }
162
+ ]
@@ -0,0 +1,79 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-drv2605', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ actuator: { value: 'erm', required: true },
9
+ library: { value: 'A', required: true }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'font-awesome/fa-cog',
14
+ label: function() { return this.name || 'DRV2605'; },
15
+ paletteLabel: 'DRV2605'
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="periph-drv2605">
20
+ <div class="form-row">
21
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-input-name" placeholder="DRV2605">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-input-actuator"><i class="fa fa-bolt"></i> Actuator</label>
30
+ <select id="node-input-actuator" style="width:120px">
31
+ <option value="erm">ERM</option>
32
+ <option value="lra">LRA</option>
33
+ </select>
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-input-library"><i class="fa fa-book"></i> Library</label>
37
+ <select id="node-input-library" style="width:120px">
38
+ <option value="A">A (ERM)</option>
39
+ <option value="B">B (ERM)</option>
40
+ <option value="C">C (ERM)</option>
41
+ <option value="D">D (ERM)</option>
42
+ <option value="E">E (ERM)</option>
43
+ <option value="LRA">LRA</option>
44
+ </select>
45
+ </div>
46
+ </script>
47
+
48
+ <script type="text/html" data-help-name="periph-drv2605">
49
+ <p>Plays haptic effects on an ERM or LRA vibration motor through a DRV2605 haptic driver over I²C (fixed address 0x5A). The EN pin must be high.</p>
50
+
51
+ <h3>Inputs</h3>
52
+ <dl class="message-properties">
53
+ <dt>payload.effect <span class="property-type">number</span></dt>
54
+ <dd>Plays one ROM effect (1–123). A bare number <code>msg.payload</code> does the same.</dd>
55
+ <dt>payload.sequence <span class="property-type">array</span></dt>
56
+ <dd>Plays up to 8 steps: a number is a ROM effect, <code>["wait", ms]</code> is a delay of 0–1270 ms (10 ms steps), e.g. <code>[1, ["wait", 100], 10]</code>.</dd>
57
+ <dt>payload.rtp <span class="property-type">number</span></dt>
58
+ <dd>Real-time amplitude 0.0–1.0; stays on until stopped.</dd>
59
+ <dt>payload.stop <span class="property-type">boolean</span></dt>
60
+ <dd><code>true</code> stops playback (also leaves real-time playback).</dd>
61
+ <dt>payload.status <span class="property-type">boolean</span></dt>
62
+ <dd><code>true</code> reads the chip status. Note this clears the latched diagnostic and over-temperature flags.</dd>
63
+ </dl>
64
+
65
+ <h3>Outputs</h3>
66
+ <dl class="message-properties">
67
+ <dt>payload.ok <span class="property-type">boolean</span></dt>
68
+ <dd><code>true</code> after an effect, sequence, rtp or stop command.</dd>
69
+ <dt>payload.device_id <span class="property-type">number</span></dt>
70
+ <dd>DEVICE_ID (3 for the DRV2605) — status replies only.</dd>
71
+ <dt>payload.over_temp / over_current <span class="property-type">boolean</span></dt>
72
+ <dd>Latched overtemperature / overcurrent flags — status replies only.</dd>
73
+ <dt>payload.supply_voltage <span class="property-type">number</span></dt>
74
+ <dd>Supply voltage in V; only valid while an effect is playing — status replies only.</dd>
75
+ </dl>
76
+
77
+ <h3>Configuration</h3>
78
+ <p>Set the Linux I²C bus number, the actuator type (ERM or LRA) and the ROM library (A–E for an ERM, LRA for an LRA). The I²C address is fixed at 0x5A. Playback is stopped when the node is closed.</p>
79
+ </script>
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { DRV2605Full } = require('periph/src/chips/motor/drv2605');
6
+
7
+ const LIBRARIES = { A: 1, B: 2, C: 3, D: 4, E: 5, LRA: 6 };
8
+
9
+ function DRV2605Node(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+
13
+ try {
14
+ const lra = config.actuator === 'lra';
15
+ const connection = new I2CConnection(parseInt(config.bus, 10), DRV2605Full.I2C_ADDRESS);
16
+ node.driver = new DRV2605Full(connection, lra);
17
+ node.connection = connection;
18
+ node.ready = node.driver.init()
19
+ .then(() => node.driver.setLibrary(LIBRARIES[config.library] || (lra ? 6 : 1)))
20
+ .catch((e) => { node.driver = null; node.error('DRV2605 init failed: ' + e.message); });
21
+ } catch (e) {
22
+ node.error('DRV2605 init failed: ' + e.message);
23
+ }
24
+
25
+ node.on('input', async function(msg, send, done) {
26
+ await node.ready;
27
+ if (!node.driver) { done(); return; }
28
+ try {
29
+ const p = msg.payload;
30
+ if (typeof p === 'number') {
31
+ await node.driver.playEffect(p);
32
+ msg.payload = { ok: true };
33
+ } else if (p && typeof p === 'object') {
34
+ if (typeof p.effect === 'number') {
35
+ await node.driver.playEffect(p.effect);
36
+ msg.payload = { ok: true };
37
+ } else if (Array.isArray(p.sequence)) {
38
+ await node.driver.playSequence(p.sequence);
39
+ msg.payload = { ok: true };
40
+ } else if (typeof p.rtp === 'number') {
41
+ await node.driver.rtpLevel(p.rtp);
42
+ msg.payload = { ok: true };
43
+ } else if (p.stop === true) {
44
+ await node.driver.stop();
45
+ msg.payload = { ok: true };
46
+ } else if (p.status === true) {
47
+ const device_id = await node.driver.readDeviceId();
48
+ const st = await node.driver.readStatus();
49
+ const supply_voltage = await node.driver.readSupplyVoltage();
50
+ msg.payload = { device_id, over_temp: st.overTemp, over_current: st.overCurrent, supply_voltage };
51
+ } else {
52
+ done(); return;
53
+ }
54
+ send(msg);
55
+ done();
56
+ return;
57
+ } else {
58
+ done(); return;
59
+ }
60
+ send(msg);
61
+ done();
62
+ } catch (e) {
63
+ done(e);
64
+ }
65
+ });
66
+
67
+ node.on('close', async function(removed, done) {
68
+ try {
69
+ if (node.driver) await node.driver.stop();
70
+ if (node.connection) await node.connection.close();
71
+ } catch (e) {
72
+ // bus may already be gone; nothing more to do on close
73
+ } finally {
74
+ done();
75
+ }
76
+ });
77
+ }
78
+ RED.nodes.registerType('periph-drv2605', DRV2605Node);
79
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-motor",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Node-RED nodes for motor driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
+ "drv2605": "nodes/drv2605/drv2605.js",
15
16
  "drv8830": "nodes/drv8830/drv8830.js"
16
17
  }
17
18
  },