From 51cab958b94a91b0c576e32371a0159f50e2aabf Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 11 Dec 2019 13:23:04 +0900 Subject: [PATCH] AP_Scripting: example to check battery cycle count --- .../examples/smbus-check-cycles.lua | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libraries/AP_Scripting/examples/smbus-check-cycles.lua diff --git a/libraries/AP_Scripting/examples/smbus-check-cycles.lua b/libraries/AP_Scripting/examples/smbus-check-cycles.lua new file mode 100644 index 0000000000..b2957723f5 --- /dev/null +++ b/libraries/AP_Scripting/examples/smbus-check-cycles.lua @@ -0,0 +1,21 @@ +-- This script checks SMBus battery cycle count + +local warning_cycles = 100 +local battery_instance = 0 + +function update() + if not arming:is_armed() then -- only run check when disarmed + local cycle_count = battery:get_cycle_count(battery_instance) + if cycle_count then + if cycle_count >= warning_cycles then + gcs:send_text(0, string.format("Battery needs replacing (%d cycles)", cycle_count)) + end + else + gcs:send_text(0, "failed to get battery cycles") + end + end + + return update, 15000 -- check again in 15 seconds +end + +return update(), 15000 -- first message may be displayed 15 seconds after start-up