Merge pull request #11 from realmicu/master

sl_controller: add battery status command.
This commit is contained in:
Joachim Stolberg 2019-02-12 12:26:24 +01:00 committed by GitHub
commit 7e064c9227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -130,6 +130,22 @@ sl_controller.register_function("position", {
" returns the position '(x,y,z)' of the device\n with given number." " returns the position '(x,y,z)' of the device\n with given number."
}) })
sl_controller.register_action("battery", {
cmnd = function(self)
local meta = minetest.get_meta(self.meta.pos)
local batpos = minetest.string_to_pos(meta:get_string("battery"))
local batmeta = minetest.get_meta(batpos)
local val = (sl_controller.battery_capacity -
math.min(batmeta:get_int("content") or 0,
sl_controller.battery_capacity))
return 100 - math.floor((val * 100.0 / sl_controller.battery_capacity))
end,
help = " $battery()\n"..
" Get charge level of battery connected to Controller.\n"..
" Function returns percent number (0-100) where 100 means full.\n"..
" example: battery_percent = $battery()"
})
local function formspec0(meta) local function formspec0(meta)
local state = meta:get_int("state") == tubelib.RUNNING local state = meta:get_int("state") == tubelib.RUNNING