Skip to content

Commit

Permalink
Updated button dialog:
Browse files Browse the repository at this point in the history
- Removed checkboxes, used label instead
  • Loading branch information
theone1984 committed May 19, 2011
1 parent 14fa821 commit 097bfd1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 26 deletions.
6 changes: 3 additions & 3 deletions ARDroneInput/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ private void AddNewDevices()
{
List<GenericInput> newDevices = new List<GenericInput>();

//newDevices.AddRange(KeyboardInput.GetNewInputDevices(windowHandle, inputDevices));
//newDevices.AddRange(JoystickInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(KeyboardInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(JoystickInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(WiiMoteInput.GetNewInputDevices(windowHandle, inputDevices));
//newDevices.AddRange(SpeechInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(SpeechInput.GetNewInputDevices(windowHandle, inputDevices));

foreach (GenericInput inputDevice in newDevices)
{
Expand Down
11 changes: 1 addition & 10 deletions ARDroneUI_WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Label Content="Roll" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Style="{StaticResource styleContentDescription}" Margin="20,5,0,0" />
Expand All @@ -60,13 +57,7 @@
<Label Name="labelInputYaw" Content="+0.000" Grid.Row="2" Grid.Column="1" Style="{StaticResource styleContentDescription}" />
<Label Content="Gaz" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="0" Style="{StaticResource styleContentDescription}" Margin="20,0,0,0" />
<Label Name="labelInputGaz" Content="+0.000" Grid.Row="3" Grid.Column="1" Style="{StaticResource styleContentDescription}" />
<CheckBox Name="checkBoxInputTakeoff" Content="Take off" Grid.Row="4" Grid.Column="0" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputLand" Content="Land" Height="16" Grid.Row="4" Grid.Column="1" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputEmergency" Content="Emergency" Grid.Row="5" Grid.Column="0" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputFlatTrim" Content="Flat trim" Grid.Row="5" Grid.Column="1" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputHover" Content="Hover" Grid.Row="6" Grid.Column="0" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputChangeCamera" Content="Camera" Grid.Row="6" Grid.Column="1" Style="{StaticResource styleInputCheckBox}" />
<CheckBox Name="checkBoxInputSpecialAction" Content="Sp. action" Grid.Row="7" Grid.Column="0" Style="{StaticResource styleInputCheckBox}" Margin="7,4,3,10" />
<Label Name="labelCurrentBooleanInput" Content="No button" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,10,10,10" FontSize="14" FontWeight="Bold" />
</Grid>
</GroupBox>
<GroupBox Header="Status">
Expand Down
108 changes: 95 additions & 13 deletions ARDroneUI_WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ namespace ARDrone.UI
{
public partial class MainWindow : Window
{
private readonly TimeSpan booleanInputTimeout = new TimeSpan(0, 0, 0, 0, 250);

private delegate void OutputEventHandler(String output);

private DispatcherTimer timerStatusUpdate;
private DispatcherTimer timerVideoUpdate;
private DispatcherTimer timerHudStatusUpdate;

private VideoRecorder videoRecorder = null;
private SnapshotRecorder snapshotRecorder = null;
private VideoRecorder videoRecorder;
private SnapshotRecorder snapshotRecorder;

private InstrumentsManager instrumentsManager;
private HudInterface hudInterface;

private InstrumentsManager instrumentsManager = null;
private HudInterface hudInterface = null;
private ARDrone.Input.InputManager inputManager;
private Dictionary<String, DateTime> booleanInputFadeout;

ARDrone.Input.InputManager inputManager = null;
private DroneControl droneControl = null;
private DroneControl droneControl;

int frameCountSinceLastCapture = 0;
DateTime lastFrameRateCaptureTime;
Expand Down Expand Up @@ -132,6 +136,8 @@ public void InitializeInputManager()
inputManager.NewInputState += inputManager_NewInputState;
inputManager.NewInputDevice += inputManager_NewInputDevice;
inputManager.InputDeviceLost += inputManager_InputDeviceLost;

booleanInputFadeout = new Dictionary<String, DateTime>();
}

public void InitializeAviationControls()
Expand Down Expand Up @@ -359,6 +365,8 @@ private void UpdateStatus()
labelStatusConnected.Content = droneControl.IsConnected.ToString();
labelStatusFlying.Content = droneControl.IsFlying.ToString();
labelStatusHovering.Content = droneControl.IsHovering.ToString();

UpdateCurrentBooleanInputState();
}

private void ChangeCameraStatus()
Expand Down Expand Up @@ -417,13 +425,87 @@ private void UpdateDroneState(InputState inputState)
labelInputYaw.Content = String.Format("{0:+0.000;-0.000;+0.000}", -inputState.Yaw);
labelInputGaz.Content = String.Format("{0:+0.000;-0.000;+0.000}", -inputState.Gaz);

checkBoxInputTakeoff.IsChecked = inputState.TakeOff;
checkBoxInputLand.IsChecked = inputState.Land;
checkBoxInputHover.IsChecked = inputState.Hover;
checkBoxInputEmergency.IsChecked = inputState.Emergency;
checkBoxInputFlatTrim.IsChecked = inputState.FlatTrim;
checkBoxInputChangeCamera.IsChecked = inputState.CameraSwap;
checkBoxInputSpecialAction.IsChecked = inputState.SpecialAction;
UpdateCurrentBooleanInputState(inputState);
}

private void UpdateCurrentBooleanInputState()
{
RemoveOldBooleanInputStates();

labelCurrentBooleanInput.Content = GetCurrentBooleanInputStates();
}

private void UpdateCurrentBooleanInputState(InputState inputState)
{
RemoveOldBooleanInputStates();
AddNewBooleanInputStates(inputState);

labelCurrentBooleanInput.Content = GetCurrentBooleanInputStates();
}

private void AddNewBooleanInputStates(InputState inputState)
{
if (inputState.TakeOff)
AddNewBooleanInputState("TakeOff");
if (inputState.Land)
AddNewBooleanInputState("Land");
if (inputState.Emergency)
AddNewBooleanInputState("Emergency");
if (inputState.FlatTrim)
AddNewBooleanInputState("FlatTrim");
if (inputState.Hover)
AddNewBooleanInputState("Hover");
if (inputState.CameraSwap)
AddNewBooleanInputState("Camera");
if (inputState.SpecialAction)
AddNewBooleanInputState("Special");
}

private void AddNewBooleanInputState(String command)
{
DateTime expirationDate = DateTime.Now + booleanInputTimeout;
if (booleanInputFadeout.ContainsKey(command))
booleanInputFadeout[command] = expirationDate;
else
booleanInputFadeout.Add(command, expirationDate);
}

private void RemoveOldBooleanInputStates()
{
List<String> keysToDelete = new List<String>();
foreach (KeyValuePair<String, DateTime> keyValuePair in booleanInputFadeout)
{
String command = keyValuePair.Key;
DateTime expirationDate = keyValuePair.Value;

if (expirationDate < DateTime.Now)
keysToDelete.Add(command);
}

foreach (String key in keysToDelete)
booleanInputFadeout.Remove(key);
}

private String GetCurrentBooleanInputStates()
{
String commandText = "";

List<String> commands = new List<String>();
foreach (KeyValuePair<String, DateTime> keyValuePair in booleanInputFadeout)
commands.Add(keyValuePair.Key);

for (int i = 0; i < commands.Count; i++)
{
commandText += commands[i];

if (i != commands.Count - 1)
commandText += ", ";
}

if (commandText == "")
commandText = "No buttons";

return commandText;
}

private void SendDroneCommands(InputState inputState)
Expand Down

0 comments on commit 097bfd1

Please sign in to comment.