@edgepi-cloud/node-red-edgepi-adc
Version:
node-red node for edgepi adc module utilizing remote procedure calls
296 lines (286 loc) • 9.7 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("adc", {
category: "EdgePi",
color: "#f391aa",
defaults: {
name: { value: "" },
transport: { value: "Local" },
tcpAddress: { value: "" },
tcpPort: { value: "" },
read: { value: "single" },
adcNum: { value: 1 },
adc1DataRate: { value: 38400 },
adc2DataRate: { value: 800 },
channel: { value: 1 },
diff: { value: 1 },
},
inputs: 1,
outputs: 1,
icon: "right-arrow-bracket.svg",
label: function () {
return this.name || "adc";
},
oneditprepare: function () {
const transportType = document.getElementById("node-input-transport");
const tcpTransportInputs = document.querySelector(".form-row.tcp");
const read = document.getElementById("node-input-read");
const adcNum = document.getElementById("node-input-adcNum");
const adc1 = document.getElementById("adc-option-adc1");
const dataRateField = document.querySelector(".form-row.data-rate");
const adc1DataRate = document.getElementById("node-input-adc1DataRate");
const adc2DataRate = document.getElementById("node-input-adc2DataRate");
const channelField = document.querySelector(".form-row.channel");
const diffField = document.querySelector(".form-row.diff");
function updateEditor() {
tcpTransportInputs.style.display =
transportType.value === "Network" ? "flex" : "none";
channelField.style.display = read.value === "single" ? "flex" : "none";
dataRateField.style.display = read.value === "single" ? "flex" : "none";
diffField.style.display = read.value === "diff" ? "flex" : "none";
adc1DataRate.style.display = adcNum.value === "1" ? "flex" : "none";
adc2DataRate.style.display = adcNum.value === "2" ? "flex" : "none";
if (read.value === "rtd") {
adcNum.value = "2";
adcNum.setAttribute("disabled", true);
} else {
adcNum.removeAttribute("disabled");
}
}
updateEditor();
transportType.addEventListener("change", updateEditor);
read.addEventListener("change", updateEditor);
adcNum.addEventListener("change", updateEditor);
},
});
</script>
<script type="text/html" data-template-name="adc">
<style>
* {
box-sizing: border-box ;
}
.form-row {
display: flex;
align-items: center;
}
.form-row > label {
margin-top: auto;
margin-bottom: auto;
}
.form-row.tcp {
flex-direction: row;
align-items: center;
margin-top: -5px;
margin-bottom: 10px;
}
.tcp-address-input {
width: 160px ;
margin-left: 100px ;
}
.tcp-port-input {
width: 60px ;
}
.tcp-port-label {
width: 5px ;
margin: auto 5px;
}
</style>
<div class="form-row name">
<label for="node-input-name"><i class="fa fa-tag"></i> Name:</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row transport">
<label for="node-input-transport">RPC Server:</label>
<select id="node-input-transport">
<option value="Local">Local</option>
<option value="Network">Network</option>
</select>
</div>
<div class="form-row tcp">
<input
class="tcp-address-input"
type="text"
id="node-input-tcpAddress"
placeholder="IP Address/ Hostname"
/>
<label class="tcp-port-label" for="node-input-tcpPort">:</label>
<input
class="tcp-port-input"
type="text"
id="node-input-tcpPort"
placeholder="Port"
/>
</div>
<div class="form-row read">
<label for="node-input-read">Read:</label>
<select id="node-input-read">
<option value="single">Single-ended</option>
<option value="diff">Differential</option>
<option value="rtd">RTD</option>
</select>
</div>
<div class="form-row adcNum">
<label for="node-input-adcNum">ADC:</label>
<select id="node-input-adcNum">
<option value="1" id="adc-option-adc1">ADC1</option>
<option value="2">ADC2</option>
</select>
</div>
<div class="form-row data-rate">
<label for="node-input-adc1DataRate">Data Rate:</label>
<select id="node-input-adc1DataRate">
<option value="2.5">2.5 S/s</option>
<option value="5">5 S/s</option>
<option value="10">10 S/s</option>
<option value="16P6">16.6 S/s</option>
<option value="20">20 S/s</option>
<option value="50">50 S/s</option>
<option value="60">60 S/s</option>
<option value="100">100 S/s</option>
<option value="400">400 S/s</option>
<option value="1200">1200 S/s</option>
<option value="2400">2400 S/s</option>
<option value="4800">4800 S/s</option>
<option value="7200">7200 S/s</option>
<option value="14400">14400 S/s</option>
<option value="19200">19200 S/s</option>
<option value="38400">38400 S/s</option>
</select>
<select id="node-input-adc2DataRate">
<option value="10">10 S/s</option>
<option value="100">100 S/s</option>
<option value="400">400 S/s</option>
<option value="800">800 S/s</option>
</select>
</div>
<div class="form-row channel">
<label for="node-input-channel">Channel:</label>
<select id="node-input-channel">
<option value="1">A-IN1</option>
<option value="2">A-IN2</option>
<option value="3">A-IN3</option>
<option value="4">A-IN4</option>
<option value="5">A-IN5</option>
<option value="6">A-IN6</option>
<option value="7">A-IN7</option>
<option value="8">A-IN8</option>
</select>
</div>
<div class="form-row diff">
<label for="node-input-diff">Differential:</label>
<select id="node-input-diff">
<option value="1">DIFF1</option>
<option value="2">DIFF2</option>
<option value="3">DIFF3</option>
<option value="4">DIFF4</option>
</select>
</div>
</script>
<script type="text/html" data-help-name="adc">
<p>
Reads an analog measurement from a set of input channels on the EdgePi. The
measurement can be configured to be either a voltage, differential or RTD
temperature reading.
</p>
<h3>Details</h3>
<p>Differential Types:</p>
<ul>
<li>DIFF1: Ports 16 & 17</li>
<li>DIFF2: Ports 19 & 20</li>
<li>DIFF3: Ports 21 & 22</li>
<li>DIFF4: Ports 24 & 25</li>
</ul>
<p>Assigned ports for RTD measurements:</p>
<ul>
<li>21</li>
<li>24</li>
<li>25</li>
</ul>
<p>NOTE: Port 22 will also be disabled</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>RPC Server</dt>
<dd>
The connection to your EdgePi's RPC Server. Use <strong>Local</strong> if
node-red is running on EdgePi. Otherwise use the
<strong>Network</strong> option and enter EdgePi's IP address / Hostname.
</dd>
</dl>
<dl class="message-properties">
<dt>Read</dt>
<dd>The type of read to complete.</dd>
</dl>
<dl class="message-properties">
<dt>ADC</dt>
<dd>The ADC to use for the next read.</dd>
</dl>
<dl class="message-properties">
<p>• When configured to read single-ended:</p>
<dt>Channel</dt>
<dd>Which analog channel you read from next.</dd>
</dl>
<dl class="message-properties">
<p>• When configured to read single-ended:</p>
<dt>Data Rate</dt>
<dd>
The selected ADC's data rate. Note that data rates are different depending
on the selected ADC.
</dd>
</dl>
<dl class="message-properties">
<p>• When configured to read differential:</p>
<dt>Differential</dt>
<dd>The differential you want to read next.</dd>
</dl>
<h3>Inputs</h3>
<dd>
Initial configurations set in the editor are applied once the node is
deployed. Configurations can then be dynamically set from input.
</dd>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>
The input selection -- the channel number (1 to 8) or differential
channels number (1 to 4) depending on the read type. Ignored for read type
rtd.
</dd>
<dt>readType <span class="property-type">string</span></dt>
<dd>
<strong>single</strong>, <strong>diff</strong>, or <strong>rtd</strong>.
</dd>
<dt>dataRate <span class="property-type">number</span></dt>
<dd>
ADC data rate. Default values: <strong>38400</strong> (ADC1) and
<strong>800</strong> (ADC2).
</dd>
<dt>adc <span class="property-type">number</span></dt>
<dd>
ADC number to use for reads. Valid values are <strong>1</strong> and
<strong>2</strong>. Default is <strong>1</strong>.
</dd>
</dl>
<h3>Outputs</h3>
<p>• Read type <strong>single</strong> :</p>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>Voltage reading of the specified single-ended analog input channel.</dd>
</dl>
<p>• Read type <strong>diff</strong> :</p>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>
Differential voltage reading of the specified differential channels.
</dd>
</dl>
<p>• Read type <strong>rtd</strong> :</p>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>RTD temperature reading in Celsius.</dd>
</dl>
<h3>References</h3>
<ul>
<li>
<a href="https://github.com/edgepi-cloud/node-red-edgepi-adc">GitHub</a>
-the node's github repository
</li>
</ul>
</script>