22using System . Windows . Forms ;
33using System . Xml ;
44using System . IO ;
5+ using System . Collections . Generic ;
6+ using Newtonsoft . Json ;
7+ using System . Linq ;
58
69namespace 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