Skip to content

Commit

Permalink
Merge branch 'master' into swift-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey1994 committed May 12, 2024
2 parents 9982ba8 + cf90732 commit 322c29c
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 100 deletions.
5 changes: 5 additions & 0 deletions docs/BuildBrainFlow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ Rust
cd brainflow
cargo build --features generate_binding

Swift
-------

You can build Swift binding for BrainFlow using xcode. Before that you need to compile C/C++ code :ref:`compilation-label` and ensure that native libraries are properly placed. Keep in mind that currently it supports only MacOS.

Docker Image
--------------

Expand Down
63 changes: 63 additions & 0 deletions docs/Examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,69 @@ Typescript ICA
.. literalinclude:: ../nodejs_package/tests/ica.ts
:language: javascript

Swift
------------

Swift Get Data from a Board
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/brainflow_get_data/brainflow_get_data.swift
:language: swift

Swift Markers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/markers/markers.swift
:language: swift

Swift Read Write File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/read_write_file/read_write_file.swift
:language: swift

Swift Downsample Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/downsampling/downsampling.swift
:language: swift

Swift Transforms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/transforms/transforms.swift
:language: swift

Swift Signal Filtering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/signal_filtering/signal_filtering.swift
:language: swift

Swift Denoising
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/denoising/denoising.swift
:language: swift

Swift Band Power
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/band_power/band_power.swift
:language: swift

Swift EEG Metrics
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/eeg_metrics/eeg_metrics.swift
:language: swift

Swift ICA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../swift_package/examples/tests/ica/ica.swift
:language: swift

Notebooks
------------
.. toctree::
Expand Down
10 changes: 10 additions & 0 deletions docs/UserAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ Example:

.. literalinclude:: ../nodejs_package/tests/brainflow_get_data.ts
:language: javascript

Swift
------

Swift binding calls C/C++ code as any other binding. Use Swift examples and API reference for other languaes as a starting point.

Example:

.. literalinclude:: ../swift_package/examples/tests/brainflow_get_data/brainflow_get_data.swift
:language: swift
13 changes: 6 additions & 7 deletions python_package/brainflow/board_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pkg_resources
from brainflow.exit_codes import BrainFlowExitCodes, BrainFlowError
from brainflow.utils import LogLevels
from nptyping import NDArray, Float64
from numpy.ctypeslib import ndpointer


Expand Down Expand Up @@ -777,7 +776,7 @@ def get_board_presets(cls, board_id: int) -> List[str]:
:type board_id: int
:return: presets for this board id
:rtype: List[str]
:raises BrainFlowError
:raises BrainFlowError: In case of internal error or invalid args
"""

num_presets = numpy.zeros(1).astype(numpy.int32)
Expand All @@ -795,7 +794,7 @@ def get_version(cls) -> str:
:return: version
:rtype: str
:raises BrainFlowError
:raises BrainFlowError: In case of internal error or invalid args
"""
string = numpy.zeros(64).astype(numpy.ubyte)
string_len = numpy.zeros(1).astype(numpy.int32)
Expand Down Expand Up @@ -1266,15 +1265,15 @@ def release_session(self) -> None:
if res != BrainFlowExitCodes.STATUS_OK.value:
raise BrainFlowError('unable to release streaming session', res)

def get_current_board_data(self, num_samples: int, preset: int = BrainFlowPresets.DEFAULT_PRESET) -> NDArray[Float64]:
def get_current_board_data(self, num_samples: int, preset: int = BrainFlowPresets.DEFAULT_PRESET):
"""Get specified amount of data or less if there is not enough data, doesnt remove data from ringbuffer
:param num_samples: max number of samples
:type num_samples: int
:param preset: preset
:type preset: int
:return: latest data from a board
:rtype: NDArray[Float64]
:rtype: NDArray[Shape["*, *"], Float64]
"""

package_length = BoardShim.get_num_rows(self._master_board_id, preset)
Expand Down Expand Up @@ -1345,15 +1344,15 @@ def is_prepared(self) -> bool:
raise BrainFlowError('unable to check session status', res)
return bool(prepared[0])

def get_board_data(self, num_samples=None, preset: int = BrainFlowPresets.DEFAULT_PRESET) -> NDArray[Float64]:
def get_board_data(self, num_samples=None, preset: int = BrainFlowPresets.DEFAULT_PRESET):
"""Get board data and remove data from ringbuffer
:param num_samples: number of packages to get
:type num_samples: int
:param preset: preset
:type preset: int
:return: all data from a board if num_samples is None, num_samples packages or less if not None
:rtype: NDArray[Float64]
:rtype: NDArray[Shape["*, *"], Float64]
"""

data_size = self.get_board_data_count(preset)
Expand Down
Loading

0 comments on commit 322c29c

Please sign in to comment.