This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Logic Gates with Logic Machine FB Editor
#9
Average is already implemented, for min/max add these functions before -- prepare each group
Code:
-- MAX value
calc['max'] = function(group)
  local result = -math.huge

  for _, address in ipairs(group.objects) do
    local value = values[ address ]

    if type(value) == 'number' then
      result = math.max(result, value)
    end
  end

  grp.checkupdate(group.output, result)
end

-- MIN value
calc['min'] = function(group)
  local result = math.huge

  for _, address in ipairs(group.objects) do
    local value = values[ address ]

    if type(value) == 'number' then
      result = math.min(result, value)
    end
  end

  grp.checkupdate(group.output, result)
end

Add mapping like this:
Code:
  groups = {
    { tag = 'nor1', output = '0/0/8', mode = 'nor' },
    { tag = 'avg1', output = '0/0/1', mode = 'avg' },
    { tag = 'min1', output = '0/0/2', mode = 'min' },
    { tag = 'max1', output = '0/0/3', mode = 'max' },
  }
Reply


Messages In This Thread
RE: Logic Gates with Logic Machine FB Editor - by admin - 12.12.2022, 07:21

Forum Jump: