Skip to content

Commit a345813

Browse files
authored
Merge pull request #1 from lucidcode/feature/add-boards
Add board list
2 parents fd03fac + 6b98777 commit a345813

File tree

9 files changed

+368
-51
lines changed

9 files changed

+368
-51
lines changed

BrainFlow/Board.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace lucidcode.LucidScribe.Plugin.BrainFlow
4+
{
5+
internal class Board
6+
{
7+
[JsonProperty(PropertyName = "name")]
8+
public string Name { get; set; }
9+
10+
[JsonProperty(PropertyName = "type")]
11+
public string Type { get; set; }
12+
13+
[JsonProperty(PropertyName = "id")]
14+
public int Id { get; set; }
15+
}
16+
}

BrainFlow/BrainFlow.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@
8080
<SpecificVersion>False</SpecificVersion>
8181
<HintPath>Dependencies\lucidcode.LucidScribe.Interface.Illuminated.dll</HintPath>
8282
</Reference>
83+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
84+
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
85+
</Reference>
8386
<Reference Include="System" />
8487
<Reference Include="System.Data" />
8588
<Reference Include="System.Drawing" />
8689
<Reference Include="System.Windows.Forms" />
8790
<Reference Include="System.Xml" />
8891
</ItemGroup>
8992
<ItemGroup>
93+
<Compile Include="Board.cs" />
9094
<Compile Include="Channels\Channel16.cs" />
9195
<Compile Include="Channels\Channel15.cs" />
9296
<Compile Include="Channels\Channel14.cs" />
@@ -118,6 +122,9 @@
118122
</EmbeddedResource>
119123
</ItemGroup>
120124
<ItemGroup>
125+
<None Include="brainflow_boards.json">
126+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
127+
</None>
121128
<None Include="packages.config" />
122129
</ItemGroup>
123130
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

BrainFlow/ConnectForm.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Windows.Forms;
33
using System.Xml;
44
using System.IO;
5+
using System.Collections.Generic;
6+
using Newtonsoft.Json;
7+
using System.Linq;
58

69
namespace lucidcode.LucidScribe.Plugin.BrainFlow
710
{
811
public partial class ConnectForm : Form
912
{
10-
1113
public string Algorithm = "REM Detection";
1214
public string BoardId;
1315
public string IpAddress;
@@ -22,6 +24,8 @@ public partial class ConnectForm : Form
2224

2325
public int Threshold = 600;
2426

27+
private List<Board> Boards;
28+
2529
private string lucidScribePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\lucidcode\\Lucid Scribe\\";
2630

2731
public ConnectForm()
@@ -31,9 +35,26 @@ public ConnectForm()
3135

3236
private void ConnectForm_Load(object sender, EventArgs e)
3337
{
38+
LoadBoards();
3439
LoadSettings();
3540
}
3641

42+
private void LoadBoards()
43+
{
44+
if (!File.Exists("brainflow_boards.json"))
45+
{
46+
return;
47+
}
48+
49+
var json = File.ReadAllText("brainflow_boards.json");
50+
Boards = JsonConvert.DeserializeObject<List<Board>>(json);
51+
52+
foreach (var board in Boards)
53+
{
54+
boardComboBox.Items.Add($"{board.Type} - {board.Name}");
55+
}
56+
}
57+
3758
private void LoadSettings()
3859
{
3960
XmlDocument xmlSettings = new XmlDocument();
@@ -44,6 +65,7 @@ private void LoadSettings()
4465
defaultSettings += " <Plugin>\r\n";
4566
defaultSettings += " <Algorithm>REM Detection</Algorithm>\r\n";
4667
defaultSettings += " <Threshold>600</Threshold>\r\n";
68+
defaultSettings += " <Board>BrainFlow - Synthetic</Board>\r\n";
4769
defaultSettings += " <BoardId>-1</BoardId>\r\n";
4870
defaultSettings += " <IpAddress></IpAddress>\r\n";
4971
defaultSettings += " <IpPort></IpPort>\r\n";
@@ -61,6 +83,11 @@ private void LoadSettings()
6183

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

86+
if (xmlSettings.DocumentElement.SelectSingleNode("//Board") != null)
87+
{
88+
boardComboBox.Text = xmlSettings.DocumentElement.SelectSingleNode("//Board").InnerText;
89+
}
90+
6491
cmbAlgorithm.Text = xmlSettings.DocumentElement.SelectSingleNode("//Algorithm").InnerText;
6592
thresholdText.Text = xmlSettings.DocumentElement.SelectSingleNode("//Threshold").InnerText;
6693
boardIdText.Text = xmlSettings.DocumentElement.SelectSingleNode("//BoardId").InnerText;
@@ -99,6 +126,7 @@ private void SaveSettings()
99126
settings += " <Plugin>\r\n";
100127
settings += " <Algorithm>" + cmbAlgorithm.Text + "</Algorithm>\r\n";
101128
settings += " <Threshold>" + thresholdText.Text + "</Threshold>\r\n";
129+
settings += " <Board>" + boardComboBox.Text + "</Board>\r\n";
102130
settings += " <BoardId>" + boardIdText.Text + "</BoardId>\r\n";
103131
settings += " <IpAddress>" + ipAddressText.Text + "</IpAddress>\r\n";
104132
settings += " <IpPort>" + ipPortText.Text + "</IpPort>\r\n";
@@ -169,6 +197,16 @@ private void fileText_TextChanged(object sender, EventArgs e)
169197
FileInput = fileText.Text;
170198
}
171199

200+
private void boardComboBox_SelectedIndexChanged(object sender, EventArgs e)
201+
{
202+
var board = Boards.FirstOrDefault(b => ($"{b.Type} - {b.Name}") == boardComboBox.Text);
203+
204+
if (board != null)
205+
{
206+
boardIdText.Text = board.Id.ToString();
207+
}
208+
}
209+
172210
private void cancelButton_Click(object sender, EventArgs e)
173211
{
174212
DialogResult = DialogResult.Cancel;

0 commit comments

Comments
 (0)