AP_Scripting: Swap reschedule to be callback, delay

This commit is contained in:
Michael du Breuil 2018-11-03 15:02:58 -07:00 committed by WickedShell
parent ecb1a433b1
commit 2afe72d79f
2 changed files with 6 additions and 8 deletions

View File

@ -31,8 +31,6 @@ int lua_servo_set_output_pwm(lua_State *state) {
}
SRV_Channels::set_output_pwm((SRV_Channel::Aux_servo_function_t)servo_function, output_value);
gcs().send_text(MAV_SEVERITY_INFO, "Set to %d", output_value);
return 0;
}

View File

@ -184,25 +184,25 @@ void lua_scripts::run_next_script(lua_State *L) {
case 2:
{
// sanity check the return types
if (lua_type(L, -2) != LUA_TNUMBER) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: %s did not return a delay (0x%d)", script->name, lua_type(L, -2));
if (lua_type(L, -1) != LUA_TNUMBER) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: %s did not return a delay (0x%d)", script->name, lua_type(L, -1));
lua_pop(L, 2);
remove_script(L, script);
return;
}
if (lua_type(L, -1) != LUA_TFUNCTION) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: %s did not return a function (0x%d)", script->name, lua_type(L, -1));
if (lua_type(L, -2) != LUA_TFUNCTION) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: %s did not return a function (0x%d)", script->name, lua_type(L, -2));
lua_pop(L, 2);
remove_script(L, script);
return;
}
// types match the expectations, go ahead and reschedule
script->next_run_ms = AP_HAL::millis64() + (uint64_t)luaL_checknumber(L, -1);
lua_pop(L, 1);
int old_ref = script->lua_ref;
script->lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
luaL_unref(L, LUA_REGISTRYINDEX, old_ref);
script->next_run_ms = AP_HAL::millis64() + (uint64_t)luaL_checknumber(L, -1);
lua_pop(L, 1);
reschedule_script(script);
break;
}