Skip to content

Commit

Permalink
Merge branch 'master' into pieeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey1994 committed Jul 4, 2024
2 parents 1b69409 + a0b554d commit e50d5a1
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 49 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/deploy_cpp_libs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
max-parallel: 16
matrix:
build_type: [Release, Debug]
os: [ubuntu-latest, macos-11.0]
os: [ubuntu-latest, macos-12]

steps:
- name: Clone Repository
Expand All @@ -69,13 +69,13 @@ jobs:
with:
cmake-version: '3.21.x'
- name: Install Ninja
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
uses: seanmiddleditch/gha-setup-ninja@master
with:
version: 1.10.2
# build simpleble outside from brainflow because of different deployment targets
- name: Compile SimpleBLE MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
mkdir $GITHUB_WORKSPACE/third_party/SimpleBLE/simpleble/build
cd $GITHUB_WORKSPACE/third_party/SimpleBLE/simpleble/build
Expand All @@ -86,7 +86,7 @@ jobs:
env:
BUILD: ${{ matrix.build_type }}
- name: Compile BrainFlow for MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
mkdir $GITHUB_WORKSPACE/build
cd $GITHUB_WORKSPACE/build
Expand All @@ -99,9 +99,8 @@ jobs:
- name: Compile BrainFlow in ManyLinux
if: (matrix.os == 'ubuntu-latest')
run: |
docker pull dockcross/manylinux2014-x64:20210708-94745ff
docker run -e GITHUB_WORKSPACE=$GITHUB_WORKSPACE -e BUILD=$BUILD -v $GITHUB_WORKSPACE:$GITHUB_WORKSPACE dockcross/manylinux2014-x64:20210708-94745ff /bin/bash -c "yum install -y bluez-libs-devel dbus-devel && /opt/python/cp36-cp36m/bin/pip3.6 install cmake==3.21.4 && cd $GITHUB_WORKSPACE && mkdir build_docker && cd build_docker && /opt/_internal/cpython-3.6.14/bin/cmake -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/artifacts/linux_${BUILD} -DCMAKE_BUILD_TYPE=$BUILD .. && make && make install"
docker pull dockcross/manylinux_2_28-x64:20240418-88c04a4
docker run -e GITHUB_WORKSPACE=$GITHUB_WORKSPACE -e BUILD=$BUILD -v $GITHUB_WORKSPACE:$GITHUB_WORKSPACE dockcross/manylinux_2_28-x64:20240418-88c04a4 /bin/bash -c "yum install -y bluez-libs-devel dbus-devel && /opt/python/cp36-cp36m/bin/pip3.6 install cmake==3.21.4 && cd $GITHUB_WORKSPACE && mkdir build_docker && cd build_docker && /opt/_internal/cpython-3.6.15/bin/cmake -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/artifacts/linux_${BUILD} -DCMAKE_BUILD_TYPE=$BUILD .. && make && make install"
env:
BUILD: ${{ matrix.build_type }}
- name: Upload Artifacts
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/run_unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
os: [ubuntu-20.04, macos-11.0]
os: [ubuntu-20.04, macos-12]

steps:
# compile and prepare env
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
npm install -g ts-node
- name: Install Ninja
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
uses: seanmiddleditch/gha-setup-ninja@master
with:
version: 1.10.2
Expand All @@ -63,15 +63,15 @@ jobs:
java-version: 11.0.3
# build simpleble outside from brainflow because of different deployment targets
- name: Compile SimpleBLE MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
mkdir $GITHUB_WORKSPACE/third_party/SimpleBLE/simpleble/build
cd $GITHUB_WORKSPACE/third_party/SimpleBLE/simpleble/build
cmake -G Ninja -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/installed -DCMAKE_BUILD_TYPE=Release ..
ninja
ninja install
- name: Compile BrainFlow MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
mkdir $GITHUB_WORKSPACE/build
cd $GITHUB_WORKSPACE/build
Expand All @@ -94,8 +94,8 @@ jobs:
# bindings in production have to use libraries compiled inside this image!
if: (matrix.os == 'ubuntu-20.04')
run: |
docker pull dockcross/manylinux2014-x64:20210708-94745ff
docker run -e BRAINFLOW_VERSION=$BRAINFLOW_VERSION -e GITHUB_WORKSPACE=$GITHUB_WORKSPACE -v $GITHUB_WORKSPACE:$GITHUB_WORKSPACE dockcross/manylinux2014-x64:20210708-94745ff /bin/bash -c "yum install -y bluez-libs-devel dbus-devel && /opt/python/cp36-cp36m/bin/pip3.6 install cmake==3.21.4 && cd $GITHUB_WORKSPACE && mkdir build_docker && cd build_docker && /opt/_internal/cpython-3.6.14/bin/cmake -DBRAINFLOW_VERSION=$BRAINFLOW_VERSION -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/installed_docker -DCMAKE_BUILD_TYPE=Release .. && make && make install"
docker pull dockcross/manylinux_2_28-x64:20240418-88c04a4
docker run -e BRAINFLOW_VERSION=$BRAINFLOW_VERSION -e GITHUB_WORKSPACE=$GITHUB_WORKSPACE -v $GITHUB_WORKSPACE:$GITHUB_WORKSPACE dockcross/manylinux_2_28-x64:20240418-88c04a4 /bin/bash -c "yum install -y bluez-libs-devel dbus-devel && /opt/python/cp36-cp36m/bin/pip3.6 install cmake==3.21.4 && cd $GITHUB_WORKSPACE && mkdir build_docker && cd build_docker && /opt/_internal/cpython-3.6.15/bin/cmake -DBRAINFLOW_VERSION=$BRAINFLOW_VERSION -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/installed_docker -DCMAKE_BUILD_TYPE=Release .. && make && make install"
env:
BRAINFLOW_VERSION: ${{ steps.version.outputs.version }}
- name: C# build
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
- name: Run unit tests
run: $GITHUB_WORKSPACE/build/tests/brainflow_tests
- name: Synthetic C# Test MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
cd $GITHUB_WORKSPACE/csharp_package/brainflow/examples/brainflow_get_data/bin/Release/net7.0
cp $GITHUB_WORKSPACE/installed/lib/libBoardController.dylib $GITHUB_WORKSPACE/csharp_package/brainflow/examples/brainflow_get_data/bin/Release/net7.0/
Expand All @@ -164,7 +164,7 @@ jobs:
LD_LIBRARY_PATH: ${{ github.workspace }}/installed/lib
DYLD_LIBRARY_PATH: ${{ github.workspace }}/installed/lib
- name: EEG Metrics C# Test MacOS
if: (matrix.os == 'macos-11.0')
if: (matrix.os == 'macos-12')
run: |
cd $GITHUB_WORKSPACE/csharp_package/brainflow/examples/eeg_metrics/bin/Release/net7.0
cp $GITHUB_WORKSPACE/installed/lib/libBoardController.dylib $GITHUB_WORKSPACE/csharp_package/brainflow/examples/eeg_metrics/bin/Release/net7.0/
Expand Down Expand Up @@ -409,7 +409,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Push Libraries MacOS Dev
if: ${{ github.event_name == 'push' && matrix.os == 'macos-11.0' && github.repository == 'brainflow-dev/brainflow' }}
if: ${{ github.event_name == 'push' && matrix.os == 'macos-12' && github.repository == 'brainflow-dev/brainflow' }}
run: |
aws s3 cp $GITHUB_WORKSPACE/installed/lib/ s3://brainflow/$GITHUB_SHA/macos_release --recursive
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
os: [windows-2019]
os: [windows-2022]

steps:
# install dependencies
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
os: [ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0]
os: [ubuntu-20.04, macos-12]

steps:
# install dependencies
Expand All @@ -58,7 +58,7 @@ jobs:
with:
version: 1.3.1
- name: Install Python Dependencies
if: (matrix.os == 'ubuntu-18.04') || (matrix.os == 'ubuntu-20.04')
if: (matrix.os == 'ubuntu-20.04')
run: |
sudo -H apt-get update -y
sudo -H apt-get install -y python3-setuptools python3-pygments
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (WARNINGS_AS_ERRORS)
add_compile_options (/bigobj)
endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")
else ()
add_compile_options (-Werror -Wno-varargs)
add_compile_options (-Werror -Wno-varargs -Wno-error=deprecated-declarations)
endif ()
endif (WARNINGS_AS_ERRORS)

Expand Down
86 changes: 61 additions & 25 deletions src/board_controller/brainalive/brainalive.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include <string>

#include "brainalive.h"
#include "custom_cast.h"
#include "get_dll_dir.h"
#include "timestamp.h"

// common constants
#define BRAINALIVE_PACKET_SIZE 224
#include <string.h>

// info about services and chars
#define START_BYTE 0x0A
Expand All @@ -15,10 +11,6 @@
#define BRAINALIVE_WRITE_CHAR "0000fe41-8e22-4541-9d4c-21edae82ed19"
#define BRAINALIVE_NOTIFY_CHAR "0000fe42-8e22-4541-9d4c-21edae82ed19"

// info for equations
#define BRAINALIVE_EEG_SCALE_FACTOR 0.0476837158203125
#define BRAINALIVE_EEG_GAIN_VALUE 12


static void brainalive_adapter_1_on_scan_found (
simpleble_adapter_t adapter, simpleble_peripheral_t peripheral, void *board)
Expand All @@ -29,7 +21,16 @@ static void brainalive_adapter_1_on_scan_found (
static void brainalive_read_notifications (simpleble_uuid_t service,
simpleble_uuid_t characteristic, uint8_t *data, size_t size, void *board)
{
((BrainAlive *)(board))->read_data (service, characteristic, data, size, 0);
if (size == BrainAlive::brainalive_handshaking_packet_size)
{
((BrainAlive *)(board))->setSoftwareGain (data[1]);
((BrainAlive *)(board))->setHardwareGain (data[2]);
((BrainAlive *)(board))->setReferenceVoltage (((data[3] << 8) | data[4]));
}
else
{
((BrainAlive *)(board))->read_data (service, characteristic, data, size, 0);
}
}

BrainAlive::BrainAlive (struct BrainFlowInputParams params)
Expand Down Expand Up @@ -302,7 +303,6 @@ int BrainAlive::config_board (std::string config)
return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR;
}
uint8_t command[5];
size_t len = config.size ();
command[0] = 0x0a;
command[1] = 0x81; // it is hardcoded for now only
command[2] = 0x00;
Expand Down Expand Up @@ -342,7 +342,7 @@ void BrainAlive::adapter_1_on_scan_found (
}
else
{
if (strncmp (peripheral_identified, "ORION_1", 7) == 0)
if (strncmp (peripheral_identified, "BA_FLEX", 7) == 0)
{
found = true;
}
Expand Down Expand Up @@ -371,21 +371,57 @@ void BrainAlive::adapter_1_on_scan_found (
void BrainAlive::read_data (simpleble_uuid_t service, simpleble_uuid_t characteristic,
uint8_t *data, size_t size, int channel_num)
{
if (size != BRAINALIVE_PACKET_SIZE)
if (size == brainalive_packet_size)
{
safe_logger (spdlog::level::warn, "unknown size of BrainAlive Data {}", size);
return;
}

for (int i = 0; i < (int)size; i += 32)
{
double eeg_data[9] = {0};
for (int j = i + 4, k = 0; j < i + 28; j += 3, k++)
for (int i = 0; i < (int)size; i += brainalive_single_packet_size)
{
eeg_data[k] = (((data[j] << 16 | data[j + 1] << 8 | data[j + 2]) << 8) >> 8) *
BRAINALIVE_EEG_SCALE_FACTOR / BRAINALIVE_EEG_GAIN_VALUE;

int num_rows = board_descr["default"]["num_rows"];
double *package = new double[num_rows];
for (int i = 0; i < num_rows; i++)
{
package[i] = 0.0;
}
std::vector<int> eeg_channels = board_descr["default"]["eeg_channels"];
std::vector<int> accel_channels = board_descr["default"]["accel_channels"];
std::vector<int> gyro_channels = board_descr["default"]["gyro_channels"];

package[board_descr["default"]["package_num_channel"].get<int> ()] =
data[brainalive_packet_index + i];

for (int j = i + brainalive_eeg_Start_index, k = 0; j < i + brainalive_eeg_end_index;
j += 3, k++)
{
package[eeg_channels[k]] =
(float)(((data[j] << 16 | data[j + 1] << 8 | data[j + 2]) << 8) >> 8) *
((((float)getReferenceVoltage () * 1000) /
(float)(getSoftwareGain () * getHardwareGain () * FSR_Value)));
}

for (int j = i + brainalive_axl_start_index, k = 0; j < i + brainalive_axl_end_index;
j += 2, k++)
{
package[accel_channels[k]] = (data[j] << 8) | data[j + 1];
if (package[accel_channels[k]] > 32767)
package[accel_channels[k]] = package[accel_channels[k]] - 65535;
}
for (int j = i + brainalive_gyro_start_index, k = 0; j < i + brainalive_gyro_end_index;
j += 2, k++)
{
package[gyro_channels[k]] = (data[j] << 8) | data[j + 1];
if (package[gyro_channels[k]] > 32767)
package[gyro_channels[k]] = package[gyro_channels[k]] - 65535;
}
package[board_descr["default"]["marker_channel"].get<int> ()] =
data[(brainalive_packet_index + 1) + i];
package[board_descr["default"]["timestamp_channel"].get<int> ()] = get_timestamp ();

push_package (&package[0]);
}
eeg_data[8] = data[i + 29];
push_package (&eeg_data[0]);
}
else
{
safe_logger (spdlog::level::warn, "unknown size of BrainAlive Data {}", size);
return;
}
}
61 changes: 61 additions & 0 deletions src/board_controller/brainalive/inc/brainalive.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

class BrainAlive : public BLELibBoard
{

private:
int software_gain = 0;
int hardware_gain = 0;
int reference_voltage = 0;

public:
BrainAlive (struct BrainFlowInputParams params);
~BrainAlive ();
Expand All @@ -22,6 +28,61 @@ class BrainAlive : public BLELibBoard
void adapter_1_on_scan_found (simpleble_adapter_t adapter, simpleble_peripheral_t peripheral);
void read_data (simpleble_uuid_t service, simpleble_uuid_t characteristic, uint8_t *data,
size_t size, int channel_num);
void setSoftwareGain (int gain)
{
software_gain = gain;
}

void setHardwareGain (int gain)
{
hardware_gain = gain;
}

void setReferenceVoltage (int voltage)
{
reference_voltage = voltage;
}

int getSoftwareGain () const
{
return software_gain;
}

int getHardwareGain () const
{
return hardware_gain;
}

int getReferenceVoltage () const
{
return reference_voltage;
}

// common constants
static constexpr int brainalive_packet_size = 220;
static constexpr int brainalive_single_packet_size = 44;
static constexpr int num_of_packets = brainalive_packet_size / brainalive_single_packet_size;

static constexpr int brainalive_packet_index = (brainalive_single_packet_size - 3);

static constexpr int brainalive_eeg_data_szie = 24;
static constexpr int brainalive_eeg_Start_index = 4;
static constexpr int brainalive_eeg_end_index =
(brainalive_eeg_Start_index + brainalive_eeg_data_szie);

static constexpr int brainalive_axl_data_size = 6;
static constexpr int brainalive_gyro_data_size = 6;
static constexpr int brainalive_axl_start_index = brainalive_eeg_end_index;
static constexpr int brainalive_axl_end_index =
brainalive_axl_start_index + brainalive_axl_data_size;
static constexpr int brainalive_gyro_start_index = brainalive_axl_end_index;
static constexpr int brainalive_gyro_end_index =
brainalive_gyro_start_index + brainalive_gyro_data_size;
static constexpr int FSR_Value = 8388607;
static constexpr int ba_brainflow_package_size = 17;

static constexpr int brainalive_handshaking_packet_size = 6;


protected:
volatile simpleble_adapter_t brainalive_adapter;
Expand Down
8 changes: 4 additions & 4 deletions src/board_controller/brainflow_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,14 @@ BrainFlowBoards::BrainFlowBoards()
{
{"name", "BrainAlive"},
{"sampling_rate", 250},
{"timestamp_channel", 15},
{"marker_channel", 16},
{"package_num_channel", 0},
{"marker_channel", 15},
{"timestamp_channel", 16},
{"num_rows", 17},
{"package_num_channel", 0},
{"eeg_channels", {1, 2, 3, 4, 5, 6, 7, 8}},
{"eeg_names", "F7,FT7,T7,CP5,CZ,C6,FC6,F4"},
{"accel_channels", {9, 10, 11}},
{"ppg_channels", {12, 13, 14}}
{"gyro_channels", {12, 13, 14}}
};
brainflow_boards_json["boards"]["41"]["default"] =
{
Expand Down

0 comments on commit e50d5a1

Please sign in to comment.