curves
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
curves [2021/09/10 14:33] – [Get value from the curve] atolstov | curves [2022/05/23 21:11] – [Get value from the curve via Lua] emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{ : | + | {{ network: |
======Curves====== | ======Curves====== | ||
=====Introduction===== | =====Introduction===== | ||
Line 89: | Line 89: | ||
{{ : | {{ : | ||
- | =====Get value from the curve===== | + | =====Get value from the curve via Lua ===== |
To get the **OUTPUT y value** from existing(pre-created) curve, you need: | To get the **OUTPUT y value** from existing(pre-created) curve, you need: | ||
Line 99: | Line 99: | ||
<code lua - curves.lib> | <code lua - curves.lib> | ||
- | function | + | --[[ |
- | --[[ | + | The function |
- | --Curve handler | + | Example of a curve, having multiple ranges of kx + b, set in a register of a String type with Json |
- | | + | [{" |
- | Put curve register as first argument and X coordinate as second. | + | --]] |
- | | + | function getCurveValue (curveReg, inputValue) |
- | Get as result status if it is inside curve range of outside(false) and the Y value as second output argument | + | |
+ | | ||
+ | local tab = cjson.decode( R(curveReg) ) | ||
+ | local outputValue, | ||
| | ||
- | | + | for _, sub_ in ipairs(tab) do |
- | curve_status, | + | if ( (sub_.range[s] <= inputValue) |
- | --]] | + | |
- | table = cjson.decode( R ( curve_register ) ) | + | |
- | -- inRangeCurve( table, x_to_find_y ) | + | |
- | | + | |
- | if ( value.range[1] <= x_to_find_y | + | |
- | | + | |
- | in_range_status, | + | |
- | return in_range_status, y | + | |
end | end | ||
end | end | ||
- | | + | -- edge cases |
- | -- in_range_status, | + | |
- | | + | |
- | | + | |
- | elseif | + | elseif |
- | | + | |
- | | + | |
- | return in_range_status, | + | |
end | end | ||
- | + | | |
- | | + | |
end | end | ||
</ | </ | ||
Line 141: | Line 135: | ||
local t = os.date(" | local t = os.date(" | ||
current_hour = tonumber(t.hour) | current_hour = tonumber(t.hour) | ||
- | curve_status, | + | curve_status, |
if curve_status then | if curve_status then | ||
WriteReg(" | WriteReg(" |
curves.txt · Last modified: 2024/06/03 08:45 by emozolyak