Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BrainFlow/Board.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace lucidcode.LucidScribe.Plugin.BrainFlow
{
internal class Board
{
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
}
}
7 changes: 7 additions & 0 deletions BrainFlow/BrainFlow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>Dependencies\lucidcode.LucidScribe.Interface.Illuminated.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Board.cs" />
<Compile Include="Channels\Channel16.cs" />
<Compile Include="Channels\Channel15.cs" />
<Compile Include="Channels\Channel14.cs" />
Expand Down Expand Up @@ -118,6 +122,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="brainflow_boards.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
40 changes: 39 additions & 1 deletion BrainFlow/ConnectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;

namespace lucidcode.LucidScribe.Plugin.BrainFlow
{
public partial class ConnectForm : Form
{

public string Algorithm = "REM Detection";
public string BoardId;
public string IpAddress;
Expand All @@ -22,6 +24,8 @@ public partial class ConnectForm : Form

public int Threshold = 600;

private List<Board> Boards;

private string lucidScribePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\lucidcode\\Lucid Scribe\\";

public ConnectForm()
Expand All @@ -31,9 +35,26 @@ public ConnectForm()

private void ConnectForm_Load(object sender, EventArgs e)
{
LoadBoards();
LoadSettings();
}

private void LoadBoards()
{
if (!File.Exists("brainflow_boards.json"))
{
return;
}

var json = File.ReadAllText("brainflow_boards.json");
Boards = JsonConvert.DeserializeObject<List<Board>>(json);

foreach (var board in Boards)
{
boardComboBox.Items.Add($"{board.Type} - {board.Name}");
}
}

private void LoadSettings()
{
XmlDocument xmlSettings = new XmlDocument();
Expand All @@ -44,6 +65,7 @@ private void LoadSettings()
defaultSettings += " <Plugin>\r\n";
defaultSettings += " <Algorithm>REM Detection</Algorithm>\r\n";
defaultSettings += " <Threshold>600</Threshold>\r\n";
defaultSettings += " <Board>BrainFlow - Synthetic</Board>\r\n";
defaultSettings += " <BoardId>-1</BoardId>\r\n";
defaultSettings += " <IpAddress></IpAddress>\r\n";
defaultSettings += " <IpPort></IpPort>\r\n";
Expand All @@ -61,6 +83,11 @@ private void LoadSettings()

xmlSettings.Load(lucidScribePath + "Plugins\\BrainFlow.User.lsd");

if (xmlSettings.DocumentElement.SelectSingleNode("//Board") != null)
{
boardComboBox.Text = xmlSettings.DocumentElement.SelectSingleNode("//Board").InnerText;
}

cmbAlgorithm.Text = xmlSettings.DocumentElement.SelectSingleNode("//Algorithm").InnerText;
thresholdText.Text = xmlSettings.DocumentElement.SelectSingleNode("//Threshold").InnerText;
boardIdText.Text = xmlSettings.DocumentElement.SelectSingleNode("//BoardId").InnerText;
Expand Down Expand Up @@ -99,6 +126,7 @@ private void SaveSettings()
settings += " <Plugin>\r\n";
settings += " <Algorithm>" + cmbAlgorithm.Text + "</Algorithm>\r\n";
settings += " <Threshold>" + thresholdText.Text + "</Threshold>\r\n";
settings += " <Board>" + boardComboBox.Text + "</Board>\r\n";
settings += " <BoardId>" + boardIdText.Text + "</BoardId>\r\n";
settings += " <IpAddress>" + ipAddressText.Text + "</IpAddress>\r\n";
settings += " <IpPort>" + ipPortText.Text + "</IpPort>\r\n";
Expand Down Expand Up @@ -169,6 +197,16 @@ private void fileText_TextChanged(object sender, EventArgs e)
FileInput = fileText.Text;
}

private void boardComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
var board = Boards.FirstOrDefault(b => ($"{b.Type} - {b.Name}") == boardComboBox.Text);

if (board != null)
{
boardIdText.Text = board.Id.ToString();
}
}

private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Expand Down
Loading