Skip to content

Commit

Permalink
restore support for pieeg (#729)
Browse files Browse the repository at this point in the history
* restore support for pieeg

Signed-off-by: Andrey Parfenov <[email protected]>

Author:    Nick Gamb <[email protected]>
Date:      Sun Jun 30 02:40:04 2024 +0200
  • Loading branch information
Andrey1994 committed Jul 14, 2024
1 parent a0b554d commit ebe6c25
Show file tree
Hide file tree
Showing 59 changed files with 10,429 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ option (BUILD_BLUETOOTH "BUILD_BLUETOOTH" OFF)
option (BUILD_BLE "BUILD_BLE" OFF)
option (BUILD_ONNX "BUILD_ONNX" OFF)
option (BUILD_TESTS "BUILD_TESTS" OFF)
option (BUILD_PERIPHERY "BUILD_PERIPHERY" OFF)

include (${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros.cmake)
configure_msvc_runtime ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public enum BoardIds
FREEEEG128_BOARD = 52,
AAVAA_V3_BOARD = 53,
EXPLORE_PLUS_8_CHAN_BOARD = 54,
EXPLORE_PLUS_32_CHAN_BOARD = 55
EXPLORE_PLUS_32_CHAN_BOARD = 55,
PIEEG_BOARD = 56
};


Expand Down
37 changes: 37 additions & 0 deletions docs/SupportedBoards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1268,3 +1268,40 @@ Available :ref:`presets-label`:
- :code:`BrainFlowPresets.DEFAULT_PRESET`, it contains accelerometer, gyroscope and magnetometer data
- :code:`BrainFlowPresets.AUXILIARY_PRESET`, it contains PPG data
- :code:`BrainFlowPresets.ANCILLARY_PRESET`, it contains EDA and temperature data

PiEEG
------

PiEEG Board
~~~~~~~~~~~

PiEEG (Measure EEG with RaspberryPi) – Brain-computer interface (EEG, EMG, and ECG bio-signals) is an open-source Raspberry Pi shield that measures biosignals such as those used in electroencephalography (EEG), electromyography (EMG), and electrocardiography (ECG). It integrates seamlessly with BrainFlow's API, allowing for easy data streaming, processing, and analysis.

.. image:: https://live.staticflickr.com/65535/53823500137_3bf2e27dbf_z.jpg
:width: 640px
:height: 384px

`PiEEG Website <https://pieeg.com/>`_

To create such a board, you need to specify the following board ID and fields of the BrainFlowInputParams object:

- :code:`BoardIds.PIEEG_BOARD`
- :code:`serial_port`(optional), e.g., COM3, /dev/spidev0.0, etc.
Initialization Example:
.. code-block:: python
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
params = BrainFlowInputParams()
params.serial_port = "/dev/spidev0.0"
board = BoardShim(BoardIds.PIEEG_BOARD, params)
board.prepare_session()
board.start_stream()
Supported platforms:
- Raspberry Pi
**Note**: Ensure that you have the necessary permissions to access the serial port on your operating system. For Unix-like systems, you may need to configure permissions for the serial port or run with sudo.
**To use this board you need to compile BrainFlow from the source code right on your Raspbery Pi device with flag --build-periphery(build.py) or with -DBUILD_PERIPHERY=ON(CMake) and install desired bindings using local libraries.**
3 changes: 2 additions & 1 deletion java_package/brainflow/src/main/java/brainflow/BoardIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public enum BoardIds
FREEEEG128_BOARD (52),
AAVAA_V3_BOARD(53),
EXPLORE_PLUS_8_CHAN_BOARD(54),
EXPLORE_PLUS_32_CHAN_BOARD(55);
EXPLORE_PLUS_32_CHAN_BOARD(55),
PIEEG_BOARD(56);

private final int board_id;
private static final Map<Integer, BoardIds> bi_map = new HashMap<Integer, BoardIds> ();
Expand Down
1 change: 1 addition & 0 deletions julia_package/brainflow/src/board_shim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export BrainFlowInputParams
AAVAA_V3_BOARD = 53
EXPLORE_PLUS_8_CHAN_BOARD = 54
EXPLORE_PLUS_32_CHAN_BOARD = 55
PIEEG_BOARD = 56

end

Expand Down
1 change: 1 addition & 0 deletions matlab_package/brainflow/BoardIds.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
AAVAA_V3_BOARD(53)
EXPLORE_PLUS_8_CHAN_BOARD(54)
EXPLORE_PLUS_32_CHAN_BOARD(55)
PIEEG_BOARD(56)
end
end
3 changes: 2 additions & 1 deletion nodejs_package/brainflow/brainflow.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export enum BoardIds {
NTL_WIFI_BOARD = 50,
ANT_NEURO_EE_511_BOARD = 51,
EXPLORE_PLUS_8_CHAN_BOARD = 54,
EXPLORE_PLUS_32_CHAN_BOARD = 55
EXPLORE_PLUS_32_CHAN_BOARD = 55,
PIEEG_BOARD = 56
}

export enum IpProtocolTypes {
Expand Down
1 change: 1 addition & 0 deletions python_package/brainflow/board_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class BoardIds(enum.IntEnum):
AAVAA_V3_BOARD = 53 #:
EXPLORE_PLUS_8_CHAN_BOARD = 54 #:
EXPLORE_PLUS_32_CHAN_BOARD = 55 #:
PIEEG_BOARD = 56 #:


class IpProtocolTypes(enum.IntEnum):
Expand Down
4 changes: 4 additions & 0 deletions src/board_controller/board_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "muse_bled.h"
#include "notion_osc.h"
#include "ntl_wifi.h"
#include "pieeg_board.h"
#include "playback_file_board.h"
#include "streaming_board.h"
#include "synthetic_board.h"
Expand Down Expand Up @@ -277,6 +278,9 @@ int prepare_session (int board_id, const char *json_brainflow_input_params)
case BoardIds::EXPLORE_PLUS_32_CHAN_BOARD:
board = std::shared_ptr<Board> (new Explore (board_id, params));
break;
case BoardIds::PIEEG_BOARD:
board = std::shared_ptr<Board> (new PIEEGBoard (board_id, params));
break;
default:
return (int)BrainFlowExitCodes::UNSUPPORTED_BOARD_ERROR;
}
Expand Down
15 changes: 14 additions & 1 deletion src/board_controller/brainflow_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ BrainFlowBoards::BrainFlowBoards()
{"50", json::object()},
{"51", json::object()},
{"52", json::object()},
{"53", json::object()}
{"53", json::object()},
{"54", json::object()},
{"55", json::object()},
{"56", json::object()}
}
}};

Expand Down Expand Up @@ -1082,6 +1085,16 @@ BrainFlowBoards::BrainFlowBoards()
{"battery_channel", 2},
{"other_channels", {3}}
};
brainflow_boards_json["boards"]["56"]["default"] = {
{"name", "PIEEG"},
{"sampling_rate", 250},
{"package_num_channel", 0},
{"timestamp_channel", 9},
{"marker_channel", 10},
{"num_rows", 11},
{"eeg_channels", {1, 2, 3, 4, 5, 6, 7, 8}},
{"eeg_names", "Fp1,Fp2,C3,C4,P7,P8,O1,O2"}
};
}

BrainFlowBoards boards_struct;
9 changes: 9 additions & 0 deletions src/board_controller/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SET (BOARD_CONTROLLER_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/emotibit/emotibit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/ntl/ntl_wifi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/aavaa/aavaa_v3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/pieeg/pieeg_board.cpp
)

include (${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/ant_neuro/build.cmake)
Expand Down Expand Up @@ -140,6 +141,7 @@ target_include_directories (
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/emotibit/inc
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/ntl/inc
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/aavaa/inc
${CMAKE_CURRENT_SOURCE_DIR}/src/board_controller/pieeg/inc
)

target_compile_definitions(${BOARD_CONTROLLER_NAME} PRIVATE NOMINMAX BRAINFLOW_VERSION=${BRAINFLOW_VERSION})
Expand Down Expand Up @@ -168,6 +170,13 @@ if (USE_LIBFTDI)
endif (LibFTDI1_FOUND)
endif (USE_LIBFTDI)

if (BUILD_PERIPHERY)
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/third_party/periphery)
target_compile_definitions (${BOARD_CONTROLLER_NAME} PRIVATE USE_PERIPHERY)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/third_party/periphery)
target_link_libraries (${BOARD_CONTROLLER_NAME} PRIVATE periphery ${CMAKE_THREAD_LIBS_INIT} dl)
endif (BUILD_PERIPHERY)

if (MSVC)
add_custom_command (TARGET ${BOARD_CONTROLLER_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/compiled/$<CONFIG>/${BOARD_CONTROLLER_COMPILED_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/nodejs_package/brainflow/lib/${BOARD_CONTROLLER_COMPILED_NAME}"
Expand Down
40 changes: 40 additions & 0 deletions src/board_controller/pieeg/inc/pieeg_board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <string>
#include <thread>

#include "board.h"
#include "board_controller.h"
#include "math.h"
#include "socket_server_tcp.h"

#ifdef USE_PERIPHERY
#include "gpio.h"
#include "spi.h"
#endif

class PIEEGBoard : public Board
{
protected:
#ifdef USE_PERIPHERY
volatile bool keep_alive;
bool initialized;
std::thread streaming_thread;
spi_t *spi;
gpio_t *gpio_in;
SocketServerTCP *server_socket;
void read_thread ();
int write_reg (uint8_t reg_address, uint8_t val);
int send_command (uint8_t command);
#endif

public:
PIEEGBoard (int board_id, struct BrainFlowInputParams params);
~PIEEGBoard ();

int prepare_session ();
int start_stream (int buffer_size, const char *streamer_params);
int stop_stream ();
int release_session ();
int config_board (std::string config, std::string &response);
};
Loading

0 comments on commit ebe6c25

Please sign in to comment.