Skip to content

Commit

Permalink
Code Changes + Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexe committed Nov 2, 2015
1 parent 7514856 commit d651164
Show file tree
Hide file tree
Showing 94 changed files with 2,437 additions and 96 deletions.
Binary file removed .vs/MindSetUWA/v14/.suo
Binary file not shown.
Binary file added .vs/MindSetUWP/v14/.suo
Binary file not shown.
1,030 changes: 1,030 additions & 0 deletions .vs/config/applicationhost.config

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion MindSetUWA/Common/MindSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static byte[] Get(IBuffer buffer)

public static class HeaderIndex
{
// viz MindWave packet dokumentace
private const int PARSER_SYNC = 0xAA;
private const int UsefulDataPacketLength = 32;

Expand All @@ -39,7 +40,7 @@ public static class PacketValue
{
public static int Get(byte[] usefulDataPacket, int beginInclusive, int endInclusive)
{
// From: http://www.java2s.com/Code/CSharp/Data-Types/ReadInt24frombytearray.htm
// viz: http://www.java2s.com/Code/CSharp/Data-Types/ReadInt24frombytearray.htm

return (usefulDataPacket[beginInclusive] << 16)
+ (usefulDataPacket[beginInclusive + 1] << 8)
Expand Down
1 change: 1 addition & 0 deletions MindSetUWA/EMindSetStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace MindSetUWA
{
//DODĚLAT
public enum EMindSetStatus
{
Connecting, //Connection in progress
Expand Down
Binary file added MindSetUWA/LateX Documentation/BTpair.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 MindSetUWA/LateX Documentation/DebugString.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions MindSetUWA/LateX Documentation/documentation.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}

\newenvironment{dedication}
{
\cleardoublepage
\thispagestyle{empty}
\vspace*{\stretch{1}}
\hfill\begin{minipage}[t]{0.66\textwidth}
\raggedright
}
{
\end{minipage}
\vspace*{\stretch{3}}
\clearpage
}

\makeatletter
\renewcommand{\@chapapp}{}% Not necessary...
\newenvironment{chapquote}[2][2em]
{\setlength{\@tempdima}{#1}%
\def\chapquote@author{#2}%
\parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
\itshape}
{\par\normalfont\hfill--\ \chapquote@author\hspace*{\@tempdima}\par\bigskip}
\makeatother


\title{\Huge \textbf{MindSetUWP} \\ \hugeb MindWave EEG Headset library for Windows 10 universal applications}
\author{\textsc{Ondrej Rehacek}\thanks{\url{reh0063@vsb.cz}}}


\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
language=[Sharp]C,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=3
}

\begin{document}

\maketitle
\tableofcontents
\mainmatter

\chapter*{General information}
A NeuroSky MindWave and MindWave Mobile EEG headset library for Windows 10 universal applications ecosystem. A part of my bachelor thesis at VŠB - Technical University of Ostrava. Study year 2015-2016. Library is designed primary for use with MindWave Mobile bluetooth headset paired with Windows 10 device. You can easilly recieve EEG readings to any UWA application and use them.

\section*{Legacy mode}
However library also include a separate "legacy compatibic usor MindWave headsets that uses RF 2.4Ghz dongle. This legacy compatibility is limited to a devices that are capable to run ThinkGear connector software locally (So only Windows 10 for x86 desktop - this is due to a limitation to a ThinkGear software itself that only accepts packet connection from local device.) Legacy mode is not discussed only in separate part of the documentation, nor is endorsed to use on end-user appliaction and wich is only suitable for testing purpouses.

\section*{Basics}
Library can be used for any .NET Windows 10 Universal application running on every Windows 10 device that have a bluetooth adapter installed with appropriate system drivers. The EEG headset must be paired in the system Bluettooth menu prior to the use of the library itself.


\chapter{Basic Usage}

\section{Creating the instance of MindSetConnection}
After you sucsesfully imported the library into your application references, you can proceed by declaring the instance of MindSetConnection - a class that represents a connection to a EEG headset.

\begin{lstlisting}
// Create a new instance of MindSetConnection class.
private MindSetConnection MyHeadset = new MindSetConnection();
\end{lstlisting}

\section{Establishing Bluetooth connection}
Now we can use a method "ConnectBluetooth" followed by suppling the bluetooth name of the (In most cases the name is "MindWave Mobile") to initiate the packet connection to the EEG headset - that is all, easy as that - now we are recieving the formatted EEG readings from the headset.

\begin{lstlisting}
private void EstConnBtn_Click(object sender, RoutedEventArgs e)
{
//Initiate bluetooth connection to a headset named "MindWave Mobile"
MyHeadset.ConnectBluetooth("MindWave Mobile");
}
\end{lstlisting}

\section{Working with EEG data}
MindSet headset transmits ThinkGear Data Values, encoded within TinkGear Packets, as a serial stream
of bytes over Bluetooth via a standard Bluetooth Serial Port Profile (SPP). MindSetUWP library process all of this packets and manages bluetooth connection with headset for you, so you are no longer required to do any extra work. Before we start working with the data , lets talk about all measurements that headset send to your applicaion and this library supports.


\begin{table}[ht]
\caption{EEG Data} % title of Table
\centering % used for centering table
\begin{tabular}{c c c c}
% centered columns (4 columns)
\hline\hline %inserts double horizontal lines
Variable Name & Value Range & Type & Required \\ [0.5ex]
% inserts table
%heading
\hline % inserts single horizontal line
Delta & 0.5 - 2.75Hz & Integer & X \\
Theta & 3.5 - 6.75Hz & Integer & X \\
AlphaLow & 7.5 - 9.25Hz & Integer & X \\
AlphaHigh & 10 - 11.75Hz & Integer & X \\
BetaLow & 13 - 16.75Hz & Integer & X \\
BetaHigh & 18 - 29.75Hz & Integer & X \\
GammaLow & 31 - 39.75Hz & Integer & X \\
GammaMid & 41 - 49.75Hz & Integer & X \\
esense.attention & 0 - 100 & Integer & \\
esense.meditation & 0 - 100 & Integer & \\ [1ex]
TimeStamp & & DateTime & X \\
Quality & 0-255 & Integer & X \\ [1ex] % [1ex] adds vertical space
\hline %inserts single line
\end{tabular}
\label{table:nonlin} % is used to refer this table in the text
\end{table}

All of the variables in the table represent particular EEG data recieved from the MindWave headset, they are publicly acessible variables in the instance you created and connected to a headset using "RealtimeData" class.

\begin{lstlisting}
private void ShowDataBtn_Click(object sender, RoutedEventArgs e)
{
Debug.Write(MyHeadset.RealtimeData.AlphaHigh); //Writes AlpaHigh data into debug console.
Debug.Write(MyHeadset.RealtimeData.AlphaLow); //Writes AlpaLow data into debug console.
}
\end{lstlisting}


\noindent This is of course the most basic example of how you can work with the EEG data from the headset, you can use and work with them like with any public variable in your application. They are updated constantly while the bluetooth headset is connected.

\subsection{Alternative methods of working with EEG data.}
MindSetUWP library also contains alternative three methods how you can work with recieved EEG data. Theese three methods are called \textbf{AllToIntArray} witch returns an integer array with all of the EEG readings. Alternatively you can use \textbf{AllToArray} wich returns array of all EEG readings formatted to a string values.The position of EEG data in this arrays are the same as in the Table 1.1 in this document. At last you can also use \textbf{AllToString} that returns a long nicelly formated text string of all EEG values.

\begin{lstlisting}
private void WrtDataBtn_Click(object sender, RoutedEventArgs e)
{
Debug.Write(MyHeadset.RealtimeData.AllToString()); //Writes all of the data into debug console.

int[] TableofEEG = MyHeadset.RealtimeData.AllToIntArray(); //Writes all of the data into integer array.
}
\end{lstlisting}


\chapter{Advanced Usage}

\section{Handling Events}
TODO

\section{Legacy Connection - RF MindWave}
TODO

\section{RAW EEG Data}
TODO

\end{document}
6 changes: 4 additions & 2 deletions MindSetUWA/LegacyConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ namespace MindSetUWA
{
public partial class MindSetConnection
{
// viz:
// http://developer.neurosky.com/docs/lib/exe/fetch.php?media=app_notes:thinkgear_socket_protocol.pdf

/// <summary>
/// Opens a packet connnection to a legacy MindWave headset that uses 2.4Ghz RF dongle.
/// This is compatible in Windows Phone however it requires a ThinkGear Connector installed on a target machine and connector only accepts local connection.
/// Specify a hostname (eg. localhost) and port.
/// </summary>
/// </summary>

public async void ThinkGearConnect(HostName hostname, string port)
{
StreamSocket socket = new StreamSocket();
Expand All @@ -37,7 +39,7 @@ public async void ThinkGearConnect(HostName hostname, string port)
var count = await reader.LoadAsync(1024);
if (count > 0)
receivedData = reader.ReadString(count);
//ThinkGearDeserializer(receivedData); TODO NEW DESERIALIZER
//ThinkGearDeserializer(receivedData); dodělat nový deserializer
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions MindSetUWA/MindSetConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public partial class MindSetConnection : IMindwave
public MindsetDataStruct RealtimeData = new MindsetDataStruct();
private EMindSetStatus Status = new EMindSetStatus();

private const int PacketLenght = 36; //MindSet packet is 36 bytes long.
private const int PacketLenght = 36; //MindSet packet is 36 bytes long. Check Documentation.


//returns status (TODO)
public EMindSetStatus ConnectionStatus()
{
return Status;
Expand Down Expand Up @@ -83,18 +85,20 @@ private async void ParseHeadsetPackets()
}
else
{
// Check if enough data exists to finalize this useful data packet, if not, get another
// Packet Check
if (indexOfUsefulDataHeader.Value + PacketLenght > resultArray.Length)
{
var nextResultsArray = await NextBuffer();
resultArray = resultArray.Concat(nextResultsArray).ToArray();
}

// Packet is all right
// Packet OK
var PctData = resultArray.Skip(indexOfUsefulDataHeader.Value).Take(PacketLenght + 4).ToArray();
Status = EMindSetStatus.ConnectedBT;

// viz:
// http://wearcam.org/ece516/mindset_communications_protocol.pdf
//
RealtimeData = new MindsetDataStruct(PctData[4], //Signal Quality
PacketValue.Get(PctData, 7, 9), //Delta
PacketValue.Get(PctData, 10, 12), //Theta
Expand Down
9 changes: 6 additions & 3 deletions MindSetUWA/MindSetUWA.csproj → MindSetUWA/MindSetUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{156981C0-E892-44F4-9F10-73B8671ADF53}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MindSetUWA</RootNamespace>
<AssemblyName>MindSetUWA</AssemblyName>
<RootNamespace>MindSetUWP</RootNamespace>
<AssemblyName>MindSetUWP</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
Expand Down Expand Up @@ -104,6 +104,7 @@
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="LateX Documentation\documentation.tex" />
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
Expand All @@ -114,9 +115,11 @@
<Compile Include="Common\MindSetExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LegacyConnect.cs" />
<Content Include="LateX Documentation\BTpair.png" />
<Content Include="LateX Documentation\DebugString.png" />
<Content Include="Properties\MindSetUWA.rd.xml" />
<Content Include="README_EN.txt" />
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
32 changes: 1 addition & 31 deletions MindSetUWA/MindsetDataStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@ namespace MindSetUWA
{
public class MindsetDataStruct
{
private DateTime now;
private object p1;
private object p10;
private object p2;
private object p3;
private object p4;
private object p5;
private object p6;
private object p7;
private object p8;
private object p9;
private int v;
public MindsetDataStruct()
{
}
public MindsetDataStruct(){}

public MindsetDataStruct(int quality, int delta, int theta, int alphaLow, int alphaHigh, int betaLow, int betaHigh, int gammaLow, int gammaMid, int eSenseAttention, int eSenseMeditation, DateTime timestamp)
{
Expand All @@ -36,22 +22,6 @@ public MindsetDataStruct(int quality, int delta, int theta, int alphaLow, int al
Timestamp = timestamp;
}

public MindsetDataStruct(object p1, int v, object p2, object p3, object p4, object p5, object p6, object p7, object p8, object p9, object p10, DateTime now)
{
this.p1 = p1;
this.v = v;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
this.p5 = p5;
this.p6 = p6;
this.p7 = p7;
this.p8 = p8;
this.p9 = p9;
this.p10 = p10;
this.now = now;
}

public int AlphaHigh { get; private set; }

public int AlphaLow { get; private set; }
Expand Down
6 changes: 3 additions & 3 deletions MindSetUWA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MindSetUWA")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("MindWave EEG Headset library for Windows 10 universal applications.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Ondřej Řeháček (REH0063)")]
[assembly: AssemblyProduct("MindSetUWA")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © Ondřej Řeháček (REH0063) 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
1 change: 0 additions & 1 deletion MindSetUWA/README_EN.txt

This file was deleted.

Binary file modified MindSetUWA/bin/x64/Debug/MindSetUWA.dll
Binary file not shown.
Binary file modified MindSetUWA/bin/x64/Debug/MindSetUWA.pdb
Binary file not shown.
Binary file added MindSetUWA/bin/x64/Debug/MindSetUWP.dll
Binary file not shown.
Binary file added MindSetUWA/bin/x64/Debug/MindSetUWP.pdb
Binary file not shown.
Binary file added MindSetUWA/bin/x64/Debug/MindSetUWP.pri
Binary file not shown.
Binary file not shown.
Binary file modified MindSetUWA/obj/x64/Debug/MindSetUWA.dll
Binary file not shown.
Binary file modified MindSetUWA/obj/x64/Debug/MindSetUWA.pdb
Binary file not shown.
16 changes: 16 additions & 0 deletions MindSetUWA/obj/x64/Debug/MindSetUWP.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\bin\x64\Debug\MindSetUWP.dll
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\bin\x64\Debug\MindSetUWP.pdb
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\bin\x64\Debug\MindSetUWP.pri
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\MindSetUWP.dll
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\MindSetUWP.pdb
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\priconfig.xml
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\priconfig.xml.intermediate
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\layout.resfiles
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\layout.resfiles.intermediate
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\resources.resfiles
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\resources.resfiles.intermediate
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\pri.resfiles
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\pri.resfiles.intermediate
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\qualifiers.txt
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\qualifiers.txt.intermediate
C:\Users\olire\Documents\GitHub\MindSetUWA\MindSetUWA\obj\x64\Debug\MultipleQualifiersPerDimensionFound.txt
Binary file added MindSetUWA/obj/x64/Debug/MindSetUWP.dll
Binary file not shown.
Binary file added MindSetUWA/obj/x64/Debug/MindSetUWP.pdb
Binary file not shown.
5 changes: 3 additions & 2 deletions MindSetUWA/obj/x64/Debug/layout.resfiles
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MindSetUWA\Properties\MindSetUWA.rd.xml
MindSetUWA\README_EN.txt
MindSetUWP\LateX Documentation\BTpair.png
MindSetUWP\LateX Documentation\DebugString.png
MindSetUWP\Properties\MindSetUWA.rd.xml
5 changes: 3 additions & 2 deletions MindSetUWA/obj/x64/Debug/layout.resfiles.intermediate
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MindSetUWA\Properties\MindSetUWA.rd.xml
MindSetUWA\README_EN.txt
MindSetUWP\LateX Documentation\BTpair.png
MindSetUWP\LateX Documentation\DebugString.png
MindSetUWP\Properties\MindSetUWA.rd.xml
4 changes: 2 additions & 2 deletions MindSetUWA/obj/x64/Debug/priconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<qualifier name="AlternateForm" value="" />
<qualifier name="Platform" value="UAP" />
</default>
<indexer-config type="RESW" convertDotsToSlashes="true" initialPath="MindSetUWA" />
<indexer-config type="RESJSON" initialPath="MindSetUWA" />
<indexer-config type="RESW" convertDotsToSlashes="true" initialPath="MindSetUWP" />
<indexer-config type="RESJSON" initialPath="MindSetUWP" />
<indexer-config type="RESFILES" qualifierDelimiter="." />
</index>
<index root="\" startIndexAt="obj\x64\Debug\pri.resfiles">
Expand Down
Loading

0 comments on commit d651164

Please sign in to comment.