Giter Club home page Giter Club logo

neurosky-android-sdk's Introduction

NeuroSky Android SDK

Android SDK for the NeuroSky MindWave Mobile Brainwave Sensing Headset

Build Status codecov Maven Central

This SDK allows you to write mobile Android apps interacting with the brain via NeuroSky MindWave Mobile device connected to the phone or tablet via Bluetooth. You can write apps controlled by your brain or perform data acquisition and analysis of the brain signals (attention, meditation, brain waves, raw signal) and eye blinks. NeuroSky uses EEG technology for gathering brain data and EMG sensor for detecting blinks. NeuroSky Android SDK uses ThinkGear library under the hood, which was developed by the NeuroSky company.

Please note: this SDK is not a product of NeuroSky company, but it depends on its software and hardware

Contents

Usage

Java

Listener

// initialize NeuroSky object with listener
NeuroSky neuroSky = new NeuroSky(new ExtendedDeviceMessageListener() {
  @Override public void onStateChange(State state) {
    // handle state change...
  }

  @Override public void onSignalChange(Signal signal) {
    // handle signal change...
  }

  @Override public void onBrainWavesChange(Set<BrainWave> brainWaves) {
    // handle brain waves change...
  }
});

// connect to the device
try {
  neuroSky.connect();
} catch (BluetoothNotEnabledException e) {
  // handle exception...
}

// disconnect from the device
neuroSky.disconnect();

// start monitoring
neuroSky.start();

// stop monitoring
neuroSky.stop();

You can also create simpler listener with DeviceMessageListener interface and handle android.os.Message objects.

NeuroSky neuroSky = new NeuroSky(message -> {
  // handle message...
});

Nevertheless, in that case, you'll have to process and handle data manually.

RxJava

// initialize object
RxNeuroSky neuroSky = new RxNeuroSky();

// stream data
neuroSky
  .stream()
  .subscribeOn(Schedulers.computation())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(brainEvent -> {
    // handle state in brainEvent.state();
    // handle signal in brainEvent.signal();
    // handle brainwaves in brainEvent.brainWaves();
  });

// connect to the device
neuroSky
  .connect()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
      () -> /* is connecting... */,
      throwable -> { /* handle error...*/ }
  );

// start monitoring
neuroSky
  .start()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
    () -> /* started monitoring */,
    throwable -> { /* handle error...*/ }
   );

// stop monitoring
neuroSky
  .stop()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
    () -> /* stopped monitoring */,
    throwable -> { /* handle error...*/ }
   );

// disconnect from the device
neuroSky
  .disconnect()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
    () -> /* is disconnected */,
    throwable -> { /* handle error...*/ }
  );

Default backpressure strategy is BUFFER. In order to customize backpressure strategy, you can use the following method:

Flowable<BrainEvent> stream(backpressureStrategy)

Kotlin

Listener

// initialize NeuroSky object with listener
val neuroSky = NeuroSky(object : ExtendedDeviceMessageListener() {
  override fun onStateChange(state: State) {
    handleStateChange(state)
  }

  override fun onSignalChange(signal: Signal) {
    handleSignalChange(signal)
  }

  override fun onBrainWavesChange(brainWaves: Set<BrainWave>) {
    handleBrainWavesChange(brainWaves)
  }
})

// connect to the device
try {
  neuroSky.connect()
} catch (e: BluetoothNotEnabledException) {
  // handle exception...
}

// disconnect from the device
neuroSky.disconnect()

// start monitoring
neuroSky.start()

// stop monitoring
neuroSky.stop()

You can also create simpler listener with DeviceMessageListener interface and handle android.os.Message objects.

val neuroSky = NeuroSky(DeviceMessageListener {
  // handle message here...
})

Nevertheless, in that case, you'll have to process and handle data manually.

RxKotlin

//initialize object
val neuroSky = RxNeuroSky()

// stream data
neuroSky
  .stream()
  .subscribeOn(Schedulers.computation())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe {
    // handle state in it.state();
    // handle signal in it.signal();
    // handle brainwaves in it.brainWaves();
  }

// connect to the device
neuroSky
  .connect()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
      { /* is connecting... */ },
      { throwable -> /* handle error */ }
  )

// start monitoring
neuroSky
  .start()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
      { /* started monitoring */ },
      { throwable -> /* handle error */ }
  )

// stop monitoring
neuroSky
  .stop()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
      { /* stopped monitoring */ },
      { throwable -> /* handle error */ }
  )

// disconnect from the device
neuroSky
  .disconnect()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
      { /* is disconnected */ },
      { throwable -> /* handle error */ }
  )

Default backpressure strategy is BUFFER. In order to customize backpressure strategy, you can use the following method:

Flowable<BrainEvent> stream(backpressureStrategy)

Examples

You can find examples of library usage in the following directories:

  • app-java (example with listener)
  • app-kotlin (example with listener)
  • app-rxjava
  • app-rxkotlin

Download

You can depend on the library through Gradle:

dependencies {
  implementation 'com.github.pwittchen:neurosky-android-sdk:0.0.2'
}

Please note: this library is released as a fat aar and contains all its dependencies within a single *.aar file. It's done this way because this library depends on ThinkGear library, which is distributed as a ThinkGear.jar file by the NeuroSky company. ThinkGear is also not available on the Maven Central repository. I wanted to make usage of this library as simple as possible without bothering about additional dependencies and custom configuration. Now, with this approach we can add a single dependency to our project and we're good to go.

Tests

Tests are available in library/src/test/java/ directory and can be executed on JVM without any emulator or Android device from Android Studio or CLI with the following command:

./gradlew test

To generate test coverage report, run the following command:

./gradlew test jacocoTestReport

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static code analysis

Static code analysis runs Checkstyle, PMD and Lint. It can be executed with command:

./gradlew check

JavaDoc

JavaDoc is available at: http://pwittchen.github.io/neurosky-android-sdk/javadoc

Documentation

Documentation is available at: http://pwittchen.github.io/neurosky-android-sdk/docs

Changelog

See CHANGELOG.md file.

Releasing

See RELEASING.md file.

Verified devices

This SDK was tested with the following devices:

  • NeuroSky MindWave Mobile 1
  • NeuroSky MindWave Mobile 2

Device diagram

This is diagram of the NeuroSky MindWave Mobile 1

References

License

Copyright 2018 Piotr Wittchen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

neurosky-android-sdk's People

Contributors

dependabot-preview[bot] avatar pwittchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neurosky-android-sdk's Issues

Obtain the brainwaves

Is it possible to show all the Brainwaves on the screen? (Delta, High-alpha, Low-alpha etc...)

Issue with .isConnected() method

I already copied the code below to Gradle

dependencies { implementation 'com.github.pwittchen:neurosky-android-sdk:0.0.2' }

and imported com.github.pwittchen.neurosky.library.NeuroSky; in my project

then I tried to use neuroSky.isConnected() method but I got "Cannot resolve method 'isConnected()' in 'NeuroSky'" message

How could I fix it? Thanks

Create TGDevice simulator for testing purposes

It would be nice to have TGDevice object simulator for testing purposes or maybe to provide an abstraction over it in order to simulate object behavior without having physical MindWave Mobile device.

Release 0.0.2

Release notes:

  • updating value of the type of the mid gamma brain wave signal -> 45b8e29

I want to ask about value given for each brain waves band

Hello I'm currently using your work with neurosky mindwave mobile 2, so far its working fine.

I technically don't really understand about how the brain waves converted from raw data to each bands (alpha, beta, etc). But, when I use your work to collect brain waves data, some data show very high values, exceeding 16 million. These very high values also seem to have a pattern that is like 167xxxxx
image
(please note that this is not only happen to alpha high but also other bands)

On the other hand, when I try to drop these enormous values, the data that is formed makes more sense to me
image

Is this something that really should have happened? or there was an abnormality that shouldn't have happened?

I don't know if I post this in the correct way and place, but I hope it is
Thank you

add possibility to re-connect to the device without NPE

Possible ideas:

  • removing assignment of TGDevice object to null in disconnect() method of NeuroSky and RxNeuroSky class
  • re-creation of TGDevice object when it's null in the connect() method of NeuroSky and RxNeuroSky class

Issue with start/stop monitoring

When I am using the method neuroSky.stopMonitoring() with Kotlin, it stays in an 'Idle' state, after of resuming the data transmission is not working with this method neuroSky.startMonitoring(). How could I do to fix it?.

//Start monitoring
 btn_start_monitoring.setOnClickListener {
            neuroSky.startMonitoring()
         
 }
//Stop monitoring "Idle State"
btn_stop_monitoring.setOnClickListener {
            neuroSky.stopMonitoring()      
}

Bluetooth socket instantly closes after connecting with success

Hello I'm currently using the official ThinkGear SDK from NeuroSky with mindwave mobile 2 and and I'm getting bluetooth connection issues. The device connects to the software but then it gets instantly disconnected. I checked on to the logs and saw that bluetooth socket was closed by close() method. I tried to discover why this issue is happening each time I try to connect the device but I'm running out of ideas. Since you worked and seem to know the SDK pretty well do you have any idea what could cause this issue ?

[Question] How this is better than official SDK?

Hi!
Just curious, what was the initial intention to create this 3rd party SDK.

We're doing a meditation training app, and experiencing an issue with official SDK on Bluetooth 5.0 devices. If it won't be fixed, we'll consider switching e.g. to this one.

Reduce message processing overhead in DeviceMessageHandler

Right now, DeviceMessageHandler has if statement in handleMessage(message) method. It adds overhead to data processing because every message from the device goes through that code. We should remove this if statement and add appropriate validation or annotations during object creation.

Issue with the stop() method

After calling stop() method manually, it's not possible to call start() again. In the sample apps, user should not be able to call stop manually. It should be invoked only right before disconnect() method.

Note: it could be a good idea to provide IllegalStateException in the library for this case to prevent such situations from happening. Nevertheless, current state of the device will have to be stored in the memory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.