增加LED灯控制
This commit is contained in:
parent
ce44e595ff
commit
2d4217d2f8
@ -108,6 +108,12 @@ namespace Plane.Copters
|
||||
/// <returns>表示异步设置参数操作的 <see cref="Task"/> 实例。</returns>
|
||||
/// <exception cref="System.TimeoutException">操作超时。</exception>
|
||||
Task SetParamAsync(string paramName, float value, int millisecondsTimeout = Timeout.Infinite);
|
||||
bool GetShowLEDAsync();
|
||||
|
||||
Task SetShowLEDAsync(bool Ledon);
|
||||
Task SetShowLEDFlashAsync(int Flashtype, int millisecondsTime);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开始对频。
|
||||
|
@ -54,7 +54,15 @@ namespace Plane.Communication
|
||||
var address = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault(addr => addr.AddressFamily == AddressFamily.InterNetwork && addr.GetAddressBytes()[0] == 192);
|
||||
if (address == null) return false;
|
||||
_listener = new TcpListener(address, TCP_LOCAL_PORT);
|
||||
try
|
||||
{
|
||||
_listener.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// RaiseExceptionThrown(ex);
|
||||
return false;
|
||||
}
|
||||
_shouldListen = true;
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
|
@ -58,6 +58,19 @@ namespace Plane.Copters
|
||||
{
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
public Task SetShowLEDFlashAsync(int Flashtype, int millisecondsTime)
|
||||
{
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
|
||||
public bool GetShowLEDAsync()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public Task SetShowLEDAsync(bool Ledon)
|
||||
{
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StartPairingAsync()
|
||||
{
|
||||
|
@ -84,6 +84,13 @@ namespace Plane.Copters
|
||||
/// </summary>
|
||||
private double _targetLng;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// FlyTo 的目标经度。
|
||||
/// </summary>
|
||||
private bool _ShowLED;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 使用 <see cref="SynchronizationContext.Current"/> 创建 <see cref="FakeCopter"/> 实例。
|
||||
/// </summary>
|
||||
@ -258,6 +265,35 @@ namespace Plane.Copters
|
||||
// TODO: 林俊清, 20150807, 实现仿真的 SetParamAsync。
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
public bool GetShowLEDAsync()
|
||||
{
|
||||
return _ShowLED;
|
||||
}
|
||||
public Task SetShowLEDAsync(bool Ledon)
|
||||
{
|
||||
_ShowLED = Ledon;
|
||||
RaiseLocationChanged();
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
public Task SetShowLEDFlashAsync(int Flashtype, int millisecondsTime)
|
||||
{
|
||||
bool Ledison;
|
||||
Ledison = GetShowLEDAsync();
|
||||
if (!Ledison)
|
||||
{
|
||||
SetShowLEDAsync(true);
|
||||
Task.Delay(millisecondsTime).ConfigureAwait(false);
|
||||
SetShowLEDAsync(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetShowLEDAsync(false);
|
||||
Task.Delay(millisecondsTime).ConfigureAwait(false);
|
||||
SetShowLEDAsync(true);
|
||||
}
|
||||
|
||||
return TaskUtils.CompletedTask;
|
||||
}
|
||||
|
||||
public void SetProperties(
|
||||
string id = null, //"Junqing's Drone",
|
||||
|
@ -18,6 +18,7 @@ namespace Plane.Copters
|
||||
private int _setModeCount = 0;
|
||||
|
||||
private int _takeOffCount;
|
||||
private bool _showLed=false;
|
||||
|
||||
#if PRIVATE
|
||||
public PLCopter(IConnection connection, SynchronizationContext uiSyncContext, bool autoSendHeartbeat = true, bool autoRequestData = true) : base(uiSyncContext)
|
||||
@ -113,6 +114,62 @@ namespace Plane.Copters
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public bool GetShowLEDAsync()
|
||||
{
|
||||
return _showLed;
|
||||
|
||||
/*
|
||||
int showled;
|
||||
showled=(int)await _internalCopter.GetParamAsync("NTF_SHOWLED", 0).ConfigureAwait(false);
|
||||
if (showled == 0)
|
||||
return false;
|
||||
else return true;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task SetShowLEDAsync(bool Ledon)
|
||||
{
|
||||
if (Ledon)
|
||||
await SetParamAsync("NTF_SHOWLED", 1, 5000);
|
||||
else
|
||||
await SetParamAsync("NTF_SHOWLED", 0, 5000);
|
||||
_showLed = Ledon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 闪烁SHOWLED,如果当前没亮,那就亮一下,如果本来就是亮的,那就暗一下
|
||||
/// </summary>
|
||||
/// <param name="Flashtype">闪烁类型,目前没用</param>
|
||||
/// <param name="millisecondsTime">闪烁时间ms</param>
|
||||
/// <returns></returns>
|
||||
public async Task SetShowLEDFlashAsync(int Flashtype,int millisecondsTime)
|
||||
{
|
||||
bool Ledison;
|
||||
Ledison= GetShowLEDAsync();
|
||||
if (!Ledison)
|
||||
{
|
||||
await SetShowLEDAsync(true);
|
||||
await Task.Delay(millisecondsTime).ConfigureAwait(false);
|
||||
await SetShowLEDAsync(false);
|
||||
await SetShowLEDAsync(false);
|
||||
}else
|
||||
{
|
||||
await SetShowLEDAsync(false);
|
||||
await Task.Delay(millisecondsTime).ConfigureAwait(false);
|
||||
await SetShowLEDAsync(true);
|
||||
await SetShowLEDAsync(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task SetParamAsync(string paramName, float paramValue, int millisecondsTimeout = Timeout.Infinite)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
Loading…
Reference in New Issue
Block a user