Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 1e42c92

Browse files
committed
Replaced ScpTimer with Rx pattern
1 parent 8f24844 commit 1e42c92

File tree

21 files changed

+138
-134
lines changed

21 files changed

+138
-134
lines changed

ScpCleanWipe/Properties/CommonInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
[assembly: ComVisible(false)]
1414

15-
[assembly: AssemblyVersion("1.6.207.15352")]
16-
[assembly: AssemblyFileVersion("1.6.207.15352")]
15+
[assembly: AssemblyVersion("1.6.207.15353")]
16+
[assembly: AssemblyFileVersion("1.6.207.15353")]

ScpControl.Shared/Properties/CommonInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
[assembly: ComVisible(false)]
1414

15-
[assembly: AssemblyVersion("1.6.207.15352")]
16-
[assembly: AssemblyFileVersion("1.6.207.15352")]
15+
[assembly: AssemblyVersion("1.6.207.15353")]
16+
[assembly: AssemblyFileVersion("1.6.207.15353")]

ScpControl/Bluetooth/BthDevice.Designer.cs

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScpControl/Bluetooth/BthDevice.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.ComponentModel;
33
using System.Net.NetworkInformation;
4+
using System.Reactive.Concurrency;
5+
using System.Reactive.Linq;
46
using ScpControl.ScpCore;
57
using ScpControl.Shared.Core;
68
using ScpControl.Sound;
@@ -13,6 +15,15 @@ namespace ScpControl.Bluetooth
1315
/// </summary>
1416
public partial class BthDevice : BthConnection, IDsDevice
1517
{
18+
#region Private fields
19+
20+
private readonly IObservable<long> _outputReportSchedule = Observable.Interval(TimeSpan.FromMilliseconds(10),
21+
Scheduler.Default);
22+
23+
private IDisposable _outputReportTask;
24+
25+
#endregion
26+
1627
#region Protected fields
1728

1829
protected bool m_Blocked, m_IsIdle = true, m_IsDisconnect;
@@ -51,9 +62,22 @@ public DsConnection Connection
5162

5263
#region Public methods
5364

65+
public ScpHidReport NewHidReport()
66+
{
67+
return new ScpHidReport
68+
{
69+
PadId = PadId,
70+
PadState = State,
71+
ConnectionType = Connection,
72+
Model = Model,
73+
PadMacAddress = DeviceAddress,
74+
BatteryStatus = (byte) Battery
75+
};
76+
}
77+
5478
public virtual bool Start()
5579
{
56-
tmUpdate.Enabled = true;
80+
_outputReportTask = _outputReportSchedule.Subscribe(tick => OnTimer());
5781

5882
// play connection sound
5983
if (GlobalConfiguration.Instance.IsBluetoothConnectSoundEnabled)
@@ -78,24 +102,12 @@ public virtual bool Disconnect()
78102
return BluetoothDevice.HCI_Disconnect(HciHandle) > 0;
79103
}
80104

81-
public ScpHidReport NewHidReport()
82-
{
83-
return new ScpHidReport
84-
{
85-
PadId = PadId,
86-
PadState = State,
87-
ConnectionType = Connection,
88-
Model = Model,
89-
PadMacAddress = DeviceAddress,
90-
BatteryStatus = (byte) Battery
91-
};
92-
}
93-
94105
public virtual bool Stop()
95106
{
96107
if (State == DsState.Connected)
97108
{
98-
tmUpdate.Enabled = false;
109+
if (_outputReportTask != null)
110+
_outputReportTask.Dispose();
99111

100112
State = DsState.Reserved;
101113
m_Packet = 0;
@@ -151,7 +163,7 @@ public override string ToString()
151163
case DsState.Connected:
152164

153165
return string.Format("Pad {0} : {1} {2} - {3} {4:X8} {5}", PadId, Model,
154-
DeviceAddress,
166+
DeviceAddress.AsFriendlyName(),
155167
Connection,
156168
m_Packet,
157169
Battery
@@ -188,7 +200,7 @@ protected virtual void Process(DateTime now)
188200
{
189201
}
190202

191-
protected virtual void On_Timer(object sender, EventArgs e)
203+
protected virtual void OnTimer()
192204
{
193205
if (State != DsState.Connected) return;
194206

@@ -256,4 +268,4 @@ public BthDevice(IBthDevice device, PhysicalAddress master, byte lsb, byte msb)
256268

257269
#endregion
258270
}
259-
}
271+
}

ScpControl/Properties/CommonInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
[assembly: ComVisible(false)]
1414

15-
[assembly: AssemblyVersion("1.6.207.15352")]
16-
[assembly: AssemblyFileVersion("1.6.207.15352")]
15+
[assembly: AssemblyVersion("1.6.207.15353")]
16+
[assembly: AssemblyFileVersion("1.6.207.15353")]

ScpControl/ScpControl.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<AssemblyInfoVersionSettings>
2424
</AssemblyInfoVersionSettings>
2525
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
26-
<AssemblyVersion>1.6.207.15352</AssemblyVersion>
26+
<AssemblyVersion>1.6.207.15353</AssemblyVersion>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2929
<DebugSymbols>true</DebugSymbols>
@@ -240,12 +240,6 @@
240240
<Compile Include="ScpProxy.Designer.cs">
241241
<DependentUpon>ScpProxy.cs</DependentUpon>
242242
</Compile>
243-
<Compile Include="ScpTimer.cs">
244-
<SubType>Component</SubType>
245-
</Compile>
246-
<Compile Include="ScpTimer.Designer.cs">
247-
<DependentUpon>ScpTimer.cs</DependentUpon>
248-
</Compile>
249243
<Compile Include="Properties\Settings.cs" />
250244
<Compile Include="Usb\UsbDevice.cs">
251245
<SubType>Component</SubType>

ScpControl/Usb/UsbDevice.Designer.cs

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)