node-red-contrib-periph-motor 1.5.1 → 1.5.2
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 +12 -6
- package/examples/drv2605/demo.json +12 -6
- package/examples/drv8830/demo.json +11 -5
- package/examples/tmc2130/demo.json +44 -15
- package/examples/tmc2208/demo.json +13 -7
- package/examples/tmc2209/demo.json +13 -7
- package/examples/tmc5160/demo.json +146 -24
- package/nodes/drv2605/drv2605.html +44 -18
- package/nodes/drv2605/drv2605.js +30 -24
- package/nodes/drv8830/drv8830.html +42 -16
- package/nodes/drv8830/drv8830.js +26 -20
- package/nodes/tmc2130/tmc2130.html +58 -32
- package/nodes/tmc2130/tmc2130.js +30 -23
- package/nodes/tmc2208/tmc2208.html +50 -24
- package/nodes/tmc2208/tmc2208.js +33 -26
- package/nodes/tmc2209/tmc2209.html +54 -28
- package/nodes/tmc2209/tmc2209.js +35 -28
- package/nodes/tmc5160/tmc5160.html +47 -21
- package/nodes/tmc5160/tmc5160.js +35 -28
- package/package.json +1 -1
- package/index.js +0 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('tmc2209-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
port: { value: '/dev/ttyS0', required: true },
|
|
@@ -13,58 +13,84 @@
|
|
|
13
13
|
enGpio: { value: '' },
|
|
14
14
|
diagGpio: { value: '' }
|
|
15
15
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
label: function() { return this.name || 'TMC2209'; },
|
|
20
|
-
paletteLabel: 'TMC2209'
|
|
16
|
+
label: function() {
|
|
17
|
+
return this.name || 'TMC2209';
|
|
18
|
+
}
|
|
21
19
|
});
|
|
22
20
|
</script>
|
|
23
21
|
|
|
24
|
-
<script type="text/html" data-template-name="
|
|
22
|
+
<script type="text/html" data-template-name="tmc2209-device">
|
|
25
23
|
<div class="form-row">
|
|
26
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
27
|
-
<input type="text" id="node-input-name" placeholder="TMC2209">
|
|
24
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
25
|
+
<input type="text" id="node-config-input-name" placeholder="TMC2209">
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
|
-
<label for="node-input-port"><i class="fa fa-plug"></i> Serial port</label>
|
|
31
|
-
<input type="text" id="node-input-port" placeholder="/dev/ttyS0">
|
|
28
|
+
<label for="node-config-input-port"><i class="fa fa-plug"></i> Serial port</label>
|
|
29
|
+
<input type="text" id="node-config-input-port" placeholder="/dev/ttyS0">
|
|
32
30
|
</div>
|
|
33
31
|
<div class="form-row">
|
|
34
|
-
<label for="node-input-baudrate"><i class="fa fa-tachometer"></i> Baud rate</label>
|
|
35
|
-
<input type="number" id="node-input-baudrate" min="9000" style="width:100px">
|
|
32
|
+
<label for="node-config-input-baudrate"><i class="fa fa-tachometer"></i> Baud rate</label>
|
|
33
|
+
<input type="number" id="node-config-input-baudrate" min="9000" style="width:100px">
|
|
36
34
|
</div>
|
|
37
35
|
<div class="form-row">
|
|
38
|
-
<label for="node-input-address"><i class="fa fa-hashtag"></i> Node address (0–3)</label>
|
|
39
|
-
<input type="number" id="node-input-address" min="0" max="3" style="width:100px">
|
|
36
|
+
<label for="node-config-input-address"><i class="fa fa-hashtag"></i> Node address (0–3)</label>
|
|
37
|
+
<input type="number" id="node-config-input-address" min="0" max="3" style="width:100px">
|
|
40
38
|
</div>
|
|
41
39
|
<div class="form-row">
|
|
42
|
-
<label for="node-input-rsense"><i class="fa fa-bolt"></i> Sense resistor (Ω)</label>
|
|
43
|
-
<input type="number" id="node-input-rsense" min="0.01" step="0.01" style="width:100px">
|
|
40
|
+
<label for="node-config-input-rsense"><i class="fa fa-bolt"></i> Sense resistor (Ω)</label>
|
|
41
|
+
<input type="number" id="node-config-input-rsense" min="0.01" step="0.01" style="width:100px">
|
|
44
42
|
</div>
|
|
45
43
|
<div class="form-row">
|
|
46
|
-
<label for="node-input-current"><i class="fa fa-bolt"></i> Default current (A RMS)</label>
|
|
47
|
-
<input type="number" id="node-input-current" min="0" max="1.4" step="0.05" style="width:100px">
|
|
44
|
+
<label for="node-config-input-current"><i class="fa fa-bolt"></i> Default current (A RMS)</label>
|
|
45
|
+
<input type="number" id="node-config-input-current" min="0" max="1.4" step="0.05" style="width:100px">
|
|
48
46
|
</div>
|
|
49
47
|
<div class="form-row">
|
|
50
|
-
<label for="node-input-microsteps"><i class="fa fa-th"></i> Default microsteps</label>
|
|
51
|
-
<select id="node-input-microsteps" style="width:100px">
|
|
48
|
+
<label for="node-config-input-microsteps"><i class="fa fa-th"></i> Default microsteps</label>
|
|
49
|
+
<select id="node-config-input-microsteps" style="width:100px">
|
|
52
50
|
<option value="1">1</option><option value="2">2</option><option value="4">4</option>
|
|
53
51
|
<option value="8">8</option><option value="16">16</option><option value="32">32</option>
|
|
54
52
|
<option value="64">64</option><option value="128">128</option><option value="256">256</option>
|
|
55
53
|
</select>
|
|
56
54
|
</div>
|
|
57
55
|
<div class="form-row">
|
|
58
|
-
<label for="node-input-enGpio"><i class="fa fa-microchip"></i> ENN GPIO (optional)</label>
|
|
59
|
-
<input type="text" id="node-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px">
|
|
56
|
+
<label for="node-config-input-enGpio"><i class="fa fa-microchip"></i> ENN GPIO (optional)</label>
|
|
57
|
+
<input type="text" id="node-config-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px">
|
|
58
|
+
</div>
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-config-input-diagGpio"><i class="fa fa-microchip"></i> DIAG GPIO (optional)</label>
|
|
61
|
+
<input type="text" id="node-config-input-diagGpio" placeholder="not wired, e.g. 0:27" style="width:140px">
|
|
62
|
+
</div>
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<!-- Read node -->
|
|
66
|
+
<script type="text/javascript">
|
|
67
|
+
RED.nodes.registerType('tmc2209', {
|
|
68
|
+
category: 'Peripheral',
|
|
69
|
+
color: '#C084FC',
|
|
70
|
+
defaults: {
|
|
71
|
+
name: { value: '' },
|
|
72
|
+
device: { value: '', type: 'tmc2209-device', required: true }
|
|
73
|
+
},
|
|
74
|
+
inputs: 1,
|
|
75
|
+
outputs: 1,
|
|
76
|
+
icon: 'font-awesome/fa-cog',
|
|
77
|
+
label: function() { return this.name || 'TMC2209'; },
|
|
78
|
+
paletteLabel: 'TMC2209'
|
|
79
|
+
});
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<script type="text/html" data-template-name="tmc2209">
|
|
83
|
+
<div class="form-row">
|
|
84
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
85
|
+
<input type="text" id="node-input-name" placeholder="TMC2209">
|
|
60
86
|
</div>
|
|
61
87
|
<div class="form-row">
|
|
62
|
-
<label for="node-input-
|
|
63
|
-
<input type="text" id="node-input-
|
|
88
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
89
|
+
<input type="text" id="node-input-device">
|
|
64
90
|
</div>
|
|
65
91
|
</script>
|
|
66
92
|
|
|
67
|
-
<script type="text/html" data-help-name="
|
|
93
|
+
<script type="text/html" data-help-name="tmc2209">
|
|
68
94
|
<p>Drives a two-phase bipolar stepper motor through a Trinamic TMC2209 over its single-wire UART. The chip's internal step generator moves the motor, so no STEP pulses are needed.</p>
|
|
69
95
|
|
|
70
96
|
<h3>Inputs</h3>
|
package/nodes/tmc2209/tmc2209.js
CHANGED
|
@@ -4,7 +4,7 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { UARTConnection } = require('periph/src/connection/uart');
|
|
5
5
|
const { TMC2209Full } = require('periph/src/chips/motor/tmc2209');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function TMC2209DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
node.ready = false;
|
|
@@ -63,35 +63,56 @@ module.exports = function(RED) {
|
|
|
63
63
|
}, extra);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
node.on('close', async function(removed, done) {
|
|
67
|
+
try {
|
|
68
|
+
if (node.driver && node.ready) {
|
|
69
|
+
await node.driver.stop();
|
|
70
|
+
await node.driver.disable();
|
|
71
|
+
}
|
|
72
|
+
if (node.connection) await node.connection.close();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
// port may already be gone; nothing more to do on close
|
|
75
|
+
} finally {
|
|
76
|
+
done();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
RED.nodes.registerType('tmc2209-device', TMC2209DeviceNode);
|
|
81
|
+
|
|
82
|
+
function TMC2209ReadNode(config) {
|
|
83
|
+
RED.nodes.createNode(this, config);
|
|
84
|
+
const node = this;
|
|
85
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
86
|
+
|
|
66
87
|
node.on('input', async function(msg, send, done) {
|
|
67
|
-
if (!
|
|
88
|
+
if (!deviceNode.driver || !deviceNode.ready) { done(); return; }
|
|
68
89
|
try {
|
|
69
90
|
const p = msg.payload;
|
|
70
91
|
let handled = false;
|
|
71
92
|
let extra = {};
|
|
72
93
|
if (p && typeof p === 'object') {
|
|
73
|
-
if (typeof p.microsteps === 'number') { await
|
|
74
|
-
if (typeof p.current === 'number') { await
|
|
94
|
+
if (typeof p.microsteps === 'number') { await deviceNode.driver.setMicrosteps(p.microsteps); handled = true; }
|
|
95
|
+
if (typeof p.current === 'number') { await deviceNode.driver.setCurrent(p.current); handled = true; }
|
|
75
96
|
if (typeof p.enable === 'boolean') {
|
|
76
|
-
if (p.enable) await
|
|
97
|
+
if (p.enable) await deviceNode.driver.enable(); else await deviceNode.driver.disable();
|
|
77
98
|
handled = true;
|
|
78
99
|
}
|
|
79
|
-
if (typeof p.stall_threshold === 'number') { await
|
|
80
|
-
if (p.stop === true) { await
|
|
81
|
-
if (typeof p.speed === 'number') { await
|
|
100
|
+
if (typeof p.stall_threshold === 'number') { await deviceNode.driver.setStallThreshold(p.stall_threshold); handled = true; }
|
|
101
|
+
if (p.stop === true) { await deviceNode.driver.stop(); extra.speed = 0; handled = true; }
|
|
102
|
+
if (typeof p.speed === 'number') { await deviceNode.driver.run(p.speed); extra.speed = p.speed; handled = true; }
|
|
82
103
|
}
|
|
83
104
|
if (handled) {
|
|
84
105
|
msg.payload = await snapshot(extra);
|
|
85
106
|
} else {
|
|
86
|
-
const status = await
|
|
107
|
+
const status = await deviceNode.driver.readStatus();
|
|
87
108
|
msg.payload = {
|
|
88
109
|
standstill: status.stst,
|
|
89
110
|
stealth: status.stealth,
|
|
90
|
-
fault: await
|
|
111
|
+
fault: await deviceNode.driver.readFault(),
|
|
91
112
|
cs_actual: status.cs_actual,
|
|
92
|
-
sg_result: await
|
|
93
|
-
tstep: await
|
|
94
|
-
temperature_flags: await
|
|
113
|
+
sg_result: await deviceNode.driver.readStallguard(),
|
|
114
|
+
tstep: await deviceNode.driver.readTstep(),
|
|
115
|
+
temperature_flags: await deviceNode.driver.readTemperatureFlags(),
|
|
95
116
|
};
|
|
96
117
|
}
|
|
97
118
|
send(msg);
|
|
@@ -100,20 +121,6 @@ module.exports = function(RED) {
|
|
|
100
121
|
done(e);
|
|
101
122
|
}
|
|
102
123
|
});
|
|
103
|
-
|
|
104
|
-
node.on('close', async function(removed, done) {
|
|
105
|
-
try {
|
|
106
|
-
if (node.driver && node.ready) {
|
|
107
|
-
await node.driver.stop();
|
|
108
|
-
await node.driver.disable();
|
|
109
|
-
}
|
|
110
|
-
if (node.connection) await node.connection.close();
|
|
111
|
-
} catch (e) {
|
|
112
|
-
// port may already be gone; nothing more to do on close
|
|
113
|
-
} finally {
|
|
114
|
-
done();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
124
|
}
|
|
118
|
-
RED.nodes.registerType('
|
|
125
|
+
RED.nodes.registerType('tmc2209', TMC2209ReadNode);
|
|
119
126
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('tmc5160-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: 'spi', required: true },
|
|
@@ -20,6 +20,46 @@
|
|
|
20
20
|
speed: { value: '200', validate: RED.validators.number() },
|
|
21
21
|
acceleration: { value: '400', validate: RED.validators.number() }
|
|
22
22
|
},
|
|
23
|
+
label: function() {
|
|
24
|
+
return this.name || ('TMC5160 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script type="text/html" data-template-name="tmc5160-device">
|
|
30
|
+
<div class="form-row">
|
|
31
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
32
|
+
<input type="text" id="node-config-input-name" placeholder="TMC5160">
|
|
33
|
+
</div>
|
|
34
|
+
<div class="form-row">
|
|
35
|
+
<label for="node-config-input-bus"><i class="fa fa-plug"></i> Bus</label>
|
|
36
|
+
<select id="node-config-input-bus" style="width:100px"><option value="spi">SPI</option><option value="uart">UART</option></select>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="form-row"><label for="node-config-input-spiBus">SPI bus</label><input type="number" id="node-config-input-spiBus" min="0" style="width:100px"></div>
|
|
39
|
+
<div class="form-row"><label for="node-config-input-spiDevice">SPI device (CS)</label><input type="number" id="node-config-input-spiDevice" min="0" style="width:100px"></div>
|
|
40
|
+
<div class="form-row"><label for="node-config-input-port">Serial port</label><input type="text" id="node-config-input-port" placeholder="/dev/ttyS0"></div>
|
|
41
|
+
<div class="form-row"><label for="node-config-input-baudrate">Baud rate</label><input type="number" id="node-config-input-baudrate" min="9000" style="width:100px"></div>
|
|
42
|
+
<div class="form-row"><label for="node-config-input-address">Node address</label><input type="number" id="node-config-input-address" min="0" max="253" style="width:100px"></div>
|
|
43
|
+
<div class="form-row"><label for="node-config-input-echo">UART echo</label><input type="checkbox" id="node-config-input-echo" style="width:auto"></div>
|
|
44
|
+
<div class="form-row"><label for="node-config-input-enGpio">DRV_ENN GPIO (optional)</label><input type="text" id="node-config-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px"></div>
|
|
45
|
+
<div class="form-row"><label for="node-config-input-diag0Gpio">DIAG0 GPIO (SPI, optional)</label><input type="text" id="node-config-input-diag0Gpio" placeholder="e.g. 0:23" style="width:140px"></div>
|
|
46
|
+
<div class="form-row"><label for="node-config-input-diag1Gpio">DIAG1 GPIO (SPI, optional)</label><input type="text" id="node-config-input-diag1Gpio" placeholder="e.g. 0:24" style="width:140px"></div>
|
|
47
|
+
<div class="form-row"><label for="node-config-input-rsense">Sense resistor (Ω)</label><input type="number" id="node-config-input-rsense" min="0.01" step="0.005" style="width:100px"></div>
|
|
48
|
+
<div class="form-row"><label for="node-config-input-fclk">Chip clock (Hz)</label><input type="number" id="node-config-input-fclk" min="4000000" style="width:120px"></div>
|
|
49
|
+
<div class="form-row"><label for="node-config-input-current">Default current (A RMS)</label><input type="number" id="node-config-input-current" min="0" step="0.1" style="width:100px"></div>
|
|
50
|
+
<div class="form-row"><label for="node-config-input-speed">Default speed (full steps/s)</label><input type="number" id="node-config-input-speed" min="1" style="width:100px"></div>
|
|
51
|
+
<div class="form-row"><label for="node-config-input-acceleration">Default acceleration (full steps/s²)</label><input type="number" id="node-config-input-acceleration" min="1" style="width:100px"></div>
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<!-- Read node -->
|
|
55
|
+
<script type="text/javascript">
|
|
56
|
+
RED.nodes.registerType('tmc5160', {
|
|
57
|
+
category: 'Peripheral',
|
|
58
|
+
color: '#C084FC',
|
|
59
|
+
defaults: {
|
|
60
|
+
name: { value: '' },
|
|
61
|
+
device: { value: '', type: 'tmc5160-device', required: true }
|
|
62
|
+
},
|
|
23
63
|
inputs: 1,
|
|
24
64
|
outputs: 1,
|
|
25
65
|
icon: 'font-awesome/fa-cog',
|
|
@@ -28,32 +68,18 @@
|
|
|
28
68
|
});
|
|
29
69
|
</script>
|
|
30
70
|
|
|
31
|
-
<script type="text/html" data-template-name="
|
|
71
|
+
<script type="text/html" data-template-name="tmc5160">
|
|
32
72
|
<div class="form-row">
|
|
33
73
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
34
74
|
<input type="text" id="node-input-name" placeholder="TMC5160">
|
|
35
75
|
</div>
|
|
36
76
|
<div class="form-row">
|
|
37
|
-
<label for="node-input-
|
|
38
|
-
<
|
|
77
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
78
|
+
<input type="text" id="node-input-device">
|
|
39
79
|
</div>
|
|
40
|
-
<div class="form-row"><label for="node-input-spiBus">SPI bus</label><input type="number" id="node-input-spiBus" min="0" style="width:100px"></div>
|
|
41
|
-
<div class="form-row"><label for="node-input-spiDevice">SPI device (CS)</label><input type="number" id="node-input-spiDevice" min="0" style="width:100px"></div>
|
|
42
|
-
<div class="form-row"><label for="node-input-port">Serial port</label><input type="text" id="node-input-port" placeholder="/dev/ttyS0"></div>
|
|
43
|
-
<div class="form-row"><label for="node-input-baudrate">Baud rate</label><input type="number" id="node-input-baudrate" min="9000" style="width:100px"></div>
|
|
44
|
-
<div class="form-row"><label for="node-input-address">Node address</label><input type="number" id="node-input-address" min="0" max="253" style="width:100px"></div>
|
|
45
|
-
<div class="form-row"><label for="node-input-echo">UART echo</label><input type="checkbox" id="node-input-echo" style="width:auto"></div>
|
|
46
|
-
<div class="form-row"><label for="node-input-enGpio">DRV_ENN GPIO (optional)</label><input type="text" id="node-input-enGpio" placeholder="not wired, e.g. 0:17" style="width:140px"></div>
|
|
47
|
-
<div class="form-row"><label for="node-input-diag0Gpio">DIAG0 GPIO (SPI, optional)</label><input type="text" id="node-input-diag0Gpio" placeholder="e.g. 0:23" style="width:140px"></div>
|
|
48
|
-
<div class="form-row"><label for="node-input-diag1Gpio">DIAG1 GPIO (SPI, optional)</label><input type="text" id="node-input-diag1Gpio" placeholder="e.g. 0:24" style="width:140px"></div>
|
|
49
|
-
<div class="form-row"><label for="node-input-rsense">Sense resistor (Ω)</label><input type="number" id="node-input-rsense" min="0.01" step="0.005" style="width:100px"></div>
|
|
50
|
-
<div class="form-row"><label for="node-input-fclk">Chip clock (Hz)</label><input type="number" id="node-input-fclk" min="4000000" style="width:120px"></div>
|
|
51
|
-
<div class="form-row"><label for="node-input-current">Default current (A RMS)</label><input type="number" id="node-input-current" min="0" step="0.1" style="width:100px"></div>
|
|
52
|
-
<div class="form-row"><label for="node-input-speed">Default speed (full steps/s)</label><input type="number" id="node-input-speed" min="1" style="width:100px"></div>
|
|
53
|
-
<div class="form-row"><label for="node-input-acceleration">Default acceleration (full steps/s²)</label><input type="number" id="node-input-acceleration" min="1" style="width:100px"></div>
|
|
54
80
|
</script>
|
|
55
81
|
|
|
56
|
-
<script type="text/html" data-help-name="
|
|
82
|
+
<script type="text/html" data-help-name="tmc5160">
|
|
57
83
|
<p>Drives a two-phase bipolar stepper motor through a Trinamic TMC5160 over SPI (Mode 3) or single-wire UART. The chip's internal SixPoint ramp generator moves the motor; positions are in full steps, speeds in full steps/s and accelerations in full steps/s².</p>
|
|
58
84
|
|
|
59
85
|
<h3>Inputs</h3>
|
package/nodes/tmc5160/tmc5160.js
CHANGED
|
@@ -18,7 +18,7 @@ module.exports = function(RED) {
|
|
|
18
18
|
return new GpioOutputPin(Default.output({ chip, line }));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
21
|
+
function TMC5160DeviceNode(config) {
|
|
22
22
|
RED.nodes.createNode(this, config);
|
|
23
23
|
const node = this;
|
|
24
24
|
node.ready = false;
|
|
@@ -74,28 +74,49 @@ module.exports = function(RED) {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
node.on('close', async function(removed, done) {
|
|
78
|
+
try {
|
|
79
|
+
if (node.driver && node.ready) {
|
|
80
|
+
await node.driver.stop();
|
|
81
|
+
await node.driver.disable();
|
|
82
|
+
}
|
|
83
|
+
if (node.connection) await node.connection.close();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// bus may already be gone; nothing more to do on close
|
|
86
|
+
} finally {
|
|
87
|
+
done();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
RED.nodes.registerType('tmc5160-device', TMC5160DeviceNode);
|
|
92
|
+
|
|
93
|
+
function TMC5160ReadNode(config) {
|
|
94
|
+
RED.nodes.createNode(this, config);
|
|
95
|
+
const node = this;
|
|
96
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
97
|
+
|
|
77
98
|
node.on('input', async function(msg, send, done) {
|
|
78
|
-
if (!
|
|
99
|
+
if (!deviceNode.driver || !deviceNode.ready) { done(); return; }
|
|
79
100
|
try {
|
|
80
101
|
const p = msg.payload;
|
|
81
102
|
let handled = false;
|
|
82
103
|
if (p && typeof p === 'object') {
|
|
83
|
-
if (typeof p.current === 'number') { await
|
|
84
|
-
if (typeof p.acceleration === 'number') { await
|
|
85
|
-
if (typeof p.stall_threshold === 'number') { await
|
|
86
|
-
if (p.zero === true) { await
|
|
104
|
+
if (typeof p.current === 'number') { await deviceNode.driver.setCurrent(p.current); handled = true; }
|
|
105
|
+
if (typeof p.acceleration === 'number') { await deviceNode.driver.setAcceleration(p.acceleration); handled = true; }
|
|
106
|
+
if (typeof p.stall_threshold === 'number') { await deviceNode.driver.setStallThreshold(p.stall_threshold); handled = true; }
|
|
107
|
+
if (p.zero === true) { await deviceNode.driver.setPosition(0); handled = true; }
|
|
87
108
|
if (typeof p.enable === 'boolean') {
|
|
88
|
-
if (p.enable) await
|
|
109
|
+
if (p.enable) await deviceNode.driver.enable(); else await deviceNode.driver.disable();
|
|
89
110
|
handled = true;
|
|
90
111
|
}
|
|
91
112
|
if (typeof p.speed === 'number' && typeof p.move !== 'number') {
|
|
92
|
-
if (p.speed === 0) await
|
|
113
|
+
if (p.speed === 0) await deviceNode.driver.stop(); else await deviceNode.driver.run(p.speed);
|
|
93
114
|
handled = true;
|
|
94
115
|
}
|
|
95
|
-
if (p.stop === true) { await
|
|
96
|
-
if (typeof p.move_to === 'number') { await
|
|
116
|
+
if (p.stop === true) { await deviceNode.driver.stop(); handled = true; }
|
|
117
|
+
if (typeof p.move_to === 'number') { await deviceNode.driver.moveTo(p.move_to); handled = true; }
|
|
97
118
|
if (typeof p.move === 'number') {
|
|
98
|
-
await
|
|
119
|
+
await deviceNode.driver.move(p.move, typeof p.speed === 'number' ? p.speed : deviceNode.speed);
|
|
99
120
|
handled = true;
|
|
100
121
|
}
|
|
101
122
|
}
|
|
@@ -103,9 +124,9 @@ module.exports = function(RED) {
|
|
|
103
124
|
msg.payload = await snapshot();
|
|
104
125
|
} else {
|
|
105
126
|
const snap = await snapshot();
|
|
106
|
-
const status = await
|
|
127
|
+
const status = await deviceNode.driver.readStatus();
|
|
107
128
|
msg.payload = Object.assign(snap, {
|
|
108
|
-
tstep: await
|
|
129
|
+
tstep: await deviceNode.driver.readTstep(),
|
|
109
130
|
stallguard: status.stallguard,
|
|
110
131
|
otpw: status.otpw,
|
|
111
132
|
ot: status.ot,
|
|
@@ -117,20 +138,6 @@ module.exports = function(RED) {
|
|
|
117
138
|
done(e);
|
|
118
139
|
}
|
|
119
140
|
});
|
|
120
|
-
|
|
121
|
-
node.on('close', async function(removed, done) {
|
|
122
|
-
try {
|
|
123
|
-
if (node.driver && node.ready) {
|
|
124
|
-
await node.driver.stop();
|
|
125
|
-
await node.driver.disable();
|
|
126
|
-
}
|
|
127
|
-
if (node.connection) await node.connection.close();
|
|
128
|
-
} catch (e) {
|
|
129
|
-
// bus may already be gone; nothing more to do on close
|
|
130
|
-
} finally {
|
|
131
|
-
done();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
141
|
}
|
|
135
|
-
RED.nodes.registerType('
|
|
142
|
+
RED.nodes.registerType('tmc5160', TMC5160ReadNode);
|
|
136
143
|
};
|
package/package.json
CHANGED
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
module.exports = function(RED) {
|
|
5
|
-
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
-
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
-
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
-
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
-
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
-
});
|
|
11
|
-
};
|