1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FlyADBase;
using Misc;
using System.Windows.Threading;
namespace Flyad7_WPF
{
/// <summary>
/// 来回走
/// </summary>
public class AutoForwBackw : INotifyPropertyChanged
{
DispatcherTimer timer;
FlyAD7 flyad;
public bool FB_Enable { get; set; }
public int FB_Pos1 { get; set; } = 1000;
public int FB_Pos2 { get; set; } = 3000;
public AutoForwBackw(FlyAD7 flyad)
{
this.flyad = flyad;
FB_init();
}
void timer_Tick(object sender, EventArgs e)
{
if (!flyad.IsConnected)
{
FB_Enable = false;
}
if (!flyad.IsFinish)
return;
if (flyad.IsTimeToPushTimeGridAdv)//推送完成
return;
if (Math.Abs(FB_Pos1 - flyad.Position) > Math.Abs(FB_Pos2 - flyad.Position))
{
flyad.Runto(FB_Pos1);
}
else
{
flyad.Runto(FB_Pos2);
}
}
void FB_init()
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(timer_Tick);
FB_Enable = false;
this.PropertyChanged += AutoForwBackw_PropertyChanged;
}
private void AutoForwBackw_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(FB_Enable))
{
if (FB_Enable)
{
timer.Start();
}
else
{
timer.Stop();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}