AP_Scripting: Applets: MissionSelector: fix error on file open and checker errors

This commit is contained in:
Iampete1 2024-11-04 15:36:05 +00:00 committed by Peter Barker
parent 711d7c8493
commit d01ac70c16

View File

@ -2,9 +2,6 @@
-- Must have Mission Reset switch assigned, it will function normally when armed or disarmed -- Must have Mission Reset switch assigned, it will function normally when armed or disarmed
-- but also on the disarm to arm transition, it will load (if file exists) a file in the root named -- but also on the disarm to arm transition, it will load (if file exists) a file in the root named
-- missionH.txt, missionM.txt, or missionH.txt corresponding to the the Mission Reset switch position of High/Mid/Low -- missionH.txt, missionM.txt, or missionH.txt corresponding to the the Mission Reset switch position of High/Mid/Low
-- luacheck: only 0
---@diagnostic disable: need-check-nil
local mission_loaded = false local mission_loaded = false
local rc_switch = rc:find_channel_for_option(24) --AUX FUNC sw for mission restart local rc_switch = rc:find_channel_for_option(24) --AUX FUNC sw for mission restart
@ -15,12 +12,12 @@ end
local function read_mission(file_name) local function read_mission(file_name)
-- Open file try and read header -- Open file try and read header
local file = io.open(file_name,"r") local file = io.open(file_name,"r")
local header = file:read('l') if not file then
if not header then
return update, 1000 --could not read, file probably does not exist return update, 1000 --could not read, file probably does not exist
end end
local header = file:read('l')
-- check header -- check header
assert(string.find(header,'QGC WPL 110') == 1, file_name .. ': incorrect format') assert(string.find(header,'QGC WPL 110') == 1, file_name .. ': incorrect format')
@ -64,7 +61,6 @@ local function read_mission(file_name)
end end
index = index + 1 index = index + 1
end end
file:close()
end end
function update() function update()