Skip to content

Commit 8257691

Browse files
committed
fixing muse anthena implementation
Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
1 parent 12daeaf commit 8257691

20 files changed

Lines changed: 217 additions & 52 deletions

File tree

cpp_package/src/board_shim.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,18 @@ std::vector<int> BoardShim::get_ppg_channels (int board_id, int preset)
508508
return std::vector<int> (channels, channels + len);
509509
}
510510

511+
std::vector<int> BoardShim::get_optical_channels (int board_id, int preset)
512+
{
513+
int channels[MAX_CHANNELS];
514+
int len = 0;
515+
int res = ::get_optical_channels (board_id, preset, channels, &len);
516+
if (res != (int)BrainFlowExitCodes::STATUS_OK)
517+
{
518+
throw BrainFlowException ("failed to get board info", res);
519+
}
520+
return std::vector<int> (channels, channels + len);
521+
}
522+
511523
std::vector<int> BoardShim::get_accel_channels (int board_id, int preset)
512524
{
513525
int channels[MAX_CHANNELS];

cpp_package/src/inc/board_shim.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class BoardShim
138138
*/
139139
static std::vector<int> get_ppg_channels (
140140
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
141+
/**
142+
* get row indices which hold optical data
143+
* @param board_id board id of your device
144+
* @throw BrainFlowException If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR
145+
*/
146+
static std::vector<int> get_optical_channels (
147+
int board_id, int preset = (int)BrainFlowPresets::DEFAULT_PRESET);
141148
/**
142149
* get row indices which hold EDA data
143150
* @param board_id board id of your device

csharp_package/brainflow/brainflow/board_controller_library.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public static class BoardControllerLibrary64
184184
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
185185
public static extern int get_ppg_channels (int board_id, int preset, int[] channels, int[] len);
186186
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
187+
public static extern int get_optical_channels (int board_id, int preset, int[] channels, int[] len);
188+
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
187189
public static extern int get_accel_channels (int board_id, int preset, int[] channels, int[] len);
188190
[DllImport ("BoardController", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
189191
public static extern int get_rotation_channels (int board_id, int preset, int[] channels, int[] len);
@@ -276,6 +278,8 @@ public static class BoardControllerLibrary32
276278
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
277279
public static extern int get_ppg_channels (int board_id, int preset, int[] channels, int[] len);
278280
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
281+
public static extern int get_optical_channels (int board_id, int preset, int[] channels, int[] len);
282+
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
279283
public static extern int get_accel_channels (int board_id, int preset, int[] channels, int[] len);
280284
[DllImport ("BoardController32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
281285
public static extern int get_rotation_channels (int board_id, int preset, int[] channels, int[] len);
@@ -774,6 +778,19 @@ public static int get_ppg_channels (int board_id, int preset, int[] channels, in
774778
return (int)BrainFlowExitCodes.GENERAL_ERROR;
775779
}
776780

781+
public static int get_optical_channels (int board_id, int preset, int[] channels, int[] len)
782+
{
783+
switch (PlatformHelper.get_library_environment ())
784+
{
785+
case LibraryEnvironment.x64:
786+
return BoardControllerLibrary64.get_optical_channels (board_id, preset, channels, len);
787+
case LibraryEnvironment.x86:
788+
return BoardControllerLibrary32.get_optical_channels (board_id, preset, channels, len);
789+
}
790+
791+
return (int)BrainFlowExitCodes.GENERAL_ERROR;
792+
}
793+
777794
public static int get_accel_channels (int board_id, int preset, int[] channels, int[] len)
778795
{
779796
switch (PlatformHelper.get_library_environment ())

csharp_package/brainflow/brainflow/board_descr.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class BoardDescr
1818
[DataMember]
1919
public int[] ppg_channels;
2020
[DataMember]
21+
public int[] optical_channels;
22+
[DataMember]
2123
public int[] eda_channels;
2224
[DataMember]
2325
public int[] accel_channels;
@@ -54,6 +56,7 @@ public BoardDescr ()
5456
exg_channels = null;
5557
emg_channels = null;
5658
ppg_channels = null;
59+
optical_channels = null;
5760
eda_channels = null;
5861
accel_channels = null;
5962
rotation_channels = null;

csharp_package/brainflow/brainflow/board_shim.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,30 @@ public static int[] get_ppg_channels (int board_id, int preset = (int)BrainFlowP
441441
return result;
442442
}
443443

444+
/// <summary>
445+
/// get row indices which hold optical data
446+
/// </summary>
447+
/// <param name="board_id"></param>
448+
/// <param name="preset">preset for device</param>
449+
/// <returns>array of row nums</returns>
450+
/// <exception cref="BrainFlowException">If this board has no such data exit code is UNSUPPORTED_BOARD_ERROR</exception>
451+
public static int[] get_optical_channels (int board_id, int preset = (int)BrainFlowPresets.DEFAULT_PRESET)
452+
{
453+
int[] len = new int[1];
454+
int[] channels = new int[512];
455+
int res = BoardControllerLibrary.get_optical_channels (board_id, preset, channels, len);
456+
if (res != (int)BrainFlowExitCodes.STATUS_OK)
457+
{
458+
throw new BrainFlowError (res);
459+
}
460+
int[] result = new int[len[0]];
461+
for (int i = 0; i < len[0]; i++)
462+
{
463+
result[i] = channels[i];
464+
}
465+
return result;
466+
}
467+
444468
/// <summary>
445469
/// get row indices which hold accel data
446470
/// </summary>

java_package/brainflow/src/main/java/brainflow/BoardDescr.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class BoardDescr
1010
public List<Integer> exg_channels;
1111
public List<Integer> emg_channels;
1212
public List<Integer> ppg_channels;
13+
public List<Integer> optical_channels;
1314
public List<Integer> eda_channels;
1415
public List<Integer> accel_channels;
1516
public List<Integer> rotation_channels;
@@ -33,6 +34,7 @@ public BoardDescr ()
3334
exg_channels = null;
3435
emg_channels = null;
3536
ppg_channels = null;
37+
optical_channels = null;
3638
eda_channels = null;
3739
accel_channels = null;
3840
rotation_channels = null;

java_package/brainflow/src/main/java/brainflow/BoardShim.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ int get_current_board_data (int num_samples, int preset, double[] data_buf, int[
8282

8383
int get_ppg_channels (int board_id, int preset, int[] ppg_channels, int[] len);
8484

85+
int get_optical_channels (int board_id, int preset, int[] optical_channels, int[] len);
86+
8587
int get_accel_channels (int board_id, int preset, int[] accel_channels, int[] len);
8688

8789
int get_rotation_channels (int board_id, int preset, int[] rotation_channels, int[] len);
@@ -1108,6 +1110,50 @@ public static int[] get_ppg_channels (BoardIds board_id) throws BrainFlowError
11081110
return get_ppg_channels (board_id.get_code ());
11091111
}
11101112

1113+
/**
1114+
* get row indices in returned by get_board_data() 2d array which contain
1115+
* optical data
1116+
*/
1117+
public static int[] get_optical_channels (int board_id, BrainFlowPresets preset) throws BrainFlowError
1118+
{
1119+
int[] len = new int[1];
1120+
int[] channels = new int[512];
1121+
int ec = instance.get_optical_channels (board_id, preset.get_code (), channels, len);
1122+
if (ec != BrainFlowExitCode.STATUS_OK.get_code ())
1123+
{
1124+
throw new BrainFlowError ("Error in board info getter", ec);
1125+
}
1126+
1127+
return Arrays.copyOfRange (channels, 0, len[0]);
1128+
}
1129+
1130+
/**
1131+
* get row indices in returned by get_board_data() 2d array which contain
1132+
* optical data
1133+
*/
1134+
public static int[] get_optical_channels (int board_id) throws BrainFlowError
1135+
{
1136+
return get_optical_channels (board_id, BrainFlowPresets.DEFAULT_PRESET);
1137+
}
1138+
1139+
/**
1140+
* get row indices in returned by get_board_data() 2d array which contain
1141+
* optical data
1142+
*/
1143+
public static int[] get_optical_channels (BoardIds board_id, BrainFlowPresets preset) throws BrainFlowError
1144+
{
1145+
return get_optical_channels (board_id.get_code (), preset);
1146+
}
1147+
1148+
/**
1149+
* get row indices in returned by get_board_data() 2d array which contain
1150+
* optical data
1151+
*/
1152+
public static int[] get_optical_channels (BoardIds board_id) throws BrainFlowError
1153+
{
1154+
return get_optical_channels (board_id.get_code ());
1155+
}
1156+
11111157
/**
11121158
* get row indices in returned by get_board_data() 2d array which contain accel
11131159
* data

julia_package/brainflow/src/board_shim.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ channel_function_names = (
202202
:get_eog_channels,
203203
:get_eda_channels,
204204
:get_ppg_channels,
205+
:get_optical_channels,
205206
:get_accel_channels,
206207
:get_rotation_channels,
207208
:get_analog_channels,

matlab_package/brainflow/BoardShim.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ function log_message(log_level, message)
269269
ppg_channels = data.Value(1,1:num_channels.Value) + 1;
270270
end
271271

272+
function optical_channels = get_optical_channels(board_id, preset)
273+
% get optical channels for provided board id
274+
task_name = 'get_optical_channels';
275+
num_channels = libpointer('int32Ptr', 0);
276+
data = libpointer('int32Ptr', zeros(1, 512));
277+
lib_name = BoardShim.load_lib();
278+
exit_code = calllib(lib_name, task_name, board_id, preset, data, num_channels);
279+
BoardShim.check_ec(exit_code, task_name);
280+
optical_channels = data.Value(1,1:num_channels.Value) + 1;
281+
end
282+
272283
function eda_channels = get_eda_channels(board_id, preset)
273284
% get eda channels for provided board id
274285
task_name = 'get_eda_channels';

nodejs_package/brainflow/board_shim.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class BoardControllerDLL extends BoardControllerFunctions
8989
this.getEogChannels = this.lib.func(CLike.get_eog_channels);
9090
this.getEcgChannels = this.lib.func(CLike.get_ecg_channels);
9191
this.getPpgChannels = this.lib.func(CLike.get_ppg_channels);
92+
this.getOpticalChannels = this.lib.func(CLike.get_optical_channels);
9293
this.getEdaChannels = this.lib.func(CLike.get_eda_channels);
9394
this.getAccelChannels = this.lib.func(CLike.get_accel_channels);
9495
this.getRotationChannels = this.lib.func(CLike.get_rotation_channels);
@@ -546,6 +547,21 @@ export class BoardShim
546547
return сhannels.slice(0, numChannels[0]);
547548
}
548549

550+
public static getOpticalChannels(
551+
boardId: BoardIds, preset = BrainFlowPresets.DEFAULT_PRESET): number[]
552+
{
553+
const numChannels = [0];
554+
const сhannels = [...new Array (512).fill(0)];
555+
const res =
556+
BoardControllerDLL.getInstance().getOpticalChannels(
557+
boardId, preset, сhannels, numChannels);
558+
if (res !== BrainFlowExitCodes.STATUS_OK)
559+
{
560+
throw new BrainFlowError (res, 'Could not get board info');
561+
}
562+
return сhannels.slice(0, numChannels[0]);
563+
}
564+
549565
public static getEdaChannels(
550566
boardId: BoardIds, preset = BrainFlowPresets.DEFAULT_PRESET): number[]
551567
{

0 commit comments

Comments
 (0)