slmodules: cropswatcher: add extended status command.
Device registers new SaferLua command: $get_crops_status(NUM) which returns 3 values: state (as for $get_status() function) and 2 counters - total number of crops and how many are fully grown. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
This commit is contained in:
parent
03814af39e
commit
f00bf97b77
15
README.md
15
README.md
@ -145,12 +145,14 @@ git clone https://github.com/realmicu/minetest-micupack.git micupack
|
||||
crops are fully grown so they can be collected either manually or by machines. Device recognizes
|
||||
all registered farming nodes. Crops Watcher sees plants at its level and down to 2 levels below
|
||||
its node (-2 .. 0), with exception of nodes directly under its box.
|
||||
Field scan is peformed when device is asked for status via standard "state" message. When Tubelib ID
|
||||
numbers are entered in the configuration panel, scan can also be initiated by sending "on" message
|
||||
to Crops Watcher (by Timer, Button etc). If field is ready for harvest, device immediately responses
|
||||
with "on" command sent to specified IDs (for example Tubelib Harvester). No messages are sent for
|
||||
other crop states - Crops Watcher never sends "off" commands to not interfere with machinery automation.
|
||||
It is purely event-based node - it does not use node timers.
|
||||
Field scan is peformed when device is asked for status - either via standard "state" message or by
|
||||
device-specific status request (Watcher registers new SaferLua command $get_crops_status() for
|
||||
SL Controllers). When Tubelib ID numbers are entered in the configuration panel, scan can also be
|
||||
initiated by sending "on" message to Crops Watcher (by Timer, Button etc). If field is ready for
|
||||
harvest, device immediately responses with "on" command sent to specified IDs (for example Tubelib
|
||||
Harvester). No messages are sent for other crop states - Crops Watcher never sends "off" commands
|
||||
to not interfere with machinery automation.
|
||||
It is purely event-based node - it does not use node timers or ABMs.
|
||||
|
||||
Configuration options:
|
||||
|
||||
@ -174,6 +176,7 @@ git clone https://github.com/realmicu/minetest-micupack.git micupack
|
||||
Supported SaferLua functions:
|
||||
|
||||
- $get_status(...)
|
||||
- $get_crops_status(...)
|
||||
|
||||
Punch node to see current status and crop numbers.
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
Supported SaferLua functions:
|
||||
- $get_status(...)
|
||||
- $get_crops_status(...)
|
||||
|
||||
Punch node to see current status and crop numbers.
|
||||
|
||||
@ -281,6 +282,9 @@ tubelib.register_node("slmodules:cropswatcher", {}, {
|
||||
return true
|
||||
elseif topic == "state" then
|
||||
return cwstate[get_cropswatcher_area_state(pos)]
|
||||
elseif topic == "crops" then
|
||||
local sn, cn, gn = get_cropswatcher_area_state(pos)
|
||||
return { cwstate[sn], cn, gn }
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
@ -302,3 +306,23 @@ minetest.register_craft({
|
||||
{ "group:wood", "tubelib:wlanchip", "group:wood" },
|
||||
},
|
||||
})
|
||||
|
||||
--[[
|
||||
--------
|
||||
SaferLua
|
||||
--------
|
||||
]]--
|
||||
|
||||
sl_controller.register_action("get_crops_status", {
|
||||
cmnd = function(self, num)
|
||||
num = tostring(num or "")
|
||||
return unpack(tubelib.send_request(num, "crops", nil) or { "", "", "" })
|
||||
end,
|
||||
help = " $get_crops_status(num)\n" ..
|
||||
" Read Crops Watcher device state.\n" ..
|
||||
" Function returns 3 values:\n" ..
|
||||
' 1: "error", "growing" or "ready"\n' ..
|
||||
" 2: total number of crops\n" ..
|
||||
" 3: number of fully grown crops\n" ..
|
||||
' example: state, total, grown = $get_crops_status("1234")\n'
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user