AP_Scripting: add binding for BattMonitor's get_cycle_count method

This commit is contained in:
Randy Mackay
2019-12-18 15:54:42 +11:00
committed by Andrew Tridgell
parent 44a8702d94
commit fdf8d4b2ee
2 changed files with 25 additions and 0 deletions
@@ -1232,6 +1232,29 @@ static int AP_GPS_num_sensors(lua_State *L) {
return 1;
}
static int AP_BattMonitor_get_cycle_count(lua_State *L) {
AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
if (ud == nullptr) {
return luaL_argerror(L, 1, "battery not supported on this firmware");
}
binding_argcheck(L, 2);
const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
uint16_t data_5003 = {};
const bool data = ud->get_cycle_count(
data_2,
data_5003);
if (data) {
lua_pushinteger(L, data_5003);
} else {
lua_pushnil(L);
}
return 1;
}
static int AP_BattMonitor_get_temperature(lua_State *L) {
AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
if (ud == nullptr) {
@@ -1793,6 +1816,7 @@ const luaL_Reg AP_GPS_meta[] = {
};
const luaL_Reg AP_BattMonitor_meta[] = {
{"get_cycle_count", AP_BattMonitor_get_cycle_count},
{"get_temperature", AP_BattMonitor_get_temperature},
{"overpower_detected", AP_BattMonitor_overpower_detected},
{"has_failsafed", AP_BattMonitor_has_failsafed},