Skip to content

Commit

Permalink
Merge remote-tracking branch 'openbci/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Parfenov committed Dec 19, 2019
2 parents cd42c9b + d032fc5 commit 6d280d0
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 65 deletions.
24 changes: 24 additions & 0 deletions docs/Examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,30 @@ R Get Data from a Board
.. literalinclude:: ../tests/r/brainflow_get_data.R
:language: r

R Read Write File
~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../tests/r/serialization.R
:language: r

R Transforms
~~~~~~~~~~~~~

.. literalinclude:: ../tests/r/transforms.R
:language: r

R Signal Filtering
~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../tests/r/signal_filtering.R
:language: r

R Denoising
~~~~~~~~~~~~~

.. literalinclude:: ../tests/r/denoising.R
:language: r

Notebooks
------------
.. toctree::
Expand Down
6 changes: 3 additions & 3 deletions docs/SupportedBoards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To create an instance of BoardShim class for your board check required inputs in
"Cyton", "BoardIds.CYTON_BOARD (0)", "dongle serial port(COM3, /dev/ttyUSB0...)", "-", "-", "-", "-", "-"
"Ganglion", "BoardIds.GANGLION_BOARD (1)", "dongle serial port(COM3, /dev/ttyUSB0...)", "Optional: Ganglion's MAC address", "-", "-", "-", "-"
"Cyton Daisy", "BoardIds.CYTON_DAISY_BOARD (2)", "dongle serial port(COM3, /dev/ttyUSB0...)", "-", "-", "-", "-", "-"
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(in direct mode 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(in direct mode 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Daisy Wifi", "BoardIds.CYTON_DAISY_WIFI_BOARD (6)", "-", "-", "Wifi Shield IP(in direct mode 192.168.4.1)", "any local port which is free", "-", "-"
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Daisy Wifi", "BoardIds.CYTON_DAISY_WIFI_BOARD (6)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"

Streaming Board
------------------
Expand Down
5 changes: 2 additions & 3 deletions docs/UserAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ R API Reference
-----------------

R binding is a wrapper on top of Python binding, it is implemented using `reticulate <https://rstudio.github.io/reticulate/>`_.
There are a few methods which allow you to create python objects and call their methods. **BrainFlow's Signal processing API is unavailable for R you need to perform signal processing in R by yourself**

Check R sample to see how to use it.
Check R samples to see how to use it.

Full code for R binding:

.. literalinclude:: ../r-package/brainflow/R/board_shim.R
.. literalinclude:: ../r-package/brainflow/R/package.R
:language: r
2 changes: 1 addition & 1 deletion r-package/brainflow/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description: Provides an R Interface to the brainflow project
Depends: R (>= 3.2.3)
Encoding: UTF-8
License: MIT
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Imports: reticulate
Suggests: knitr
VignetteBuilder: knitr
Expand Down
7 changes: 3 additions & 4 deletions r-package/brainflow/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(BoardIds)
export(get_board_shim_class)
export(get_board_shim_object)
export(get_brainflow_input_params)
export(brainflow_python)
export(np)
export(pandas)
import(reticulate)
37 changes: 0 additions & 37 deletions r-package/brainflow/R/board_shim.R

This file was deleted.

7 changes: 5 additions & 2 deletions r-package/brainflow/R/package.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#' @import reticulate
NULL

brainflow <- NULL
#' @export
brainflow_python <- NULL
#' @export
np <- NULL
#' @export
pandas <- NULL
sys <- NULL
type_map <- NULL

.onLoad <- function (libname, pkgname)
{
brainflow <<- import ('brainflow', delay_load = TRUE)
brainflow_python <<- import ('brainflow', delay_load = TRUE)
np <<- import ('numpy', delay_load = TRUE)
pandas <<- import ('pandas', delay_load = TRUE)
sys <<- import ('sys', delay_load = TRUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OpenBCIWifiShieldBoard : public Board
{

private:
int wait_for_http_resp (http_t *request, int max_attempts = 3000);
int wait_for_http_resp (http_t *request, int max_attempts = 500);

protected:
volatile bool keep_alive;
Expand Down
4 changes: 2 additions & 2 deletions src/board_controller/openbci/novaxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int NovaXR::prepare_session ()
}
if (params.ip_address.empty ())
{
safe_logger (spdlog::level::err, "ip address is empty");
return INVALID_ARGUMENTS_ERROR;
safe_logger (spdlog::level::info, "use default IP address 192.168.4.1");
params.ip_address = "192.168.4.1";
}
if (params.ip_protocol == (int)IpProtocolType::TCP)
{
Expand Down
5 changes: 2 additions & 3 deletions src/board_controller/openbci/openbci_wifi_shield_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ int OpenBCIWifiShieldBoard::prepare_session ()
}
if (params.ip_address.empty ())
{
safe_logger (
spdlog::level::err, "ip address is empty and autodiscovery is not implemented");
return INVALID_ARGUMENTS_ERROR;
safe_logger (spdlog::level::warn, "use default ip address 192.168.4.1");
params.ip_address = "192.168.4.1";
}
// user doent need to provide this param because we have only tcp impl,
// but if its specified and its UDP return an error
Expand Down
18 changes: 9 additions & 9 deletions tests/r/brainflow_get_data.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
library(brainflow)
library (brainflow)

params <- get_brainflow_input_params()
board_shim <- get_board_shim_object(BoardIds()$SYNTHETIC_BOARD["Id"], params)
board_shim$prepare_session()
board_shim$start_stream()
Sys.sleep(time = 5)
board_shim$stop_stream()
data <- board_shim$get_current_board_data(as.integer(250))
board_shim$release_session()
params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()
16 changes: 16 additions & 0 deletions tests/r/denoising.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library (brainflow)

params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()

# need to convert to numpy array manually
numpy_data <- np$array (data[2,])
print (numpy_data)
brainflow_python$DataFilter$perform_wavelet_denoising (numpy_data, "db4", as.integer (3))
print (numpy_data)
16 changes: 16 additions & 0 deletions tests/r/downsampling.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library (brainflow)

params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()

# need to convert to numpy array manually
numpy_data <- np$array (data[2,])
print (numpy_data)
brainflow_python$DataFilter$perform_downsampling (numpy_data, as.integer (3), brainflow_python$AggOperations$EACH$value)
print (numpy_data)
14 changes: 14 additions & 0 deletions tests/r/serialization.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
library (brainflow)

params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()

brainflow_python$DataFilter$write_file (data, "test.csv", "w")
data_restored <- brainflow_python$DataFilter$read_file ("test.csv")
print (restored_data)
18 changes: 18 additions & 0 deletions tests/r/signal_filtering.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
library (brainflow)

params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()

# need to convert to numpy array manually
numpy_data <- np$array (data[2,])
print (numpy_data)
sampling_rate <- board_shim$get_sampling_rate (brainflow_python$BoardIds$SYNTHETIC_BOARD$value)
brainflow_python$DataFilter$perform_bandpass (numpy_data, sampling_rate, 10.0, 5.0, as.integer (3), brainflow_python$FilterTypes$BESSEL$value, 0)
print (numpy_data)

17 changes: 17 additions & 0 deletions tests/r/transforms.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
library (brainflow)

params <- brainflow_python$BrainFlowInputParams ()
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
board_shim$prepare_session ()
board_shim$start_stream ()
Sys.sleep (time = 5)
board_shim$stop_stream ()
data <- board_shim$get_current_board_data (as.integer (250))
board_shim$release_session ()

# need to convert to numpy array manually
numpy_data <- np$array (data[2,])
print (numpy_data)
wavelet_data <- brainflow_python$DataFilter$perform_wavelet_transform (numpy_data, "db4", as.integer (3))
restored_data <- brainflow_python$DataFilter$perform_inverse_wavelet_transform (wavelet_data, length (numpy_data), "db4", as.integer (3))
print (restored_data)

0 comments on commit 6d280d0

Please sign in to comment.