Skip to content

Commit

Permalink
Added orderCommandList() to be chronological
Browse files Browse the repository at this point in the history
Fixes #51
  • Loading branch information
Peppie84 committed Jan 4, 2015
1 parent 984f89e commit bfe356e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/RemoteTech/FlightComputer/FlightComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void Enqueue(ICommand cmd, bool ignore_control = false, bool ignore_delay
if (pos < 0)
{
mCommandQueue.Insert(~pos, cmd);
orderCommandList();
}
}

Expand Down Expand Up @@ -312,6 +313,26 @@ public void updatePIDParameters()
initPIDParameters();
}

/// <summary>
/// Orders the mCommand queue to be chronological
/// </summary>
public void orderCommandList()
{
if (mCommandQueue.Count <= 0) return;

List<ICommand> backupList = mCommandQueue;
// sort the backup queue
backupList = backupList.OrderBy(s => (s.TimeStamp + s.ExtraDelay)).ToList();
// clear the old queue
mCommandQueue.Clear();

// add the sorted queue
foreach(var command in backupList)
{
mCommandQueue.Add(command);
}
}

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit bfe356e

Please sign in to comment.