Skip to content

Commit

Permalink
Make UI changes (microsoft#52)
Browse files Browse the repository at this point in the history
* Make bluetooth address selectable, make read and write values in characteristic page stretch, and make hitting enter also write the value to the device
  • Loading branch information
jg4ye authored May 4, 2021
1 parent 249a209 commit 55279da
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,13 @@ public void Dispose()
{
bluetoothLEDeviceLock.Release();
}
temp.ConnectionStatusChanged -= BluetoothLEDevice_ConnectionStatusChanged;
temp.NameChanged -= BluetoothLEDevice_NameChanged;
temp.Dispose();

if (temp != null)
{
temp.ConnectionStatusChanged -= BluetoothLEDevice_ConnectionStatusChanged;
temp.NameChanged -= BluetoothLEDevice_NameChanged;
temp.Dispose();
}
IsConnected = false;
}

Expand Down Expand Up @@ -561,7 +564,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
{
Debug.WriteLine(debugMsg + "Previously connected, not calling BluetoothLEDevice.FromIdAsync");
}

Debug.WriteLine(debugMsg + "BluetoothLEDevice is " + BluetoothLEDevice.Name);

Name = bluetoothLEDevice.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ public async void WriteValue()
{
NotifyUser.Insert(0, "Unable to write data - Protocol error");
}
ValueToWrite = String.Empty;
}
catch (Exception ex) when ((uint)ex.HResult == 0x80650003 || (uint)ex.HResult == 0x80070005)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<RelativePanel VerticalAlignment="Center" Visibility="{x:Bind ViewModel.CharacteristicValueVisible, Converter={StaticResource VisibleWhenTrueConverter}}" >
<TextBlock Name="ReadValueText" Text="Read Value: " VerticalAlignment="Center" Width="100" Height="32" Margin="0,5,5,5"/>
<Border Name="Value" Background="LightGray" RelativePanel.RightOf="ReadValueText" RelativePanel.AlignVerticalCenterWith="ReadValueText" MinWidth="75" Height="32" Margin="5" >
<TextBlock Text="{x:Bind ViewModel.Characteristic.Value, Mode=OneWay}" VerticalAlignment="Center" Margin="5,0" TextWrapping="WrapWholeWords"/>
<TextBlock Text="{x:Bind ViewModel.Characteristic.Value, Mode=OneWay}" VerticalAlignment="Center" Margin="5,0" TextWrapping="Wrap" IsTextSelectionEnabled="True" HorizontalAlignment="Stretch"/>
</Border>
<Button Name="ReadAgainButton" Content="Read Again" Click="{x:Bind ViewModel.Characteristic.ReadValueAsync}" Visibility="{x:Bind ViewModel.CharacteristicCanBeRead, Converter={StaticResource VisibleWhenTrueConverter}}" Margin="5" Width="100" Height="32" d:LayoutOverrides="LeftMargin, RightMargin" />

Expand All @@ -228,10 +228,9 @@

<RelativePanel Grid.Row="2" VerticalAlignment="Center" Visibility="{x:Bind ViewModel.CharacteristicCanWrite, Converter={StaticResource VisibleWhenTrueConverter}}">
<TextBlock x:Name="WriteValueText" Text="Write Value: " Margin="0,5,5,5" VerticalAlignment="Center" Width="100" />
<TextBox x:Name="WriteValue" Text="{x:Bind ViewModel.ValueToWrite, Mode=TwoWay}" VerticalAlignment="Center" Width="100" Margin="5"
RelativePanel.RightOf="WriteValueText" TextChanging="WriteValue_TextChanging"
/>
<Button x:Name="WriteButton" Content="Write" Click="{x:Bind ViewModel.WriteValue}" Margin="5" RelativePanel.RightOf="WriteValue" />
<TextBox x:Name="WriteValue" Text="{x:Bind ViewModel.ValueToWrite, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5"
RelativePanel.RightOf="WriteValueText" TextChanging="WriteValue_TextChanging" KeyUp="DetectEnter_Keydown"/>
<Button x:Name="WriteButton" Content="Write" Click="{x:Bind ViewModel.WriteValue}" Margin="5" RelativePanel.RightOf="WriteValue"/>
<!-- The radio buttons need to be in different groups because they are all bound to the same property, so it takes care of which ones stays on vs off. If there is no group then the stackpanel container -->
<!-- groups them and it conflicts with the value converter -->
<StackPanel Name="WriteType" Orientation="Horizontal" Margin="5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ private void DescriptorsListView_ItemClick(object sender, ItemClickEventArgs e)
{
ViewModel.SelectedDescriptor = (ObservableGattDescriptors)e.ClickedItem;
}

/// <summary>
/// Detect when a user presses enter and writes the value to the selected GattCharacterisitc.
/// </summary>
public void DetectEnter_Keydown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
ViewModel.WriteValue();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

<StackPanel Grid.Row="0">
<TextBlock Text="{x:Bind ViewModel.Device.ErrorText}" Visibility="{x:Bind ViewModel.Device.ErrorText, Converter={StaticResource VisibleWhenBlankConverter}}" />
<TextBlock>
<TextBlock IsTextSelectionEnabled="True">
<Run Text="BT Address: " />
<Run Text="{x:Bind ViewModel.Device.BluetoothAddressAsString, Mode=OneWay}"/>
</TextBlock>
Expand Down
26 changes: 13 additions & 13 deletions BluetoothLEExplorer/BluetoothLEExplorer/Views/Discover.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:local="using:BluetoothLEExplorer.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:Template10.Converters"
xmlns:vm="using:BluetoothLEExplorer.ViewModels" mc:Ignorable="d"
xmlns:vm="using:BluetoothLEExplorer.ViewModels" mc:Ignorable="d"
xmlns:models="using:BluetoothLEExplorer.Models"
xmlns:release="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:insider="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
Expand Down Expand Up @@ -114,8 +114,8 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>



<controls:PageHeader x:Name="pageHeader" RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Expand All @@ -134,10 +134,10 @@
<TextBlock Text="Central role is not supported on this device" />
</RelativePanel>

<ProgressBar x:Name="progressBar"
<ProgressBar x:Name="progressBar"
IsEnabled="{x:Bind ViewModel.IsEnumerating, Mode=OneWay }"
IsIndeterminate="{x:Bind ViewModel.IsEnumerating, Mode=OneWay }"
RelativePanel.Below="pageHeader"
RelativePanel.Below="pageHeader"
RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True"
Visibility="{x:Bind ViewModel.IsCentralRoleSupported, Converter={StaticResource VisibleWhenTrueConverter}}"/>

Expand All @@ -153,20 +153,20 @@
<TextBlock Text="Enumeration finished" Visibility="{x:Bind ViewModel.EnumerationFinished, Mode=OneWay, Converter={StaticResource VisibleWhenTrueConverter}}" Margin="10,0,0,0" VerticalAlignment="Center" />
</StackPanel>
<CheckBox Content="Continuous Enumeration" IsChecked="{x:Bind ViewModel.ContinuousEnumeration, Mode=TwoWay}" />

<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,5">
<TextBlock Text="Filter: " VerticalAlignment="Center" Margin="0, 0, 5, 0"/>
<TextBox Text="{Binding GridFilter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>

<TextBlock>
<Run Text="Total Device Count:" />
<Run Text="{x:Bind ViewModel.Context.BluetoothLEDevices.Count, Mode=OneWay}" />
</TextBlock>
</TextBlock>
</StackPanel>

<GridView Grid.Row="1" x:Name="DevicesListView"
ItemsSource="{x:Bind ViewModel.DeviceList, Mode=OneWay}"
<GridView Grid.Row="1" x:Name="DevicesListView"
ItemsSource="{x:Bind ViewModel.DeviceList, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.SelectedDevice, Mode=TwoWay}" Margin="0,20,0,0">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
Expand Down Expand Up @@ -200,7 +200,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Border BorderBrush="Black" BorderThickness="2" >
<Image Grid.Column="0" x:Name="Glyph" Source="{Binding Glyph}" Height="40" Width="40" Margin="5" />
</Border>
Expand All @@ -214,7 +214,7 @@
<TextBlock TextWrapping="Wrap">
Name: <Run Text="{x:Bind Name, Mode=OneWay}" />
</TextBlock>
<TextBlock TextWrapping="WrapWholeWords" Foreground="Black">
<TextBlock TextWrapping="WrapWholeWords" Foreground="Black" IsTextSelectionEnabled="True">
BT Address: <Run Text="{x:Bind BluetoothAddressAsString, Mode=OneTime}" />
</TextBlock>
<TextBlock Foreground="Black">
Expand All @@ -226,7 +226,7 @@
<TextBlock Foreground="Black">
Paired: <Run Text="{x:Bind IsPaired, Mode=OneWay}"/>
</TextBlock>
<TextBlock Visibility="{x:Bind ServiceCount, Converter={StaticResource CollapsedWhenZero}}" Foreground="Black" >
<TextBlock Visibility="{x:Bind ServiceCount, Converter={StaticResource CollapsedWhenZero}}" Foreground="Black" >
Service Count: <Run Text="{x:Bind ServiceCount, Mode=OneWay}"/>
</TextBlock>
<TextBlock>
Expand Down

0 comments on commit 55279da

Please sign in to comment.