Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Replaced ScpTimer with Rx pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Dec 19, 2015
1 parent 8f24844 commit 1e42c92
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 134 deletions.
4 changes: 2 additions & 2 deletions ScpCleanWipe/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.207.15352")]
[assembly: AssemblyFileVersion("1.6.207.15352")]
[assembly: AssemblyVersion("1.6.207.15353")]
[assembly: AssemblyFileVersion("1.6.207.15353")]
4 changes: 2 additions & 2 deletions ScpControl.Shared/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.207.15352")]
[assembly: AssemblyFileVersion("1.6.207.15352")]
[assembly: AssemblyVersion("1.6.207.15353")]
[assembly: AssemblyFileVersion("1.6.207.15353")]
11 changes: 0 additions & 11 deletions ScpControl/Bluetooth/BthDevice.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 30 additions & 18 deletions ScpControl/Bluetooth/BthDevice.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.ComponentModel;
using System.Net.NetworkInformation;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using ScpControl.ScpCore;
using ScpControl.Shared.Core;
using ScpControl.Sound;
Expand All @@ -13,6 +15,15 @@ namespace ScpControl.Bluetooth
/// </summary>
public partial class BthDevice : BthConnection, IDsDevice
{
#region Private fields

private readonly IObservable<long> _outputReportSchedule = Observable.Interval(TimeSpan.FromMilliseconds(10),
Scheduler.Default);

private IDisposable _outputReportTask;

#endregion

#region Protected fields

protected bool m_Blocked, m_IsIdle = true, m_IsDisconnect;
Expand Down Expand Up @@ -51,9 +62,22 @@ public DsConnection Connection

#region Public methods

public ScpHidReport NewHidReport()
{
return new ScpHidReport
{
PadId = PadId,
PadState = State,
ConnectionType = Connection,
Model = Model,
PadMacAddress = DeviceAddress,
BatteryStatus = (byte) Battery
};
}

public virtual bool Start()
{
tmUpdate.Enabled = true;
_outputReportTask = _outputReportSchedule.Subscribe(tick => OnTimer());

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

public ScpHidReport NewHidReport()
{
return new ScpHidReport
{
PadId = PadId,
PadState = State,
ConnectionType = Connection,
Model = Model,
PadMacAddress = DeviceAddress,
BatteryStatus = (byte) Battery
};
}

public virtual bool Stop()
{
if (State == DsState.Connected)
{
tmUpdate.Enabled = false;
if (_outputReportTask != null)
_outputReportTask.Dispose();

State = DsState.Reserved;
m_Packet = 0;
Expand Down Expand Up @@ -151,7 +163,7 @@ public override string ToString()
case DsState.Connected:

return string.Format("Pad {0} : {1} {2} - {3} {4:X8} {5}", PadId, Model,
DeviceAddress,
DeviceAddress.AsFriendlyName(),
Connection,
m_Packet,
Battery
Expand Down Expand Up @@ -188,7 +200,7 @@ protected virtual void Process(DateTime now)
{
}

protected virtual void On_Timer(object sender, EventArgs e)
protected virtual void OnTimer()
{
if (State != DsState.Connected) return;

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

#endregion
}
}
}
4 changes: 2 additions & 2 deletions ScpControl/Properties/CommonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.6.207.15352")]
[assembly: AssemblyFileVersion("1.6.207.15352")]
[assembly: AssemblyVersion("1.6.207.15353")]
[assembly: AssemblyFileVersion("1.6.207.15353")]
8 changes: 1 addition & 7 deletions ScpControl/ScpControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<AssemblyInfoVersionSettings>
</AssemblyInfoVersionSettings>
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
<AssemblyVersion>1.6.207.15352</AssemblyVersion>
<AssemblyVersion>1.6.207.15353</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -240,12 +240,6 @@
<Compile Include="ScpProxy.Designer.cs">
<DependentUpon>ScpProxy.cs</DependentUpon>
</Compile>
<Compile Include="ScpTimer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ScpTimer.Designer.cs">
<DependentUpon>ScpTimer.cs</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.cs" />
<Compile Include="Usb\UsbDevice.cs">
<SubType>Component</SubType>
Expand Down
10 changes: 0 additions & 10 deletions ScpControl/Usb/UsbDevice.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e42c92

Please sign in to comment.