AP_Scripting: fix switch check in ahrs-source

This commit is contained in:
tajisoft 2021-10-11 13:09:20 +09:00 committed by Peter Barker
parent 5f6af3567a
commit 68274ff996
3 changed files with 82 additions and 73 deletions

View File

@ -64,11 +64,12 @@ end
function update()
-- check switches are configured
-- at least one switch must be set
-- source selection from RCx_FUNCTION = 90 (EKF Source Select)
-- auto source from RCx_FUNCTION = 300 (Scripting1)
local rc_function_source = rc:find_channel_for_option(90)
local rc_function_auto = rc:find_channel_for_option(300)
if not rc_function_source or not rc_function_auto then
if not rc_function_source and not rc_function_auto then
gcs:send_text(0, "ahrs-source-gps-optflow.lua: RCx_FUNCTION=90 or 300 not set!")
return update, 1000
end
@ -166,7 +167,8 @@ function update()
play_source_tune(source_prev) -- alert user of source whether changed or not
end
-- read auto source switch position from RCx_FUNCTION = 300 (Scripting1)
-- if auto switch exists then read auto source switch position from RCx_FUNCTION = 300 (Scripting1)
if rc_function_auto then
local sw_auto_pos = rc_function_auto:get_aux_switch_pos()
if sw_auto_pos ~= sw_auto_pos_prev then -- check for changes in source auto switch position
sw_auto_pos_prev = sw_auto_pos -- record new switch position so we can detect changes
@ -193,6 +195,7 @@ function update()
end
play_source_tune(source_prev)
end
end
-- auto switching
if auto_switch and (auto_source >= 0) and (auto_source ~= source_prev) then

View File

@ -35,11 +35,12 @@ end
function update()
-- check switches are configured
-- at least one switch must be set
-- source selection from RCx_FUNCTION = 90 (EKF Source Select)
-- auto source from RCx_FUNCTION = 300 (Scripting1)
local rc_function_source = rc:find_channel_for_option(90)
local rc_function_auto = rc:find_channel_for_option(300)
if (rc_function_source == nil) or (rc_function_auto == nil) then
if (rc_function_source == nil) and (rc_function_auto == nil) then
gcs:send_text(0, "ahrs-source-gps-wheelencoders.lua: RCx_FUNCTION=90 or 300 not set!")
return update, 1000
end
@ -102,6 +103,7 @@ function update()
end
-- read auto source switch position from RCx_FUNCTION = 300 (Scripting1)
if rc_function_auto then
local sw_auto_pos = rc_function_auto:get_aux_switch_pos()
if sw_auto_pos ~= sw_auto_pos_prev then -- check for changes in source auto switch position
sw_auto_pos_prev = sw_auto_pos -- record new switch position so we can detect changes
@ -128,6 +130,7 @@ function update()
end
play_source_tune(source_prev)
end
end
-- auto switching
if auto_switch and (auto_source >= 0) and (auto_source ~= source_prev) then

View File

@ -42,11 +42,12 @@ end
function update()
-- check switches are configured
-- at least one switch must be set
-- source selection from RCx_FUNCTION = 90 (EKF Source Select)
-- auto source from RCx_FUNCTION = 300 (Scripting1)
local rc_function_source = rc:find_channel_for_option(90)
local rc_function_auto = rc:find_channel_for_option(300)
if (rc_function_source == nil) or (rc_function_auto == nil) then
if (rc_function_source == nil) and (rc_function_auto == nil) then
gcs:send_text(0, "ahrs-source.lua: RCx_FUNCTION=90 or 300 not set!")
return update, 1000
end
@ -140,6 +141,7 @@ function update()
end
-- read auto source switch position from RCx_FUNCTION = 300 (Scripting1)
if rc_function_auto then
local sw_auto_pos = rc_function_auto:get_aux_switch_pos()
if sw_auto_pos ~= sw_auto_pos_prev then -- check for changes in source auto switch position
sw_auto_pos_prev = sw_auto_pos -- record new switch position so we can detect changes
@ -166,6 +168,7 @@ function update()
end
play_source_tune(source_prev)
end
end
-- auto switching
if auto_switch and (auto_source >= 0) and (auto_source ~= source_prev) then