-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBthHub.cs
146 lines (110 loc) · 3.65 KB
/
BthHub.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.ComponentModel;
namespace ScpControl
{
public partial class BthHub : ScpHub
{
protected BthDongle Device;
public String Dongle
{
get { return Device.ToString(); }
}
public String Master
{
get { return Device.Local; }
}
public Boolean Pairable
{
get { return m_Started && Device.State == DsState.Connected && Device.Initialised; }
}
public BthHub()
{
InitializeComponent();
}
public BthHub(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public override Boolean Open()
{
Device = new BthDongle();
Device.Arrival += new EventHandler<ArrivalEventArgs>(On_Arrival);
Device.Debug += new EventHandler<DebugEventArgs> (On_Debug);
Device.Report += new EventHandler<ReportEventArgs> (On_Report);
if (!Device.Open()) Device.Close();
return true;
}
public override Boolean Start()
{
m_Started = true;
if (Device.State == DsState.Reserved)
{
Device.Start();
}
return m_Started;
}
public override Boolean Stop()
{
m_Started = false;
if (Device.State == DsState.Connected)
{
Device.Stop();
}
return !m_Started;
}
public override Boolean Close()
{
m_Started = false;
return Device.Close();
}
public override Boolean Suspend()
{
Stop();
Close();
return base.Suspend();
}
public override Boolean Resume()
{
Open();
Start();
return base.Resume();
}
public override DsPadId Notify(ScpDevice.Notified Notification, String Class, String Path)
{
LogDebug(String.Format("++ Notify [{0}] [{1}] [{2}]", Notification, Class, Path));
switch (Notification)
{
case ScpDevice.Notified.Arrival:
{
if (Device.State != DsState.Connected)
{
BthDongle Arrived = new BthDongle();
if (Arrived.Open(Path))
{
LogDebug(String.Format("-- Device Arrival [{0}]", Arrived.Local));
Device.Close();
Device = Arrived;
Device.Arrival += new EventHandler<ArrivalEventArgs>(On_Arrival);
Device.Debug += new EventHandler<DebugEventArgs> (On_Debug );
Device.Report += new EventHandler<ReportEventArgs> (On_Report );
if (m_Started) Device.Start();
break;
}
Arrived.Close();
Arrived.Dispose();
}
}
break;
case ScpDevice.Notified.Removal:
if (Device.Path == Path)
{
LogDebug(String.Format("-- Device Removal [{0}]", Device.Local));
Device.Stop();
}
break;
}
return DsPadId.None;
}
}
}