Skip to content

Commit

Permalink
Merge pull request #11 from realmicu/master
Browse files Browse the repository at this point in the history
sl_controller: add battery status command.
  • Loading branch information
joe7575 authored Feb 12, 2019
2 parents 9e12dc1 + 96d5ee9 commit 7e064c9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sl_controller/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ sl_controller.register_function("position", {
" 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 state = meta:get_int("state") == tubelib.RUNNING
Expand Down

0 comments on commit 7e064c9

Please sign in to comment.