Skip to content

Commit

Permalink
Bugfix and Improvements:
Browse files Browse the repository at this point in the history
- Fixed get firmware command
- Improved bluetooth connection class such that the bluegiga dongle does not be to be connected when the class is created
- Added the flush command for the Connection class
- Updated the example program to have the get firmware/hardware version command, get battery level command, and connect to either a TappyBLE or TappyUSB
- Added a method to convert the UID byte array to a string for the Tag class
  • Loading branch information
brianEngio committed Aug 10, 2016
1 parent f9e01c1 commit dc0d81e
Show file tree
Hide file tree
Showing 23 changed files with 686 additions and 150 deletions.
17 changes: 17 additions & 0 deletions Example/ConnectWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="TapTrack.Demo.ConnectWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TapTrack.Demo"
mc:Ignorable="d"
Title="ConnectWindow" Height="200" Width="300"
Background="{StaticResource LightBackground}"
WindowStartupLocation="CenterScreen">
<StackPanel Orientation="Vertical" Margin="10" Background="{StaticResource LightBackground}">
<TextBlock Foreground="White" HorizontalAlignment="Center">Connect to a</TextBlock>
<Button Style="{StaticResource RoundButton}" Click="bleButton_Click">TappyBLE</Button>
<TextBlock Foreground="White" HorizontalAlignment="Center">or</TextBlock>
<Button Style="{StaticResource RoundButton}" Click="usbButton_Click">TappyUSB</Button>
</StackPanel>
</Window>
44 changes: 44 additions & 0 deletions Example/ConnectWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TapTrack.Tcmp.Communication;

namespace TapTrack.Demo
{
/// <summary>
/// Interaction logic for ConnectWindow.xaml
/// </summary>
public partial class ConnectWindow : Window
{
public ConnectWindow()
{
InitializeComponent();
}

public CommunicationProtocol Protocol { get; internal set; }

private void bleButton_Click(object sender, RoutedEventArgs e)
{
this.Protocol = CommunicationProtocol.Bluetooth;
this.DialogResult = true;
this.Close();
}

private void usbButton_Click(object sender, RoutedEventArgs e)
{
this.Protocol = CommunicationProtocol.Usb;
this.DialogResult = true;
this.Close();
}
}
}
268 changes: 210 additions & 58 deletions Example/MainWindow.xaml

Large diffs are not rendered by default.

126 changes: 104 additions & 22 deletions Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace TapTrack.Demo
using Tcmp;
using NdefLibrary.Ndef;
using System.Text;

using Tcmp.CommandFamilies.System;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
Expand Down Expand Up @@ -365,15 +365,27 @@ private void StopButton_Click(object sender, RoutedEventArgs e)

private void AutoDetectButton_Click(object sender, RoutedEventArgs e)
{
ShowPendingStatus("Searching for a TappyUSB");
ConnectWindow window = new ConnectWindow();

Task.Run(() =>
if (window.ShowDialog() == true)
{
if (tappyDriver.AutoDetect())
ShowSuccessStatus($"Connected to {tappyDriver.DeviceName}");
else
ShowFailStatus("No TappyUSB found");
});
if (window.Protocol == CommunicationProtocol.Usb)
batteryTab.Visibility = Visibility.Hidden;
else if (window.Protocol == CommunicationProtocol.Bluetooth)
batteryTab.Visibility = Visibility.Visible;

tappyDriver.SwitchProtocol(window.Protocol);

ShowPendingStatus("Searching for a Tappy");

Task.Run(() =>
{
if (tappyDriver.AutoDetect())
ShowSuccessStatus($"Connected to {tappyDriver.DeviceName}");
else
ShowFailStatus("No Tappy found");
});
}
}

private void SettingsButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -455,7 +467,7 @@ public bool CheckForErrorsOrTimeout(ResponseFrame frame, Exception e)
if (e != null)
{
if (e.GetType() == typeof(HardwareException))
ShowFailStatus("TappyUSB is not connected");
ShowFailStatus("Tappy is not connected");
else
ShowFailStatus("An error occured");

Expand Down Expand Up @@ -537,20 +549,8 @@ private void configureTagForPlatform_Click(object sender, RoutedEventArgs e)

tappyDriver.SendCommand(readCommand, delegate (ResponseFrame frame, Exception exc)
{
if (exc != null)
{
return;
}
else if (!TcmpFrame.IsValidFrame(frame))
{
ShowFailStatus("Error occured");
return;
}
else if (frame.IsApplicationErrorFrame())
{
ShowFailStatus(((ApplicationErrorFrame)frame).ErrorString);
if (CheckForErrorsOrTimeout(frame, exc))
return;
}

Tag tag = new Tag(frame.Data);
string uid = BitConverter.ToString(tag.UID).Replace("-", "");
Expand Down Expand Up @@ -591,5 +591,87 @@ private void disconnectButton_Click(object sender, RoutedEventArgs e)
{
tappyDriver.Disconnect();
}

private void firmwareVersionButton_Click(object sender, RoutedEventArgs e)
{
ShowPendingStatus("");
Command cmd = new GetFirmwareVersion();

Action<string> update = (string text) =>
{
firmwareTextBox.Text = text;
};

Callback callback = (ResponseFrame frame, Exception exc) =>
{
if (CheckForErrorsOrTimeout(frame, exc))
return;

if (frame.ResponseCode == 0x06)
{
byte[] data = frame.Data;

Dispatcher.BeginInvoke(update, $"{data[0]}.{data[1]}");
}
ShowSuccessStatus();
};

tappyDriver.SendCommand(cmd, callback);
}

private void hardwareVersionButton_Click(object sender, RoutedEventArgs e)
{
ShowPendingStatus("");
Command cmd = new GetHardwareVersion();

Action<string> update = (string text) =>
{
hardwareTextBox.Text = text;
};

Callback callback = (ResponseFrame frame, Exception exc) =>
{
if (CheckForErrorsOrTimeout(frame, exc))
return;

if (frame.ResponseCode == 0x05)
{
byte[] data = frame.Data;

Dispatcher.BeginInvoke(update, $"{data[0]}.{data[1]}");
}
ShowSuccessStatus();
};

tappyDriver.SendCommand(cmd, callback);
}

private void batteryButton_Click(object sender, RoutedEventArgs e)
{
ShowPendingStatus("");
Command cmd = new GetBatteryLevel();

Action<string> update = (string text) =>
{
batteryTextBox.Text = text;
};

Callback callback = (ResponseFrame frame, Exception exc) =>
{
if (CheckForErrorsOrTimeout(frame, exc))
return;


if (frame.ResponseCode == 0x08)
{
byte[] data = frame.Data;

Dispatcher.BeginInvoke(update, $"{data[0]}%");
}
ShowSuccessStatus();
};

tappyDriver.SendCommand(cmd, callback);
}
}
}
4 changes: 2 additions & 2 deletions Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: NeutralResourcesLanguage("en-CA")]

40 changes: 40 additions & 0 deletions Example/Properties/Resources.Designer.cs

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

12 changes: 12 additions & 0 deletions Example/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,16 @@
<data name="disconnect_highlight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\disconnect_highlight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="battery" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\battery.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="battery_highlight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\battery_highlight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firmware" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\firmware.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="firmware_highlight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\firmware_highlight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Example/Resources/battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Example/Resources/battery_highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Example/Resources/firmware.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Example/Resources/firmware_highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Example/Resources/usb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Example/Resources/usb_highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 43 additions & 1 deletion Example/Styles/TapTrack Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<BitmapImage x:Key="Platform_highlight" UriSource="/Resources/platform_highlight.png"/>
<BitmapImage x:Key="Disconnect" UriSource="/Resources/disconnect.png"/>
<BitmapImage x:Key="Disconnect_highlight" UriSource="/Resources/disconnect_highlight.png"/>
<BitmapImage x:Key="Battery" UriSource="/Resources/battery.png"/>
<BitmapImage x:Key="Battery_highlight" UriSource="/Resources/battery_highlight.png"/>
<BitmapImage x:Key="Version" UriSource="/Resources/firmware.png"/>
<BitmapImage x:Key="Version_highlight" UriSource="/Resources/firmware_highlight.png"/>

<Style x:Key="TextBox" TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="10,0,20,20"/>
Expand Down Expand Up @@ -112,7 +116,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid ToolTip="Auto Detect TappyUSB">
<Grid ToolTip="Auto Detect Tappy">
<Image Name="Pressed" Visibility="Hidden" Source="{StaticResource Usb_highlight}"/>
<Image Name="Unpressed" Visibility="Visible" Source="{StaticResource Usb}"/>
</Grid>
Expand Down Expand Up @@ -373,4 +377,42 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="BatteryTab" TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Name="Container" ToolTip="Get battery level" Background="White" Margin="10">
<Image Width="30" Height="30" Stretch="Fill" Name="Pressed" Visibility="Hidden" Source="{StaticResource Battery_highlight}"/>
<Image Width="30" Height="30" Stretch="Fill" Name="Unpressed" Visibility="Visible" Source="{StaticResource Battery}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="Container" Property="IsMouseOver" Value="True">
<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
<Setter TargetName="Unpressed" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="VersionTab" TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Name="Container" ToolTip="Get version info of Tappy" Background="White" Margin="10">
<Image Width="30" Height="30" Stretch="Fill" Name="Pressed" Visibility="Hidden" Source="{StaticResource Version_highlight}"/>
<Image Width="30" Height="30" Stretch="Fill" Name="Unpressed" Visibility="Visible" Source="{StaticResource Version}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="Container" Property="IsMouseOver" Value="True">
<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
<Setter TargetName="Unpressed" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Loading

0 comments on commit dc0d81e

Please sign in to comment.