UNPKG

@strato-automation/node-red-contrib-strato-automation

Version:
180 lines (159 loc) 7.23 kB
<script type="text/javascript"> RED.nodes.registerType('func-ramp', { category: 'Strato Automation', color: '#f3b567', defaults: { name: { value: "", label: "name" }, x1: { value: 0, required: true, label: "x1" }, y1: { value: 0, required: true, label: "y1" }, x2: { value: 100, required: true, label: "x2" }, y2: { value: 100, required: true, label: "y2" }, limit: { value: true, required: true, label: "limit" }, topic: { value: "default", required: true, label: "topic" }, }, inputs: 1, outputs: 1, icon: "font-awesome/fa-line-chart", paletteLabel: function() { return "Linear Reset"; }, label: function () { return (this.name || "Linear Reset") }, labelStyle: function () { return this.name ? "node_label_italic" : ""; }, outputLabels: function (index) { return this.topic + " " + index; }, inputLabels: function (index) { return "Input 1: X1\nInput 2: Y1\nInput 3: X2\nInput 4: Y2"; }, oneditprepare: function () { var node = this; $("#node-input-topic").typedInput({ types: [ { value: "", options: topics() } ] }) } }); </script> <script type="text/html" data-template-name="func-ramp"> <!-- Basic Settings --> <div class="form-tips" style="margin-bottom: 20px;"> <b>Basic Settings</b> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-bookmark"></i> Name</label> <input type="text" id="node-input-name" placeholder="Optional name for this function"> </div> <!-- Linear Function Settings --> <div class="form-tips" style="margin: 20px 0;"> <b>Linear Mapping</b> </div> <div style="padding-left: 10px; border-left: 3px solid #ddd;"> <div class="form-row"> <label><i class="fa fa-arrows-h"></i> Map the input range:</label> <span style="margin-left:10px;">from</span> <input type="num" id="node-input-x1" style="width:60px; margin:0 5px;" placeholder="X1"> <span>to</span> <input type="num" id="node-input-x2" style="width:60px; margin:0 5px;" placeholder="X2"> </div> <div class="form-row"> <label><i class="fa fa-arrows-h"></i> to the target range:</label> <span style="margin-left:10px;">from</span> <input type="num" id="node-input-y1" style="width:60px; margin:0 5px;" placeholder="Y1"> <span>to</span> <input type="num" id="node-input-y2" style="width:60px; margin:0 5px;" placeholder="Y2"> </div> </div> <!-- Output Settings --> <div class="form-tips" style="margin: 20px 0;"> <b>Output Settings</b> </div> <div style="padding-left: 10px; border-left: 3px solid #ddd;"> <div class="form-row"> <label for="node-input-limit"><i class="fa fa-compress"></i> Limit Output</label> <input type="checkbox" id="node-input-limit" style="width: auto; margin-top: 0;"> <span class="form-tips" style="margin-left: 10px;">Constrain output between Y1 and Y2 values</span> </div> <div class="form-row"> <label for="node-input-topic"><i class="fa fa-tags"></i> Topic</label> <input type="text" id="node-input-topic"> </div> </div> <div class="form-tips" style="margin-top: 20px;"> <p><i class="fa fa-info-circle"></i> Tip: Points can be dynamically updated through input messages using topics in1-in4.</p> </div> </script> <script type="text/html" data-help-name="func-ramp"> <p>A function node that performs linear interpolation between two points, creating a linear transfer function (ramp).</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">number</span></dt> <dd>The input value (X) to transform using the linear function</dd> <dt>topic <span class="property-type">string</span></dt> <dd> <ul> <li><code>default</code> - Input value to transform</li> <li><code>in1</code> - Update X1 coordinate</li> <li><code>in2</code> - Update Y1 coordinate</li> <li><code>in3</code> - Update X2 coordinate</li> <li><code>in4</code> - Update Y2 coordinate</li> </ul> </dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">number</span></dt> <dd>The transformed value (Y) based on the linear function</dd> <dt>topic <span class="property-type">string</span></dt> <dd>The configured topic name</dd> </dl> <h3>Configuration</h3> <dl class="message-properties"> <dt>Name <span class="property-type">string</span></dt> <dd>Optional name to identify the node in the flow</dd> <dt>Point 1 (X1,Y1) <span class="property-type">number, number</span></dt> <dd>First point coordinates defining the linear function</dd> <dt>Point 2 (X2,Y2) <span class="property-type">number, number</span></dt> <dd>Second point coordinates defining the linear function</dd> <dt>Limit Output <span class="property-type">boolean</span></dt> <dd>When enabled, constrains the output between Y1 and Y2 values</dd> <dt>Topic <span class="property-type">string</span></dt> <dd>Topic identifier for the output messages</dd> </dl> <h3>Status</h3> <dl class="message-properties"> <dt>Green dot</dt> <dd>Successfully transformed value (shows input and output)</dd> <dt>Red dot</dt> <dd>Error condition (invalid input or configuration)</dd> </dl> <h3>Details</h3> <p>This node implements a linear transfer function defined by two points (X1,Y1) and (X2,Y2). For any input X, it calculates the corresponding Y value using linear interpolation:</p> <p><code>Y = (Y2 - Y1)/(X2 - X1) * (X - X1) + Y1</code></p> <h4>Operation Modes</h4> <ul> <li><b>Unlimited:</b> Output follows the linear function for any input value</li> <li><b>Limited:</b> Output is constrained between Y1 and Y2 values</li> </ul> <h4>Error Conditions</h4> <ul> <li>Invalid input value (not a number)</li> <li>Missing or invalid point coordinates</li> <li>X1 equals X2 (undefined slope)</li> </ul> <h4>Dynamic Configuration</h4> <p>The function points can be dynamically updated by sending messages with specific topics:</p> <ul> <li><code>in1</code> - Updates X1 coordinate</li> <li><code>in2</code> - Updates Y1 coordinate</li> <li><code>in3</code> - Updates X2 coordinate</li> <li><code>in4</code> - Updates Y2 coordinate</li> </ul> </script>