Skip to content

Commit

Permalink
Added legacy compatibility
Browse files Browse the repository at this point in the history
Legacy comptatibility for old RF headsets using ThinkGear connector.
  • Loading branch information
oliexe committed Oct 21, 2015
1 parent b5d53bf commit 2d358e2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
Binary file added .vs/MindSetUWA/v14/.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions MindSetUWA/IMindwave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface IMindwave : IDisposable
/// Opens a bluetooth connnection to a MindWave Mobile headset.
/// Please specify a Bluetooth name (Usually "MindWave Mobile") in the first parameter.
/// </summary>
void Connect(String BTname);
void ConnectBluetooth(String BTname);

/// <summary>
/// Closes a already established bluetooth connnection to a MindWave Mobile headset.
/// </summary>
void Disconnect();
void DisconnectBluetooth();

/// <summary>
/// Returns a realtime status of the connection to a headset in MindSetUWA.EMindSetStatus format.
Expand Down
42 changes: 42 additions & 0 deletions MindSetUWA/LegacyConnect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Networking;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;

namespace MindSetUWA
{
public partial class MindSetConnection
{

public async void ThinkGearConnect(HostName hostname, string port)
{
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(hostname, port);
byte[] buffer = new byte[8192];

DataReader reader = new DataReader(socket.InputStream);
DataWriter writer = new DataWriter(socket.OutputStream);

//Switch ThinkGear Connector to JSON format.
byte[] myWriteBuffer = Encoding.ASCII.GetBytes(@"{""enableRawOutput"": false, ""format"": ""Json""}");
writer.WriteBytes(myWriteBuffer);
await writer.StoreAsync();

//Continuously recieve stream of JSON data.
while (true)
{
string receivedData = "";
reader.InputStreamOptions = InputStreamOptions.Partial;
var count = await reader.LoadAsync(1024);
if (count > 0)
receivedData = reader.ReadString(count);
//ThinkGearDeserializer(receivedData); TODO NEW DESERIALIZER
}
}

}
}
17 changes: 12 additions & 5 deletions MindSetUWA/MindSetConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MindSetUWA
{
public class MindSetConnection
public partial class MindSetConnection : IMindwave
{
StreamSocket socket;
DataReader reader;
Expand All @@ -36,7 +36,7 @@ public String ConnectionStatusString()
/// Opens a bluetooth connnection to a MindWave Mobile headset.
/// Please specify a Bluetooth name (Usually "MindWave Mobile") in the first parameter.
/// </summary>
public async void Connect(String BTname)
public async void ConnectBluetooth(String BTname)
{
try
{
Expand All @@ -59,7 +59,7 @@ public async void Connect(String BTname)
/// <summary>
/// Closes a already established bluetooth connnection to a MindWave Mobile headset.
/// </summary>
public void Disconnect()
public void DisconnectBluetooth()
{
socket.Dispose();
}
Expand Down Expand Up @@ -126,7 +126,14 @@ private async Task<byte[]> NextBuffer(uint length = 512)
return resultArray;
}



void IMindwave.ParseHeadsetPackets()
{
throw new NotImplementedException();
}

public void Dispose()
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions MindSetUWA/MindSetUWA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<Compile Include="MindsetDataStruct.cs" />
<Compile Include="Common\MindSetExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LegacyConnect.cs" />
<Content Include="Properties\MindSetUWA.rd.xml" />
<Content Include="README_EN.txt" />
</ItemGroup>
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion MindWaveBc/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MainPage()
private void button_Click(object sender, RoutedEventArgs e)
{
//Initiate bluetooth connection to a headset named "MindWave Mobile"
MyHeadset.Connect("MindWave Mobile");
MyHeadset.ConnectBluetooth("MindWave Mobile");
}

private void button1_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 2d358e2

Please sign in to comment.