Skip to content

Commit

Permalink
Update MissionRotation.lua
Browse files Browse the repository at this point in the history
Second attempt: fixed duplicate message sending problem in mission loading.
  • Loading branch information
robustini authored Dec 2, 2024
1 parent 8186d84 commit a96fa59
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions libraries/AP_Scripting/applets/MissionRotation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ if not rc_switch then
end

local current_mission_index = 0
local max_missions = 6 -- Aggiornato a 6 poiché hai fino a mission6.txt
local max_missions = 9
local high_timer = 0
local latest_mission_loaded = -1 -- Track the last loaded mission

local function read_mission(file_name)
if vehicle:get_mode() == 3 then
Expand Down Expand Up @@ -79,14 +78,14 @@ if not read_mission("mission0.txt") then
end

local function load_next_mission()
if vehicle:get_mode() == 3 then
return
end

current_mission_index = (current_mission_index + 1) % (max_missions + 1)
local file_name = string.format("mission%d.txt", current_mission_index)

if read_mission(file_name) then
if latest_mission_loaded ~= current_mission_index then
gcs:send_text(MAV_SEVERITY.WARNING, "Loaded mission: " .. file_name)
latest_mission_loaded = current_mission_index
end
gcs:send_text(MAV_SEVERITY.WARNING, "Loaded mission: " .. file_name)
end
end

Expand All @@ -106,11 +105,11 @@ function update()
end
else
if high_timer > 0 and high_timer < 3 then
load_next_mission() -- Load next mission if switched back before 3 seconds
load_next_mission()
end
high_timer = 0
end

return update, 1000
end

Expand Down

0 comments on commit a96fa59

Please sign in to comment.