Skip to content

Commit 6d280d0

Browse files
author
Andrey Parfenov
committed
Merge remote-tracking branch 'openbci/master'
2 parents cd42c9b + d032fc5 commit 6d280d0

16 files changed

+133
-65
lines changed

docs/Examples.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,30 @@ R Get Data from a Board
199199
.. literalinclude:: ../tests/r/brainflow_get_data.R
200200
:language: r
201201

202+
R Read Write File
203+
~~~~~~~~~~~~~~~~~~~
204+
205+
.. literalinclude:: ../tests/r/serialization.R
206+
:language: r
207+
208+
R Transforms
209+
~~~~~~~~~~~~~
210+
211+
.. literalinclude:: ../tests/r/transforms.R
212+
:language: r
213+
214+
R Signal Filtering
215+
~~~~~~~~~~~~~~~~~~~
216+
217+
.. literalinclude:: ../tests/r/signal_filtering.R
218+
:language: r
219+
220+
R Denoising
221+
~~~~~~~~~~~~~
222+
223+
.. literalinclude:: ../tests/r/denoising.R
224+
:language: r
225+
202226
Notebooks
203227
------------
204228
.. toctree::

docs/SupportedBoards.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ To create an instance of BoardShim class for your board check required inputs in
1313
"Cyton", "BoardIds.CYTON_BOARD (0)", "dongle serial port(COM3, /dev/ttyUSB0...)", "-", "-", "-", "-", "-"
1414
"Ganglion", "BoardIds.GANGLION_BOARD (1)", "dongle serial port(COM3, /dev/ttyUSB0...)", "Optional: Ganglion's MAC address", "-", "-", "-", "-"
1515
"Cyton Daisy", "BoardIds.CYTON_DAISY_BOARD (2)", "dongle serial port(COM3, /dev/ttyUSB0...)", "-", "-", "-", "-", "-"
16-
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(in direct mode 192.168.4.1)", "any local port which is free", "-", "-"
17-
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(in direct mode 192.168.4.1)", "any local port which is free", "-", "-"
18-
"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", "-", "-"
16+
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
17+
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
18+
"Cyton Daisy Wifi", "BoardIds.CYTON_DAISY_WIFI_BOARD (6)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
1919

2020
Streaming Board
2121
------------------

docs/UserAPI.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ R API Reference
101101
-----------------
102102

103103
R binding is a wrapper on top of Python binding, it is implemented using `reticulate <https://rstudio.github.io/reticulate/>`_.
104-
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**
105104

106-
Check R sample to see how to use it.
105+
Check R samples to see how to use it.
107106

108107
Full code for R binding:
109108

110-
.. literalinclude:: ../r-package/brainflow/R/board_shim.R
109+
.. literalinclude:: ../r-package/brainflow/R/package.R
111110
:language: r

r-package/brainflow/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Description: Provides an R Interface to the brainflow project
1111
Depends: R (>= 3.2.3)
1212
Encoding: UTF-8
1313
License: MIT
14-
RoxygenNote: 6.1.1
14+
RoxygenNote: 7.0.2
1515
Imports: reticulate
1616
Suggests: knitr
1717
VignetteBuilder: knitr

r-package/brainflow/NAMESPACE

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(BoardIds)
4-
export(get_board_shim_class)
5-
export(get_board_shim_object)
6-
export(get_brainflow_input_params)
3+
export(brainflow_python)
4+
export(np)
5+
export(pandas)
76
import(reticulate)

r-package/brainflow/R/board_shim.R

Lines changed: 0 additions & 37 deletions
This file was deleted.

r-package/brainflow/R/package.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#' @import reticulate
22
NULL
33

4-
brainflow <- NULL
4+
#' @export
5+
brainflow_python <- NULL
6+
#' @export
57
np <- NULL
8+
#' @export
69
pandas <- NULL
710
sys <- NULL
811
type_map <- NULL
912

1013
.onLoad <- function (libname, pkgname)
1114
{
12-
brainflow <<- import ('brainflow', delay_load = TRUE)
15+
brainflow_python <<- import ('brainflow', delay_load = TRUE)
1316
np <<- import ('numpy', delay_load = TRUE)
1417
pandas <<- import ('pandas', delay_load = TRUE)
1518
sys <<- import ('sys', delay_load = TRUE)

src/board_controller/openbci/inc/openbci_wifi_shield_board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OpenBCIWifiShieldBoard : public Board
1414
{
1515

1616
private:
17-
int wait_for_http_resp (http_t *request, int max_attempts = 3000);
17+
int wait_for_http_resp (http_t *request, int max_attempts = 500);
1818

1919
protected:
2020
volatile bool keep_alive;

src/board_controller/openbci/novaxr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ int NovaXR::prepare_session ()
3939
}
4040
if (params.ip_address.empty ())
4141
{
42-
safe_logger (spdlog::level::err, "ip address is empty");
43-
return INVALID_ARGUMENTS_ERROR;
42+
safe_logger (spdlog::level::info, "use default IP address 192.168.4.1");
43+
params.ip_address = "192.168.4.1";
4444
}
4545
if (params.ip_protocol == (int)IpProtocolType::TCP)
4646
{

src/board_controller/openbci/openbci_wifi_shield_board.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ int OpenBCIWifiShieldBoard::prepare_session ()
4141
}
4242
if (params.ip_address.empty ())
4343
{
44-
safe_logger (
45-
spdlog::level::err, "ip address is empty and autodiscovery is not implemented");
46-
return INVALID_ARGUMENTS_ERROR;
44+
safe_logger (spdlog::level::warn, "use default ip address 192.168.4.1");
45+
params.ip_address = "192.168.4.1";
4746
}
4847
// user doent need to provide this param because we have only tcp impl,
4948
// but if its specified and its UDP return an error

tests/r/brainflow_get_data.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
library(brainflow)
1+
library (brainflow)
22

3-
params <- get_brainflow_input_params()
4-
board_shim <- get_board_shim_object(BoardIds()$SYNTHETIC_BOARD["Id"], params)
5-
board_shim$prepare_session()
6-
board_shim$start_stream()
7-
Sys.sleep(time = 5)
8-
board_shim$stop_stream()
9-
data <- board_shim$get_current_board_data(as.integer(250))
10-
board_shim$release_session()
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()

tests/r/denoising.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library (brainflow)
2+
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()
11+
12+
# need to convert to numpy array manually
13+
numpy_data <- np$array (data[2,])
14+
print (numpy_data)
15+
brainflow_python$DataFilter$perform_wavelet_denoising (numpy_data, "db4", as.integer (3))
16+
print (numpy_data)

tests/r/downsampling.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library (brainflow)
2+
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()
11+
12+
# need to convert to numpy array manually
13+
numpy_data <- np$array (data[2,])
14+
print (numpy_data)
15+
brainflow_python$DataFilter$perform_downsampling (numpy_data, as.integer (3), brainflow_python$AggOperations$EACH$value)
16+
print (numpy_data)

tests/r/serialization.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library (brainflow)
2+
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()
11+
12+
brainflow_python$DataFilter$write_file (data, "test.csv", "w")
13+
data_restored <- brainflow_python$DataFilter$read_file ("test.csv")
14+
print (restored_data)

tests/r/signal_filtering.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library (brainflow)
2+
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()
11+
12+
# need to convert to numpy array manually
13+
numpy_data <- np$array (data[2,])
14+
print (numpy_data)
15+
sampling_rate <- board_shim$get_sampling_rate (brainflow_python$BoardIds$SYNTHETIC_BOARD$value)
16+
brainflow_python$DataFilter$perform_bandpass (numpy_data, sampling_rate, 10.0, 5.0, as.integer (3), brainflow_python$FilterTypes$BESSEL$value, 0)
17+
print (numpy_data)
18+

tests/r/transforms.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library (brainflow)
2+
3+
params <- brainflow_python$BrainFlowInputParams ()
4+
board_shim <- brainflow_python$BoardShim (brainflow_python$BoardIds$SYNTHETIC_BOARD$value, params)
5+
board_shim$prepare_session ()
6+
board_shim$start_stream ()
7+
Sys.sleep (time = 5)
8+
board_shim$stop_stream ()
9+
data <- board_shim$get_current_board_data (as.integer (250))
10+
board_shim$release_session ()
11+
12+
# need to convert to numpy array manually
13+
numpy_data <- np$array (data[2,])
14+
print (numpy_data)
15+
wavelet_data <- brainflow_python$DataFilter$perform_wavelet_transform (numpy_data, "db4", as.integer (3))
16+
restored_data <- brainflow_python$DataFilter$perform_inverse_wavelet_transform (wavelet_data, length (numpy_data), "db4", as.integer (3))
17+
print (restored_data)

0 commit comments

Comments
 (0)