Skip to content

Commit

Permalink
-Fixed When AutoConnect enabled and App minimized app was not restore…
Browse files Browse the repository at this point in the history
… showing state #43

- Renewed app certificate
  • Loading branch information
WebSpiderTeam committed Aug 23, 2023
1 parent 5a861ac commit 6feb606
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 396 deletions.
17 changes: 16 additions & 1 deletion BluetoothDMM WPF/Bluetooth.Dmm/HeartRateMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class HeartRateMonitor
private BluetoothAttribute _heartRateAttribute;
private GattCharacteristic _heartRateMeasurementCharacteristic;
private byte[] olddata = { 0 };
private Stopwatch threatTime;
private int maxTime;

/// <summary>
/// Occurs when [connection status changed].
Expand Down Expand Up @@ -305,9 +307,14 @@ private void DeviceConnectionStatusChanged(BluetoothLEDevice sender, object args

private void HeartRateValueChanged(GattCharacteristic sender, GattValueChangedEventArgs e)
{
#if DEBUG
threatTime = new Stopwatch();
threatTime.Start();
#endif
CryptographicBuffer.CopyToByteArray(e.CharacteristicValue, out byte[] data);
if (!Enumerable.SequenceEqual(data, olddata))
{

var GattData = Utilities.ParseHeartRateValue(data, LogData);
if ((string)GattData[0] != "Error")
{
Expand All @@ -334,9 +341,17 @@ private void HeartRateValueChanged(GattCharacteristic sender, GattValueChangedEv
};
olddata = data;
OnRateChanged(args);

}
}

#if DEBUG
threatTime.Stop();
if (threatTime.ElapsedMilliseconds > 0)
{
maxTime = (int)threatTime.ElapsedMilliseconds > maxTime ? (int)threatTime.ElapsedMilliseconds : maxTime;
Console.WriteLine("Elapsed={0} ms Max={1}", threatTime.ElapsedMilliseconds, maxTime);
}
#endif
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion BluetoothDMM WPF/Bluetooth.Dmm/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ public static ArrayList ParseHeartRateValue(byte[] data, bool LogData)
// Testing other device data
var TestDevice = 0;
#if DEBUG// In debug mode do not custom-handle the exception, let Visual Studio handle it
TestDevice = 4;
TestDevice = 0;
#else
TestDevice = 0;
#endif
Expand Down
5 changes: 3 additions & 2 deletions BluetoothDMM WPF/BluetoothDMM/BluetoothDMM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
<ApplicationIcon>Logo.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>DF7CC3A7101539D266AABA8702FFB242FDA756B7</ManifestCertificateThumbprint>
<ManifestCertificateThumbprint>6888F40556FF4093A9543521ABC0D5068E596F70</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>BluetoothDMM_TemporaryKey.pfx</ManifestKeyFile>
<ManifestKeyFile>BluetoothDMM_1_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
Expand Down Expand Up @@ -263,6 +263,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.zh-CN.resx" />
<EmbeddedResource Include="Properties\Resources.zh-TW.resx" />
<None Include="BluetoothDMM_1_TemporaryKey.pfx" />
<None Include="BluetoothDMM_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
Expand Down
14 changes: 6 additions & 8 deletions BluetoothDMM WPF/BluetoothDMM/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
<Path Fill="Wheat" Data="m 172.74609,71.828125 c -4.89848,0.07276 -9.83122,1.833867 -13.38069,5.269269 -4.58189,4.361543 -6.94441,10.512901 -8.16263,16.602277 -1.39568,7.103479 -1.53717,14.401709 -1.09517,21.609169 0.51035,6.77715 1.71845,13.71026 5.12923,19.68226 2.52107,4.46574 6.61188,8.15437 11.58348,9.62023 4.54199,1.3305 9.52172,1.28972 14.00602,-0.25312 4.85158,-1.66757 8.69366,-5.50999 11.05117,-9.99162 3.22881,-6.08235 4.33429,-13.02835 4.77843,-19.82658 0.39435,-7.75769 0.18463,-15.635838 -1.66808,-23.212791 -1.43926,-5.790149 -4.1373,-11.553264 -8.89091,-15.345762 -3.73402,-3.028037 -8.59765,-4.30785 -13.35085,-4.153332 z M 36.865234,74.550781 c -5.976779,23.257273 -11.957104,46.513639 -17.93164,69.771489 4.548828,0 9.097656,0 13.646484,0 1.22195,-5.61907 2.449593,-11.2369 3.673828,-16.85547 4.752604,0 9.505209,0 14.257813,0 1.253493,5.61858 2.510793,11.23631 3.761719,16.85547 4.720703,0 9.441406,0 14.162109,0 -5.660465,-23.75728 -11.317573,-47.515352 -16.974609,-71.273442 -4.736329,0 -9.472657,0 -14.208985,0 -0.128906,0.500651 -0.257812,1.001302 -0.386719,1.501953 z m 31.806641,0.498047 c 0.0144,14.674009 -0.02888,29.348372 0.02177,44.022162 0.126156,4.88184 0.333603,9.85117 1.804403,14.54424 1.540248,4.5849 5.051616,8.56471 9.636417,10.25091 4.628639,1.80788 9.76845,2.05196 14.64232,1.27935 3.986576,-0.63892 7.789405,-2.51877 10.549425,-5.49199 2.60897,-2.65807 4.13365,-6.21268 4.67678,-9.86775 1.28489,-7.67409 0.84773,-15.48598 0.93256,-23.23106 0,-6.680992 0,-13.361982 0,-20.042971 4.37304,0 8.74609,0 13.11914,0 0,19.270181 0,38.540361 0,57.810551 4.63021,0 9.26041,0 13.89062,0 0,-19.27019 0,-38.54037 0,-57.810551 4.45183,0 8.90365,0 13.35547,0 0,-4.48763 0,-8.975261 0,-13.462891 -17.75,0 -35.5,0 -53.249998,0 -0.01449,15.303709 0.02918,30.607762 -0.02219,45.911252 -0.09714,2.93997 -0.07605,5.93382 -0.808452,8.80074 -0.587476,2.08246 -2.210138,4.00342 -4.436244,4.33615 -2.454152,0.439 -5.245646,0.40152 -7.358111,-1.09111 -1.94356,-1.46072 -2.571343,-3.96558 -2.747061,-6.27113 -0.141654,-1.29801 -0.215979,-2.68047 -0.259663,-3.87149 -0.146472,-6.35846 -0.03417,-12.72023 -0.06945,-19.08004 0,-9.578122 0,-19.156247 0,-28.734372 -4.559244,0 -9.118489,0 -13.677734,0 0,0.666667 0,1.333333 0,2 z m 105.261715,9.908203 c 2.18633,0.07106 4.13346,1.477585 5.14591,3.374845 1.67064,3.110035 2.3055,6.652746 2.79259,10.114672 0.10009,0.736523 0.16728,1.482487 0.23729,2.121812 0.14938,1.6773 0.24895,3.34862 0.2955,4.95287 0.0841,2.84091 0.0565,5.77282 -0.092,8.51688 -0.30004,4.7107 -0.8014,9.5209 -2.6477,13.91001 -0.91434,2.17746 -2.78178,4.1739 -5.25256,4.37744 -2.31408,0.32511 -4.86347,-0.46775 -6.24132,-2.43716 -1.75593,-2.428 -2.33871,-5.45491 -2.92513,-8.33419 -0.52574,-2.89139 -0.7776,-5.82551 -0.90634,-8.75929 -0.04,-1.018 -0.0736,-2.30173 -0.0772,-3.42459 0.003,-6.16487 0.27401,-12.445301 2.15959,-18.361555 0.76094,-2.40767 2.19358,-4.999679 4.77356,-5.766476 0.88222,-0.277821 1.81866,-0.338526 2.73776,-0.285268 z M 47.654297,114.69727 c -2.851563,0 -5.703125,0 -8.554688,0 1.420573,-6.49349 2.841146,-12.98698 4.261719,-19.480473 1.43099,6.493493 2.861979,12.986983 4.292969,19.480473 z" />
</Viewbox>
</Button>
<Button x:Name="cmdC" Tag="EA EC 70 E3 A2 C1 32 71 64 9B" Height="40" Width="40" Background="#A0000000" Style="{StaticResource pb_style}" Margin="1,0" Click="Commands_Click">
<Button x:Name="cmdC" Tag="EA EC 70 E3 A2 C1 32 71 64 9B" Height="40" Width="40" Background="#A0000000" Style="{StaticResource pb_style}" Margin="1,1" Click="Commands_Click">
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" Height="25" Width="25" HorizontalAlignment="Right">
<TextBlock Text="°C" TextAlignment="Center" Width="30" Height="25" FontSize="18" FontWeight="Bold" Margin="-3,0,0,0"/>
</StackPanel>
Expand Down Expand Up @@ -630,22 +630,22 @@
</Path.Effect>
</Path>
</Viewbox>
<Viewbox x:Name="MyGattCDataBattery" Grid.Row="1" Margin="15,110,90,0" Height="50" Width="80" Stretch="Uniform" HorizontalAlignment="Left" VerticalAlignment="Top" OpacityMask="Black">
<Path d:Opacity="1" Opacity="0" Fill="Red" Data="m 10.1,256 h 381.1 c 5.5,0 9.9,-4.5 9.9,-10 V 192 H 438 c 5.6,0 10.1,-4.5 10.1,-10 V 74 c 0,-5.5 -4.5,-10 -10.1,-10 H 401 V 10 C 401,4.5 396.7,0 391.1,0 H 10.1 C 4.5,0 0,4.5 0,10 v 236 c 0,5.5 4.5,10 10.1,10 z M 369,32 v 32 32 h 32.2 14.8 v 64 H 401.2 369 v 32 32 H 192 L 160,32 Z">
<Viewbox x:Name="MyGattCDataBattery" Grid.Row="1" Margin="15,110,90,0" Height="50" Width="80" Stretch="Uniform" HorizontalAlignment="Left" VerticalAlignment="Top" OpacityMask="Black">
<Path CacheMode="BitmapCache" d:Opacity="1" Opacity="0" Fill="Red" Data="m 10.1,256 h 381.1 c 5.5,0 9.9,-4.5 9.9,-10 V 192 H 438 c 5.6,0 10.1,-4.5 10.1,-10 V 74 c 0,-5.5 -4.5,-10 -10.1,-10 H 401 V 10 C 401,4.5 396.7,0 391.1,0 H 10.1 C 4.5,0 0,4.5 0,10 v 236 c 0,5.5 4.5,10 10.1,10 z M 369,32 v 32 32 h 32.2 14.8 v 64 H 401.2 369 v 32 32 H 192 L 160,32 Z">
<Path.Style>
<Style TargetType="{x:Type Path}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=Battery}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<Storyboard Timeline.DesiredFrameRate="8" RenderOptions.CachingHint="Cache" RenderOptions.BitmapScalingMode="LowQuality">
<DoubleAnimation Storyboard.TargetProperty='Opacity' From='0' To='1' Duration='0:0:1' AutoReverse='True' RepeatBehavior='Forever'/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<Storyboard FillBehavior='Stop' Timeline.DesiredFrameRate="8" RenderOptions.CachingHint="Cache" RenderOptions.BitmapScalingMode="LowQuality">
<DoubleAnimation Storyboard.TargetProperty='Opacity' From="1" To='0' Duration='0:0:0.5'/>
</Storyboard>
</BeginStoryboard>
Expand All @@ -654,9 +654,7 @@
</Style.Triggers>
</Style>
</Path.Style>
<Path.Effect>
<DropShadowEffect BlurRadius="20" RenderingBias="Quality"/>
</Path.Effect>

</Path>
</Viewbox>
<TextBlock x:Name="MyGattCDataSymbol" Grid.Row="1" HorizontalAlignment="Right" Height="87" Margin="800,159,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="171" FontSize="72" FontWeight="Bold" d:Text="mV"/>
Expand Down
17 changes: 14 additions & 3 deletions BluetoothDMM WPF/BluetoothDMM/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,14 @@ private Task SearchDevices()
{
Debug.WriteLine("Connecting From Updated Event");
var connectResult = await _heartRateMonitor.ConnectAsync(SelectedDeviceId);
if (connectResult.IsConnected)
if (connectResult.IsConnected) {
Debug.WriteLine("Connected From Updated Event");
await RunOnUiThread(() =>
{
if (this.WindowState == WindowState.Minimized)
Show_Click(null, null);
});
}
}
else
{
Expand Down Expand Up @@ -742,7 +748,14 @@ private Task SearchDevices()
{
var connectResult = await _heartRateMonitor.ConnectAsync(SelectedDeviceId);
if (connectResult.IsConnected)
{
Debug.WriteLine("Connected From Updated Event");
await RunOnUiThread(() =>
{
if (this.WindowState == WindowState.Minimized)
Show_Click(null, null);
});
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1432,8 +1445,6 @@ private void Button_Click(object sender, RoutedEventArgs e)
{
ResultDialog = ((System.Windows.FrameworkElement)sender).Name;
CustomDialog.IsOpen = false;
if (this.WindowState == WindowState.Minimized && ResultDialog=="Button1")
Show_Click(null, null);
Properties.Settings.Default.AskOnConnect = (bool)!DontAsk.IsChecked;
Properties.Settings.Default.Save();
}
Expand Down
4 changes: 2 additions & 2 deletions BluetoothDMM WPF/BluetoothDMM/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.24.0.0")]
[assembly: AssemblyFileVersion("1.24.0.0")]
[assembly: AssemblyVersion("1.25.0.0")]
[assembly: AssemblyFileVersion("1.25.0.0")]
Loading

0 comments on commit 6feb606

Please sign in to comment.