Merge pull request #49 from realmicu/master
Allow read of Distributor slot status
This commit is contained in:
commit
b74c596b00
@ -27,7 +27,7 @@ local STANDBY_TICKS = 3
|
|||||||
local COUNTDOWN_TICKS = 4
|
local COUNTDOWN_TICKS = 4
|
||||||
local CYCLE_TIME = 4
|
local CYCLE_TIME = 4
|
||||||
|
|
||||||
local INFO = [[Turn port on/off: command = 'port', payload = red/green/blue/yellow=on/off]]
|
local INFO = [[Turn port on/off or read its state: command = 'port', payload = red/green/blue/yellow{=on/off}]]
|
||||||
|
|
||||||
|
|
||||||
--local Side2Color = {B="red", L="green", F="blue", R="yellow"}
|
--local Side2Color = {B="red", L="green", F="blue", R="yellow"}
|
||||||
@ -374,6 +374,13 @@ local function change_filter_settings(pos, slot, val)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- techage command to read filter channel status (on/off)
|
||||||
|
local function read_filter_settings(pos, slot)
|
||||||
|
local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4}
|
||||||
|
local filter = minetest.deserialize(M(pos):get_string("filter"))
|
||||||
|
return filter[slots[slot]] and "on" or "off"
|
||||||
|
end
|
||||||
|
|
||||||
local function can_dig(pos, player)
|
local function can_dig(pos, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
return false
|
return false
|
||||||
@ -437,7 +444,11 @@ local tubing = {
|
|||||||
elseif topic == "port" then
|
elseif topic == "port" then
|
||||||
-- "red"/"green"/"blue"/"yellow" = "on"/"off"
|
-- "red"/"green"/"blue"/"yellow" = "on"/"off"
|
||||||
local slot, val = techage.ident_value(payload)
|
local slot, val = techage.ident_value(payload)
|
||||||
|
if val == "" then
|
||||||
|
return read_filter_settings(pos, slot)
|
||||||
|
else
|
||||||
return change_filter_settings(pos, slot, val)
|
return change_filter_settings(pos, slot, val)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
||||||
end
|
end
|
||||||
|
@ -744,3 +744,52 @@ techage.icta_register_action("set_filter", {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
techage.icta_register_condition("get_filter", {
|
||||||
|
title = "read state of a Distributor filter slot",
|
||||||
|
formspec = {
|
||||||
|
{
|
||||||
|
type = "number",
|
||||||
|
name = "number",
|
||||||
|
label = "distri number",
|
||||||
|
default = "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "textlist",
|
||||||
|
name = "color",
|
||||||
|
label = "filter port",
|
||||||
|
choices = "red,green,blue,yellow",
|
||||||
|
default = "red",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "textlist",
|
||||||
|
name = "operand",
|
||||||
|
choices = "is,is not",
|
||||||
|
default = "is",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "textlist",
|
||||||
|
name = "value",
|
||||||
|
label = "state",
|
||||||
|
choices = "on,off",
|
||||||
|
default = "off",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "label",
|
||||||
|
name = "lbl",
|
||||||
|
label = "Read state of a Distributor filter slot.\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
button = function(data, environ) -- default button label
|
||||||
|
return 'fltr('..techage.fmt_number(data.number)..","..data.color..' '..data.operand..' '..data.value..')'
|
||||||
|
end,
|
||||||
|
code = function(data, environ)
|
||||||
|
local condition = function(env, idx)
|
||||||
|
return techage.send_single(environ.number, data.number, "port", data.color)
|
||||||
|
end
|
||||||
|
local result = function(val)
|
||||||
|
return techage.compare(val, data.value, data.operand)
|
||||||
|
end
|
||||||
|
return condition, result
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
@ -105,6 +105,19 @@ techage.lua_ctlr.register_action("set_filter", {
|
|||||||
' example: $set_filter("1234", "red", "off")'
|
' example: $set_filter("1234", "red", "off")'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
techage.lua_ctlr.register_action("get_filter", {
|
||||||
|
cmnd = function(self, num, slot)
|
||||||
|
num = tostring(num or "")
|
||||||
|
slot = tostring(slot or "red")
|
||||||
|
if not_protected(self.meta.owner, num) then
|
||||||
|
return techage.send_single(self.meta.number, num, "port", slot)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
help = " $get_filter(num, slot)\n"..
|
||||||
|
' Read state of a Distributor filter slot.\n'..
|
||||||
|
' Return value is "on" or "off".\n'..
|
||||||
|
' example: state = $get_filter("1234", "red")'
|
||||||
|
})
|
||||||
|
|
||||||
techage.lua_ctlr.register_action("display", {
|
techage.lua_ctlr.register_action("display", {
|
||||||
cmnd = function(self, num, row, text)
|
cmnd = function(self, num, row, text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user