Skip to content

Commit

Permalink
Led animation support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan-B committed Nov 3, 2013
1 parent 277123b commit d4f6539
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 27 deletions.
2 changes: 2 additions & 0 deletions AR.Drone.Client/AR.Drone.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<Compile Include="Configuration\FlightAnimationType.cs" />
<Compile Include="Configuration\UserboxCommand.cs" />
<Compile Include="Configuration\UserboxCommandType.cs" />
<Compile Include="Configuration\LedAnimation.cs" />
<Compile Include="Configuration\LedAnimationType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AR.Drone.Data\AR.Drone.Data.csproj">
Expand Down
1 change: 0 additions & 1 deletion AR.Drone.Client/Configuration/ConfigurationAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ConfigurationAcquisition
private const int ConfigTimeout = 1000;

private readonly DroneClient _client;
private bool _initialized;

public ConfigurationAcquisition(DroneClient client)
{
Expand Down
43 changes: 43 additions & 0 deletions AR.Drone.Client/Configuration/LedAnimation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using AR.Drone.Data;

namespace AR.Drone.Client
{
public struct LedAnimation
{
public LedAnimation(LedAnimationType type, float frequency, int duration)
: this()
{
Type = type;
Frequency = frequency;
Duration = duration;
}

public LedAnimationType Type { get; private set; }
public float Frequency { get; private set; }
public int Duration { get; private set; }

public static LedAnimation Parse(string value)
{
string[] parts = value.Split(',');
var animation = new LedAnimation();
LedAnimationType type;
int duration;
int ifrequency;
if (parts.Length > 2 && Enum.TryParse(parts[0], out type) && int.TryParse(parts[1], out ifrequency)
&& int.TryParse(parts[2], out duration))
{
animation.Type = type;
animation.Frequency = ConversionHelper.ToSingle(ifrequency);
animation.Duration = duration;
}
return animation;
}

public override string ToString()
{
return string.Format("{0},{1},{2}", (int) Type, ConversionHelper.ToInt(Frequency), Duration);
}
}
}

30 changes: 30 additions & 0 deletions AR.Drone.Client/Configuration/LedAnimationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace AR.Drone.Client
{
public enum LedAnimationType
{
BlinkGreenRed = 0,
BlinkGreen,
BlinkRed,
BlinkOrange,
SnakeGreenRed,
Fire,
Standard,
Red,
Green,
RedSnake,
Blank,
RightMissile,
LeftMissile,
DoubleMissile,
FrontLeftGreenOthersRed,
FrontRightGreenOthersRed,
RearRightGreenOthersRed,
RearLeftGreenOthersRed,
LeftGreenRightRed,
LeftRedRightGreen,
BlinkStandard
}
}

15 changes: 15 additions & 0 deletions AR.Drone.Client/Configuration/SectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ protected FlightAnimation GetFlightAnimation(string index)
return default(FlightAnimation);
}

protected LedAnimation GetLedAnimation(string index)
{
string value;
if (_settings.Items.TryGetValue(FullKey(index), out value))
{
return LedAnimation.Parse(value);
}
return default(LedAnimation);
}

protected UserboxCommand GetUserboxCommand(string index)
{
string value;
Expand Down Expand Up @@ -134,6 +144,11 @@ protected void Set(string index, FlightAnimation value)
Set(index, value.ToString());
}

protected void Set(string index, LedAnimation value)
{
Set(index, value.ToString());
}

protected void Set(string index, UserboxCommand value)
{
Set(index, value.ToString());
Expand Down
4 changes: 2 additions & 2 deletions AR.Drone.Client/Configuration/Sections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ public LedsSection(Settings settings) : base(settings, "leds")
{
}

public String Animation
public LedAnimation LedAnimation
{
get { return GetString("leds_anim"); }
get { return GetLedAnimation("leds_anim"); }
set { Set("leds_anim", value); }
}
}
Expand Down
2 changes: 1 addition & 1 deletion AR.Drone.Client/Configuration/Sections.tt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace AR.Drone.Client.Configuration
ESC();

BSC("LedsSection", "leds");
RWV("Animation", "leds_anim", "String");
RWV("LedAnimation", "leds_anim", "LedAnimation");
ESC();

BSC("DetectSection", "detect");
Expand Down
6 changes: 6 additions & 0 deletions AR.Drone.Data/ConversionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public static float ToSingle(uint value)
float result = BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
return result;
}

public static float ToSingle(int value)
{
float result = BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
return result;
}
}
}
49 changes: 26 additions & 23 deletions AR.Drone.WinApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class MainForm : Form
private readonly DroneClient _droneClient;
private readonly List<PlayerForm> _playerForms;
private readonly VideoPacketDecoderWorker _videoPacketDecoderWorker;
private Settings _configuration;
private Settings _settings;
private VideoFrame _frame;
private Bitmap _frameBitmap;
private uint _frameNumber;
Expand Down Expand Up @@ -142,7 +142,7 @@ private void tmrStateUpdate_Tick(object sender, EventArgs e)
if (_navigationData != null) DumpBranch(node.Nodes, _navigationData);

node = tvInfo.Nodes.GetOrCreate("Configuration");
if (_configuration != null) DumpBranch(node.Nodes, _configuration);
if (_settings != null) DumpBranch(node.Nodes, _settings);

TreeNode vativeNode = tvInfo.Nodes.GetOrCreate("Native");

Expand Down Expand Up @@ -287,7 +287,7 @@ private void btnReadConfig_Click(object sender, EventArgs e)
return;
}

_configuration = task.Result;
_settings = task.Result;
});
configurationTask.Start();
}
Expand All @@ -296,50 +296,53 @@ private void btnSendConfig_Click(object sender, EventArgs e)
{
var sendConfigTask = new Task(() =>
{
if (_configuration == null) _configuration = new Settings();
Settings configuration = _configuration;
if (_settings == null) _settings = new Settings();
Settings settings = _settings;

if (string.IsNullOrEmpty(configuration.Custom.SessionId) ||
configuration.Custom.SessionId == "00000000")
if (string.IsNullOrEmpty(settings.Custom.SessionId) ||
settings.Custom.SessionId == "00000000")
{
// set new session, application and profile
_droneClient.AckControlAndWaitForConfirmation(); // wait for the control confirmation

configuration.Custom.SessionId = Settings.NewId();
_droneClient.Send(configuration);
settings.Custom.SessionId = Settings.NewId();
_droneClient.Send(settings);

_droneClient.AckControlAndWaitForConfirmation();

configuration.Custom.ProfileId = Settings.NewId();
_droneClient.Send(configuration);
settings.Custom.ProfileId = Settings.NewId();
_droneClient.Send(settings);

_droneClient.AckControlAndWaitForConfirmation();

configuration.Custom.ApplicationId = Settings.NewId();
_droneClient.Send(configuration);
settings.Custom.ApplicationId = Settings.NewId();
_droneClient.Send(settings);

_droneClient.AckControlAndWaitForConfirmation();
}

configuration.General.NavdataDemo = false;
configuration.General.NavdataOptions = NavdataOptions.All;
settings.General.NavdataDemo = false;
settings.General.NavdataOptions = NavdataOptions.All;

configuration.Video.BitrateCtrlMode = VideoBitrateControlMode.Dynamic;
configuration.Video.Bitrate = 1000;
configuration.Video.MaxBitrate = 2000;
settings.Video.BitrateCtrlMode = VideoBitrateControlMode.Dynamic;
settings.Video.Bitrate = 1000;
settings.Video.MaxBitrate = 2000;

//settings.Leds.LedAnimation = new LedAnimation(LedAnimationType.BlinkGreenRed, 2.0f, 2);
//settings.Control.FlightAnimation = new FlightAnimation(FlightAnimationType.Wave);

// record video to usb
//configuration.Video.OnUsb = true;
//settings.Video.OnUsb = true;
// usage of MP4_360P_H264_720P codec is a requariment for video recording to usb
//configuration.Video.Codec = VideoCodecType.MP4_360P_H264_720P;
//settings.Video.Codec = VideoCodecType.MP4_360P_H264_720P;
// start
//configuration.Userbox.Command = new UserboxCommand(UserboxCommandType.Start);
//settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Start);
// stop
//configuration.Userbox.Command = new UserboxCommand(UserboxCommandType.Stop);
//settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Stop);


//send all changes in one pice
_droneClient.Send(configuration);
_droneClient.Send(settings);
});
sendConfigTask.Start();
}
Expand Down

0 comments on commit d4f6539

Please sign in to comment.