Skip to content

Commit

Permalink
Working.
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalej committed Feb 12, 2020
1 parent 0cc35d2 commit 5a4b147
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 148 deletions.
20 changes: 10 additions & 10 deletions BlueMuse.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace BlueMuse
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// Initializes the singleton application object.
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
Expand Down Expand Up @@ -69,9 +69,9 @@ private void Launch(ApplicationExecutionState previousExecutionState, bool prela

if (previousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
// TODO: Load state from previously suspended application.
}
// Place the frame in the current Window
// Place the frame in the current Window.
Window.Current.Content = rootFrame;
}

Expand All @@ -81,12 +81,12 @@ private void Launch(ApplicationExecutionState previousExecutionState, bool prela
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
// parameter.
if (e == null) rootFrame.Navigate(typeof(MainPage));
else rootFrame.Navigate(typeof(MainPage), e);
}

// Ensure the current window is active
// Ensure the current window is active.
var desiredSize = new Size(425d, 660d);
ApplicationView.PreferredLaunchViewSize = desiredSize;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Expand All @@ -97,7 +97,7 @@ private void Launch(ApplicationExecutionState previousExecutionState, bool prela

protected async override void OnActivated(IActivatedEventArgs args)
{
// Check for protocol activation
// Check for protocol activation.
if (args.Kind == ActivationKind.Protocol)
{
bool launching = args.PreviousExecutionState != ApplicationExecutionState.Running;
Expand Down Expand Up @@ -195,10 +195,10 @@ protected async override void OnActivated(IActivatedEventArgs args)
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// Invoked when Navigation to a certain page fails.
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
/// <param name="sender">The Frame which failed navigation.</param>
/// <param name="e">Details about the navigation failure.</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
Expand All @@ -214,7 +214,7 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
// TODO: Save application state and stop any background activity.
deferral.Complete();
}

Expand Down
12 changes: 6 additions & 6 deletions BlueMuse.App/BlueMuse.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<Version>6.2.9</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="Serilog">
<Version>2.9.0</Version>
Expand All @@ -227,11 +227,6 @@
<Version>3.3.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<SDKReference Include="Microsoft.VCLibs.Desktop, Version=14.0">
<Name>Visual C++ 2015 UWP Desktop Runtime for native apps</Name>
Expand All @@ -246,6 +241,11 @@
<Name>NativeHelpers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions BlueMuse.App/Bluetooth/BluetoothManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ public async void StopStreaming(object museId)
}
}

public async void ResetMuse(object museId)
{
var muse = Muses.SingleOrDefault(x => x.Id == (string)museId);
if(muse != null)
{
await muse.Reset();
}
}

public async Task StartStreamingAll()
{
var muses = this.Muses.Where(x => !x.IsStreaming);
Expand Down
74 changes: 38 additions & 36 deletions BlueMuse.App/Misc/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ static class Constants
// Device name filter will pickup glasses, Muse original, and Muse 2. Names with be something like SMTX-xxxx or Muse-xxxx.
public static readonly List<string> DeviceNameFilter = new List<string>()
{
"Muse", "SMTX"
"Muse", "SMXT"
};

// Query string for filtering system devices. We could probably filter in a better way, but this, along with the name match, works for now.
public const string DEVICE_AQS = "System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:=\"{BB7BB05E-5972-42B5-94FC-76EAA7084D49}\"";

// BlueMuse command arguments.
public const string ARGS_STREAMFIRST = "streamfirst";
public const string ARGS_ADDRESSES = "addresses";
public const string ARGS_STARTALL = "startall";
public const string ARGS_STOPALL = "stopall";
public const string ARGS_SETTING_KEY = "key";
public const string ARGS_SETTING_VALUE = "value";

// BlueMuse commands.
public const string CMD_START = "start";
public const string CMD_STOP = "stop";
public const string CMD_CLOSE_PROGRAM = "shutdown";
public const string CMD_SET_SETTING = "setting";

// Streaming rates.
public const int MUSE_EEG_SAMPLE_RATE = 256;
public const float MUSE_EEG_SAMPLE_TIME_MILLIS = 1000f / MUSE_EEG_SAMPLE_RATE;

Expand All @@ -38,29 +41,23 @@ static class Constants
public const int MUSE_PPG_SAMPLE_RATE = 64;
public const float MUSE_PPG_SAMPLE_TIME_MILLIS = 1.0f / MUSE_PPG_SAMPLE_RATE; // Theoretical time between consecutive PPG samples.

// Muse specific channel counts.
// Channel counts.
public const int MUSE_EEG_CHANNEL_COUNT = 5;

// Muse 2 specific channel counts.
public const int MUSE_2_EEG_CHANNEL_COUNT = 4;
public const int MUSE_2_PPG_CHANNEL_COUNT = 3;

// SMXT specific channel counts.
public const int MUSE_SMXT_EEG_CHANNEL_COUNT = 4;

// Shared channel counts (Muse, Muse2, SMXT).
public const int MUSE_EEG_NOAUX_CHANNEL_COUNT = 4;
public const int MUSE_ACCELEROMETER_CHANNEL_COUNT = 3;
public const int MUSE_GYROSCOPE_CHANNEL_COUNT = 3;
public const int MUSE_PPG_CHANNEL_COUNT = 3;

// Names and manufacturers.
public const string MUSE_DEVICE_NAME = "Muse EEG Headset";
public const string MUSE_MANUFACTURER = "Interaxon";

public const string MUSE_2_DEVICE_NAME = "Muse 2 EEG Headset";
public const string MUSE_2_MANUFACTURER = "Interaxon";

public const string MUSE_SMXT_DEVICE_NAME = "Smith Lowdown Focus";
public const string MUSE_SMXT_MANUFACTURER = "Smith";

// Sample sizes (chunk size) for LSL.
public const int MUSE_EEG_SAMPLE_COUNT = 12; // Number of samples for each EEG LSL push.
public const int MUSE_ACCELEROMETER_SAMPLE_COUNT = 1; // Number of samples for each accelerometer LSL push.
public const int MUSE_GYROSCOPE_SAMPLE_COUNT = 1; // Number of samples for each grysocope LSL push.
Expand Down Expand Up @@ -103,21 +100,45 @@ static class Constants
new Guid("273e0007-4c4d-454d-96be-f03bac821358") // Handle 43
};

// Muse glasses GATT characteristics for the 4 EEG channels, in order: TP9-AF7-AF8-TP10.
public static readonly Guid[] MUSE_SMXT_GATT_EEG_CHANNEL_UUIDS = new Guid[MUSE_SMXT_EEG_CHANNEL_COUNT] {
// Muse no AUX GATT characteristics for the 4 EEG channels, in order: TP9-AF7-AF8-TP10. Applies to SMXT and Muse 2.
public static readonly Guid[] MUSE_GATT_EGG_NOAUX_CHANNEL_UUIDS = new Guid[MUSE_EEG_NOAUX_CHANNEL_COUNT] {
new Guid("273e0003-4c4d-454d-96be-f03bac821358"), // Handle 31
new Guid("273e0004-4c4d-454d-96be-f03bac821358"), // Handle 34
new Guid("273e0005-4c4d-454d-96be-f03bac821358"), // Handle 37
new Guid("273e0006-4c4d-454d-96be-f03bac821358") // Handle 40
};

// Muse 2 GATT characteristics for the 3 PPG channels.
public static readonly Guid[] MUSE_2_GATT_PPG_CHANNEL_UUIDS = new Guid[MUSE_2_PPG_CHANNEL_COUNT] {
// Accelerometer GATT characteristic.
public static Guid MUSE_GATT_ACCELEROMETER_UUID = new Guid("273e000a-4c4d-454d-96be-f03bac821358");

// Gyroscope GATT characteristic.
public static Guid MUSE_GATT_GYROSCOPE_UUID = new Guid("273e0009-4c4d-454d-96be-f03bac821358");

// Muse (2) GATT characteristics for the 3 PPG channels.
public static readonly Guid[] MUSE_GATT_PPG_CHANNEL_UUIDS = new Guid[MUSE_PPG_CHANNEL_COUNT] {
new Guid("273e000f-4c4d-454d-96be-f03bac821358"), // PPG1
new Guid("273e0010-4c4d-454d-96be-f03bac821358"), // PPG2
new Guid("273e0011-4c4d-454d-96be-f03bac821358"), // PPG3
};

// LSL labels for the 5 EEG channels, in specific order to match muse-lsl.py.
public static readonly string[] MUSE_EEG_CHANNEL_LABELS = new string[MUSE_EEG_CHANNEL_COUNT]
{
"TP9",
"AF7",
"AF8",
"TP10",
"Right AUX"
};

// Muse no AUX GATT characteristics for the 4 EEG channels, in order: TP9-AF7-AF8-TP10. Applies to SMXT and Muse 2.
public static readonly string[] MUSE_EEG_NOAUX_CHANNEL_LABELS = new string[MUSE_EEG_NOAUX_CHANNEL_COUNT] {
"TP9",
"AF7",
"AF8",
"TP10",
};

// LSL labels for the Accelerometer stream channels.
public static readonly string[] MUSE_ACCELEROMETER_CHANNEL_LABELS = new string[3] {
"X",
Expand All @@ -133,31 +154,12 @@ static class Constants
};

// LSL labels for the PPG stream channels.
public static readonly string[] MUSE_PPG_CHANNEL_LABELS = new string[MUSE_2_PPG_CHANNEL_COUNT] {
public static readonly string[] MUSE_PPG_CHANNEL_LABELS = new string[MUSE_PPG_CHANNEL_COUNT] {
"PPG1",
"PPG2",
"PPG3"
};

// LSL labels for the 5 EEG channels, in specific order to match muse-lsl.py.
public static readonly string[] MUSE_EEG_CHANNEL_LABELS = new string[MUSE_EEG_CHANNEL_COUNT]
{
"TP9",
"AF7",
"AF8",
"TP10",
"Right AUX"
};

// LSL labels for the 4 EEG channels, in specific order to match muse-lsl.py. Note the SMXT does not have AUX channel.
public static readonly string[] MUSE_SMXT_EEG_CHANNEL_LABELS = new string[MUSE_SMXT_EEG_CHANNEL_COUNT]
{
"TP9",
"AF7",
"AF8",
"TP10",
};

public const string TIMESTAMP_FORMAT_BLUEMUSE_UNIX = "BLUEMUSE";
public const string TIMESTAMP_FORMAT_LSL_LOCAL_CLOCK_BLUEMUSE = "LSL_LOCAL_CLOCK_BLUEMUSE";
public const string TIMESTAMP_FORMAT_LSL_LOCAL_CLOCK_NATIVE = "LSL_LOCAL_CLOCK_NATIVE";
Expand Down
Loading

0 comments on commit 5a4b147

Please sign in to comment.