node-red-contrib-periph-adc-dac 1.3.2 → 1.4.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.
- package/README.md +12 -0
- package/examples/ad5243/demo.json +116 -0
- package/examples/ad5248/demo.json +125 -0
- package/examples/ads1013/demo.json +76 -0
- package/examples/ads1014/demo.json +77 -0
- package/examples/ads1113/demo.json +60 -0
- package/examples/ads1114/demo.json +61 -0
- package/examples/ads1115/demo.json +119 -0
- package/examples/es8311/demo.json +173 -0
- package/examples/mcp4xxx/demo.json +206 -0
- package/nodes/ad5243/ad5243.html +74 -0
- package/nodes/ad5243/ad5243.js +62 -0
- package/nodes/ad5248/ad5248.html +108 -0
- package/nodes/ad5248/ad5248.js +64 -0
- package/nodes/ads1013/ads1013.html +70 -0
- package/nodes/ads1013/ads1013.js +48 -0
- package/nodes/ads1014/ads1014.html +82 -0
- package/nodes/ads1014/ads1014.js +49 -0
- package/nodes/ads1113/ads1113.html +66 -0
- package/nodes/ads1113/ads1113.js +38 -0
- package/nodes/ads1114/ads1114.html +78 -0
- package/nodes/ads1114/ads1114.js +39 -0
- package/nodes/ads1115/ads1115.html +91 -0
- package/nodes/ads1115/ads1115.js +48 -0
- package/nodes/es8311/es8311.html +111 -0
- package/nodes/es8311/es8311.js +57 -0
- package/nodes/mcp4xxx/mcp4xxx.html +167 -0
- package/nodes/mcp4xxx/mcp4xxx.js +96 -0
- package/package.json +14 -5
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-es8311-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "ES8311 Volume Control",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Runtime volume control of an ES8311 audio codec whose I2S stream is produced elsewhere. An Inject node sets -40 dB on deploy; a second Inject node fires every 10 s and a Function node alternates the volume between -20 dB and -60 dB. The Debug node prints the value read back from the chip, which shows the 0.5 dB quantisation. Adjust MCLK and sample rate in the device config node to match the I2S source."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-es8311",
|
|
11
|
+
"type": "es8311-device",
|
|
12
|
+
"name": "ES8311",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "18",
|
|
15
|
+
"mclk": "12288000",
|
|
16
|
+
"sampleRate": "48000",
|
|
17
|
+
"volume": "-60",
|
|
18
|
+
"micGain": "24"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "inj-start",
|
|
22
|
+
"type": "inject",
|
|
23
|
+
"name": "-40 dB on deploy",
|
|
24
|
+
"props": [
|
|
25
|
+
{
|
|
26
|
+
"p": "payload"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"repeat": "",
|
|
30
|
+
"crontab": "",
|
|
31
|
+
"once": true,
|
|
32
|
+
"onceDelay": 1,
|
|
33
|
+
"topic": "",
|
|
34
|
+
"payload": "{\"volume\":-40,\"mute\":false}",
|
|
35
|
+
"payloadType": "json",
|
|
36
|
+
"z": "tab-es8311-demo",
|
|
37
|
+
"x": 150,
|
|
38
|
+
"y": 100,
|
|
39
|
+
"wires": [
|
|
40
|
+
[
|
|
41
|
+
"es8311"
|
|
42
|
+
]
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "inj-tick",
|
|
47
|
+
"type": "inject",
|
|
48
|
+
"name": "every 10 s",
|
|
49
|
+
"props": [
|
|
50
|
+
{
|
|
51
|
+
"p": "payload"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"repeat": "10",
|
|
55
|
+
"crontab": "",
|
|
56
|
+
"once": false,
|
|
57
|
+
"onceDelay": 0.1,
|
|
58
|
+
"topic": "",
|
|
59
|
+
"payload": "",
|
|
60
|
+
"payloadType": "date",
|
|
61
|
+
"z": "tab-es8311-demo",
|
|
62
|
+
"x": 130,
|
|
63
|
+
"y": 180,
|
|
64
|
+
"wires": [
|
|
65
|
+
[
|
|
66
|
+
"fn-alternate"
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"id": "fn-alternate",
|
|
72
|
+
"type": "function",
|
|
73
|
+
"name": "alternate -20 / -60 dB",
|
|
74
|
+
"func": "const loud = context.get('loud') || false;\ncontext.set('loud', !loud);\nmsg.payload = { volume: loud ? -60 : -20 };\nreturn msg;",
|
|
75
|
+
"outputs": 1,
|
|
76
|
+
"noerr": 0,
|
|
77
|
+
"initialize": "",
|
|
78
|
+
"finalize": "",
|
|
79
|
+
"libs": [],
|
|
80
|
+
"z": "tab-es8311-demo",
|
|
81
|
+
"x": 330,
|
|
82
|
+
"y": 180,
|
|
83
|
+
"wires": [
|
|
84
|
+
[
|
|
85
|
+
"es8311",
|
|
86
|
+
"delay-1s"
|
|
87
|
+
]
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "fn-readback",
|
|
92
|
+
"type": "change",
|
|
93
|
+
"name": "read back",
|
|
94
|
+
"rules": [
|
|
95
|
+
{
|
|
96
|
+
"t": "set",
|
|
97
|
+
"p": "payload",
|
|
98
|
+
"pt": "msg",
|
|
99
|
+
"to": "{}",
|
|
100
|
+
"tot": "json"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"action": "",
|
|
104
|
+
"property": "",
|
|
105
|
+
"from": "",
|
|
106
|
+
"to": "",
|
|
107
|
+
"reg": false,
|
|
108
|
+
"z": "tab-es8311-demo",
|
|
109
|
+
"x": 360,
|
|
110
|
+
"y": 260,
|
|
111
|
+
"wires": [
|
|
112
|
+
[
|
|
113
|
+
"es8311"
|
|
114
|
+
]
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "delay-1s",
|
|
119
|
+
"type": "delay",
|
|
120
|
+
"name": "",
|
|
121
|
+
"pauseType": "delay",
|
|
122
|
+
"timeout": "1",
|
|
123
|
+
"timeoutUnits": "seconds",
|
|
124
|
+
"rate": "1",
|
|
125
|
+
"nbRateUnits": "1",
|
|
126
|
+
"rateUnits": "second",
|
|
127
|
+
"randomFirst": "1",
|
|
128
|
+
"randomLast": "5",
|
|
129
|
+
"randomUnits": "seconds",
|
|
130
|
+
"drop": false,
|
|
131
|
+
"allowrate": false,
|
|
132
|
+
"outputs": 1,
|
|
133
|
+
"z": "tab-es8311-demo",
|
|
134
|
+
"x": 350,
|
|
135
|
+
"y": 220,
|
|
136
|
+
"wires": [
|
|
137
|
+
[
|
|
138
|
+
"fn-readback"
|
|
139
|
+
]
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"id": "es8311",
|
|
144
|
+
"type": "periph-es8311",
|
|
145
|
+
"name": "ES8311",
|
|
146
|
+
"device": "cfg-es8311",
|
|
147
|
+
"z": "tab-es8311-demo",
|
|
148
|
+
"x": 560,
|
|
149
|
+
"y": 180,
|
|
150
|
+
"wires": [
|
|
151
|
+
[
|
|
152
|
+
"dbg-output"
|
|
153
|
+
]
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"id": "dbg-output",
|
|
158
|
+
"type": "debug",
|
|
159
|
+
"name": "",
|
|
160
|
+
"active": true,
|
|
161
|
+
"tosidebar": true,
|
|
162
|
+
"console": false,
|
|
163
|
+
"tostatus": false,
|
|
164
|
+
"complete": "payload",
|
|
165
|
+
"targetType": "msg",
|
|
166
|
+
"statusVal": "",
|
|
167
|
+
"statusType": "auto",
|
|
168
|
+
"z": "tab-es8311-demo",
|
|
169
|
+
"x": 760,
|
|
170
|
+
"y": 180,
|
|
171
|
+
"wires": []
|
|
172
|
+
}
|
|
173
|
+
]
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-mcp4xxx-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "MCP4XXX Digital Potentiometer Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Sets network 0 of an MCP4652 (dual 8-bit rheostat; change the part in the config node for any of the sixteen MCP4531...MCP4662) to a code from a slider-like inject, sweeps the wiper in 16 steps every 500 ms with { step: 16 } to show the resistance staircase (wrapping back to zero), and mirrors the code to network 1 with a third inject. For a non-volatile part (MCP454X/456X/464X/466X) the fourth inject sends { store: true } to keep the current wiper over power cycles. All paths print the resulting code and W-B resistance in ohms to the debug panel."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-mcp4xxx",
|
|
11
|
+
"type": "mcp4xxx-device",
|
|
12
|
+
"name": "MCP4652",
|
|
13
|
+
"part": "MCP4652",
|
|
14
|
+
"bus": "1",
|
|
15
|
+
"address": "58",
|
|
16
|
+
"rab": "10000",
|
|
17
|
+
"rwiper": "75",
|
|
18
|
+
"gpioChip": "0",
|
|
19
|
+
"hvcPin": ""
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"id": "inj-set",
|
|
23
|
+
"type": "inject",
|
|
24
|
+
"name": "set code 128",
|
|
25
|
+
"topic": "",
|
|
26
|
+
"payload": "128",
|
|
27
|
+
"payloadType": "num",
|
|
28
|
+
"repeat": "",
|
|
29
|
+
"crontab": "",
|
|
30
|
+
"once": false,
|
|
31
|
+
"onceDelay": 0.1,
|
|
32
|
+
"z": "tab-mcp4xxx-demo",
|
|
33
|
+
"x": 150,
|
|
34
|
+
"y": 80,
|
|
35
|
+
"wires": [
|
|
36
|
+
[
|
|
37
|
+
"fn-set"
|
|
38
|
+
]
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "fn-set",
|
|
43
|
+
"type": "function",
|
|
44
|
+
"name": "network 0 code",
|
|
45
|
+
"func": "msg.payload = { channel: 0, code: msg.payload };\nreturn msg;",
|
|
46
|
+
"outputs": 1,
|
|
47
|
+
"noerr": 0,
|
|
48
|
+
"initialize": "",
|
|
49
|
+
"finalize": "",
|
|
50
|
+
"libs": [],
|
|
51
|
+
"z": "tab-mcp4xxx-demo",
|
|
52
|
+
"x": 380,
|
|
53
|
+
"y": 80,
|
|
54
|
+
"wires": [
|
|
55
|
+
[
|
|
56
|
+
"mcp4xxx"
|
|
57
|
+
]
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "inj-sweep",
|
|
62
|
+
"type": "inject",
|
|
63
|
+
"name": "step +16 every 500 ms",
|
|
64
|
+
"topic": "",
|
|
65
|
+
"payload": "",
|
|
66
|
+
"payloadType": "date",
|
|
67
|
+
"repeat": "0.5",
|
|
68
|
+
"crontab": "",
|
|
69
|
+
"once": false,
|
|
70
|
+
"onceDelay": 0.1,
|
|
71
|
+
"z": "tab-mcp4xxx-demo",
|
|
72
|
+
"x": 150,
|
|
73
|
+
"y": 140,
|
|
74
|
+
"wires": [
|
|
75
|
+
[
|
|
76
|
+
"fn-sweep"
|
|
77
|
+
]
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "fn-sweep",
|
|
82
|
+
"type": "function",
|
|
83
|
+
"name": "staircase step",
|
|
84
|
+
"func": "let n = context.get('n') || 0;\nmsg.payload = n % 16 === 0 ? { channel: 0, code: 0 } : { channel: 0, step: 16 };\ncontext.set('n', n + 1);\nreturn msg;",
|
|
85
|
+
"outputs": 1,
|
|
86
|
+
"noerr": 0,
|
|
87
|
+
"initialize": "",
|
|
88
|
+
"finalize": "",
|
|
89
|
+
"libs": [],
|
|
90
|
+
"z": "tab-mcp4xxx-demo",
|
|
91
|
+
"x": 380,
|
|
92
|
+
"y": 140,
|
|
93
|
+
"wires": [
|
|
94
|
+
[
|
|
95
|
+
"mcp4xxx"
|
|
96
|
+
]
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "inj-mirror",
|
|
101
|
+
"type": "inject",
|
|
102
|
+
"name": "mirror to network 1",
|
|
103
|
+
"topic": "",
|
|
104
|
+
"payload": "64",
|
|
105
|
+
"payloadType": "num",
|
|
106
|
+
"repeat": "",
|
|
107
|
+
"crontab": "",
|
|
108
|
+
"once": false,
|
|
109
|
+
"onceDelay": 0.1,
|
|
110
|
+
"z": "tab-mcp4xxx-demo",
|
|
111
|
+
"x": 150,
|
|
112
|
+
"y": 200,
|
|
113
|
+
"wires": [
|
|
114
|
+
[
|
|
115
|
+
"fn-mirror"
|
|
116
|
+
]
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "fn-mirror",
|
|
121
|
+
"type": "function",
|
|
122
|
+
"name": "network 1 code",
|
|
123
|
+
"func": "msg.payload = { channel: 1, code: msg.payload };\nreturn msg;",
|
|
124
|
+
"outputs": 1,
|
|
125
|
+
"noerr": 0,
|
|
126
|
+
"initialize": "",
|
|
127
|
+
"finalize": "",
|
|
128
|
+
"libs": [],
|
|
129
|
+
"z": "tab-mcp4xxx-demo",
|
|
130
|
+
"x": 380,
|
|
131
|
+
"y": 200,
|
|
132
|
+
"wires": [
|
|
133
|
+
[
|
|
134
|
+
"mcp4xxx"
|
|
135
|
+
]
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"id": "inj-store",
|
|
140
|
+
"type": "inject",
|
|
141
|
+
"name": "store wiper (NV parts)",
|
|
142
|
+
"topic": "",
|
|
143
|
+
"payload": "",
|
|
144
|
+
"payloadType": "date",
|
|
145
|
+
"repeat": "",
|
|
146
|
+
"crontab": "",
|
|
147
|
+
"once": false,
|
|
148
|
+
"onceDelay": 0.1,
|
|
149
|
+
"z": "tab-mcp4xxx-demo",
|
|
150
|
+
"x": 150,
|
|
151
|
+
"y": 260,
|
|
152
|
+
"wires": [
|
|
153
|
+
[
|
|
154
|
+
"fn-store"
|
|
155
|
+
]
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"id": "fn-store",
|
|
160
|
+
"type": "function",
|
|
161
|
+
"name": "store",
|
|
162
|
+
"func": "msg.payload = { channel: 0, store: true };\nreturn msg;",
|
|
163
|
+
"outputs": 1,
|
|
164
|
+
"noerr": 0,
|
|
165
|
+
"initialize": "",
|
|
166
|
+
"finalize": "",
|
|
167
|
+
"libs": [],
|
|
168
|
+
"z": "tab-mcp4xxx-demo",
|
|
169
|
+
"x": 380,
|
|
170
|
+
"y": 260,
|
|
171
|
+
"wires": [
|
|
172
|
+
[
|
|
173
|
+
"mcp4xxx"
|
|
174
|
+
]
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"id": "mcp4xxx",
|
|
179
|
+
"type": "periph-mcp4xxx",
|
|
180
|
+
"name": "MCP4XXX",
|
|
181
|
+
"device": "cfg-mcp4xxx",
|
|
182
|
+
"z": "tab-mcp4xxx-demo",
|
|
183
|
+
"x": 600,
|
|
184
|
+
"y": 140,
|
|
185
|
+
"wires": [
|
|
186
|
+
[
|
|
187
|
+
"dbg"
|
|
188
|
+
]
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"id": "dbg",
|
|
193
|
+
"type": "debug",
|
|
194
|
+
"name": "code and resistance",
|
|
195
|
+
"active": true,
|
|
196
|
+
"tosidebar": true,
|
|
197
|
+
"console": false,
|
|
198
|
+
"tostatus": false,
|
|
199
|
+
"complete": "payload",
|
|
200
|
+
"targetType": "msg",
|
|
201
|
+
"z": "tab-mcp4xxx-demo",
|
|
202
|
+
"x": 820,
|
|
203
|
+
"y": 140,
|
|
204
|
+
"wires": []
|
|
205
|
+
}
|
|
206
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-ad5243', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
rab: { value: '10000', required: true },
|
|
9
|
+
rwiper: { value: '160', required: true, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-sliders',
|
|
14
|
+
label: function() { return this.name || 'AD5243'; },
|
|
15
|
+
paletteLabel: 'AD5243'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-ad5243">
|
|
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="AD5243">
|
|
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"> (Linux /dev/i2c-N)
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label><i class="fa fa-at"></i> I²C address</label>
|
|
30
|
+
<span>0x2F (fixed, no address pins)</span>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-rab"><i class="fa fa-sliders"></i> RAB</label>
|
|
34
|
+
<select id="node-input-rab" style="width:120px">
|
|
35
|
+
<option value="2500">2.5 kΩ</option>
|
|
36
|
+
<option value="10000">10 kΩ</option>
|
|
37
|
+
<option value="50000">50 kΩ</option>
|
|
38
|
+
<option value="100000">100 kΩ</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="form-row">
|
|
42
|
+
<label for="node-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
|
|
43
|
+
<input type="number" id="node-input-rwiper" min="0" style="width:80px"> Ω (typ. 160 Ω)
|
|
44
|
+
</div>
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script type="text/html" data-help-name="periph-ad5243">
|
|
48
|
+
<p>Sets and reads the two 256-position wipers of an AD5243 dual I²C digital potentiometer. Wiper values are volatile: both channels power up at midscale (128).</p>
|
|
49
|
+
|
|
50
|
+
<h3>Inputs</h3>
|
|
51
|
+
<dl class="message-properties">
|
|
52
|
+
<dt>payload.channel <span class="property-type">number</span></dt>
|
|
53
|
+
<dd>Channel to act on: <code>0</code> or <code>1</code>.</dd>
|
|
54
|
+
<dt>payload.code <span class="property-type">number</span></dt>
|
|
55
|
+
<dd>With <code>channel</code>: wiper position 0–255 (clamped).</dd>
|
|
56
|
+
<dt>payload.ohms <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>With <code>channel</code> (and no <code>code</code>): target W–B resistance in ohms, set to the nearest code.</dd>
|
|
58
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
59
|
+
<dd>Any other message reads back both channels.</dd>
|
|
60
|
+
</dl>
|
|
61
|
+
|
|
62
|
+
<h3>Outputs</h3>
|
|
63
|
+
<dl class="message-properties">
|
|
64
|
+
<dt>payload.channel, payload.code, payload.resistance <span class="property-type">number</span></dt>
|
|
65
|
+
<dd>After a set: the channel, the wiper code read back, and the resulting W–B resistance in ohms.</dd>
|
|
66
|
+
<dt>payload.wiper <span class="property-type">number[2]</span></dt>
|
|
67
|
+
<dd>After any other message: wiper codes of channels 0 and 1.</dd>
|
|
68
|
+
<dt>payload.resistance <span class="property-type">number[2]</span></dt>
|
|
69
|
+
<dd>After any other message: W–B resistances (Ω) of channels 0 and 1.</dd>
|
|
70
|
+
</dl>
|
|
71
|
+
|
|
72
|
+
<h3>Configuration</h3>
|
|
73
|
+
<p>Set the Linux I²C bus number, the part's end-to-end resistance RAB (2.5, 10, 50 or 100 kΩ, as ordered) and the wiper resistance RW. The address is fixed at 0x2F. Absolute resistance is only accurate to the part's tolerance (±20 %); ratios are exact.</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { AD5243Full } = require('periph/src/chips/adc_dac/ad5243');
|
|
6
|
+
|
|
7
|
+
function AD5243Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const rAb = parseFloat(config.rab) || 10000.0;
|
|
13
|
+
const rWiper = config.rwiper === '' || config.rwiper === undefined ? 160.0 : parseFloat(config.rwiper);
|
|
14
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), AD5243Full.I2C_ADDRESS);
|
|
15
|
+
node.driver = new AD5243Full(connection, rAb, rWiper);
|
|
16
|
+
node.connection = connection;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
node.error('AD5243 init failed: ' + e.message);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
node.on('input', async function(msg, send, done) {
|
|
22
|
+
if (!node.driver) { done(); return; }
|
|
23
|
+
try {
|
|
24
|
+
const p = msg.payload;
|
|
25
|
+
if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
|
|
26
|
+
if (typeof p.code === 'number') {
|
|
27
|
+
await node.driver.setWiper(p.channel, p.code);
|
|
28
|
+
} else if (typeof p.ohms === 'number') {
|
|
29
|
+
await node.driver.setResistance(p.channel, p.ohms);
|
|
30
|
+
} else {
|
|
31
|
+
done(new Error('payload needs code or ohms'));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const code = await node.driver.getWiper(p.channel);
|
|
35
|
+
const resistance = await node.driver.getResistance(p.channel);
|
|
36
|
+
msg.payload = { channel: p.channel, code, resistance };
|
|
37
|
+
} else {
|
|
38
|
+
const c1 = await node.driver.getWiper(0);
|
|
39
|
+
const c2 = await node.driver.getWiper(1);
|
|
40
|
+
const r1 = await node.driver.getResistance(0);
|
|
41
|
+
const r2 = await node.driver.getResistance(1);
|
|
42
|
+
msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
|
|
43
|
+
}
|
|
44
|
+
send(msg);
|
|
45
|
+
done();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
done(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
node.on('close', async function(removed, done) {
|
|
52
|
+
try {
|
|
53
|
+
if (node.connection) await node.connection.close();
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// bus may already be gone; nothing more to do on close
|
|
56
|
+
} finally {
|
|
57
|
+
done();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
RED.nodes.registerType('periph-ad5243', AD5243Node);
|
|
62
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ad5248-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '2C', required: true },
|
|
9
|
+
rab: { value: '10000', required: true, validate: RED.validators.number() },
|
|
10
|
+
rwiper: { value: '160', required: true, validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('AD5248 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="ad5248-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="AD5248">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<select id="node-config-input-address" style="width:100px">
|
|
30
|
+
<option value="2C">0x2C (AD1=0, AD0=0)</option>
|
|
31
|
+
<option value="2D">0x2D (AD1=0, AD0=1)</option>
|
|
32
|
+
<option value="2E">0x2E (AD1=1, AD0=0)</option>
|
|
33
|
+
<option value="2F">0x2F (AD1=1, AD0=1)</option>
|
|
34
|
+
</select>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-config-input-rab">RAB (Ω)</label>
|
|
38
|
+
<select id="node-config-input-rab" style="width:100px">
|
|
39
|
+
<option value="2500">2.5 kΩ</option>
|
|
40
|
+
<option value="10000">10 kΩ</option>
|
|
41
|
+
<option value="50000">50 kΩ</option>
|
|
42
|
+
<option value="100000">100 kΩ</option>
|
|
43
|
+
</select>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="form-row">
|
|
46
|
+
<label for="node-config-input-rwiper">Wiper R (Ω)</label>
|
|
47
|
+
<input type="number" id="node-config-input-rwiper" min="0" style="width:100px"> typical 160 Ω at 5 V
|
|
48
|
+
</div>
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<!-- Node: set or read the wiper -->
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
RED.nodes.registerType('periph-ad5248', {
|
|
54
|
+
category: 'Peripheral',
|
|
55
|
+
color: '#C084FC',
|
|
56
|
+
defaults: {
|
|
57
|
+
name: { value: '' },
|
|
58
|
+
device: { value: '', type: 'ad5248-device', required: true }
|
|
59
|
+
},
|
|
60
|
+
inputs: 1,
|
|
61
|
+
outputs: 1,
|
|
62
|
+
icon: 'font-awesome/fa-sliders',
|
|
63
|
+
label: function() { return this.name || 'AD5248'; },
|
|
64
|
+
paletteLabel: 'AD5248'
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-template-name="periph-ad5248">
|
|
69
|
+
<div class="form-row">
|
|
70
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
71
|
+
<input type="text" id="node-input-device">
|
|
72
|
+
</div>
|
|
73
|
+
<div class="form-row">
|
|
74
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
75
|
+
<input type="text" id="node-input-name" placeholder="AD5248">
|
|
76
|
+
</div>
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script type="text/html" data-help-name="periph-ad5248">
|
|
80
|
+
<p>Sets or reads the two 256-position wipers of an AD5248 dual digital rheostat over I²C.
|
|
81
|
+
The device is configured via an <b>ad5248-device</b> config node.</p>
|
|
82
|
+
|
|
83
|
+
<h3>Inputs</h3>
|
|
84
|
+
<dl class="message-properties">
|
|
85
|
+
<dt>payload.channel <span class="property-type">number</span></dt>
|
|
86
|
+
<dd>Channel 0 or 1.</dd>
|
|
87
|
+
<dt>payload.code <span class="property-type">number</span></dt>
|
|
88
|
+
<dd>Wiper position 0–255. Takes precedence over <code>ohms</code>.</dd>
|
|
89
|
+
<dt>payload.ohms <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>Target wiper-to-B resistance in ohms; the nearest reachable code is used.</dd>
|
|
91
|
+
</dl>
|
|
92
|
+
<p>Any other message reads both channels back.</p>
|
|
93
|
+
|
|
94
|
+
<h3>Outputs</h3>
|
|
95
|
+
<dl class="message-properties">
|
|
96
|
+
<dt>payload.channel, payload.code, payload.resistance</dt>
|
|
97
|
+
<dd>After a write: the channel, the resulting wiper code and its W–B resistance (Ω).</dd>
|
|
98
|
+
<dt>payload.wiper <span class="property-type">array</span></dt>
|
|
99
|
+
<dd>After a read: <code>[code1, code2]</code>.</dd>
|
|
100
|
+
<dt>payload.resistance <span class="property-type">array</span></dt>
|
|
101
|
+
<dd>After a read: <code>[R1, R2]</code> in ohms.</dd>
|
|
102
|
+
</dl>
|
|
103
|
+
|
|
104
|
+
<h3>Configuration</h3>
|
|
105
|
+
<p>Set the I²C bus number and address (<code>0x2C</code>–<code>0x2F</code>, selected by the AD0/AD1 pins),
|
|
106
|
+
the end-to-end resistance RAB (2.5 / 10 / 50 / 100 kΩ) and the wiper resistance RW. The wiper
|
|
107
|
+
values are volatile and return to midscale (128) at every power-up.</p>
|
|
108
|
+
</script>
|