flutter_mindwave_mobile_2 0.1.0

pub package

FlutterMindWaveMobile2

Introduction #

FlutterMindWaveMobile2 is a plugin to connect and receive data from the Neurosky MindWave Mobile 2 using Flutter, a new mobile SDK to help developers build modern apps for iOS and Android.

Cross-Platform #

FlutterMindWaveMobile2 aims to offer the most from both the Android Developer Tools 4.2 and iOS Developer Tools 4.8 from Neurosky. Data is fed from the COMM SDK into the EEG Algorithm SDK (see note below).

Note: iOS License Key Requirement for EEG Algorithm SDK #

Android by default uses the EEG Algorithm, but iOS requires a license key to use the EEG Algorithm SDK. However, the COMMS SDK (used to feed the EEG Algorithm SDK) is still available and providing values on all channels except Band Power (BP) (see supported algorithms below).

Please contact Neurosky for a client specific license key.

Note: Will only work on actual devices #

This plugin will NOT connect in Android Emulator and will NOT build on iOS simulator.

Supported Algorithms #

All algorithm data have a fixed output interval of 1 second.

AndroidiOS (with License)iOS (without License)Description
Attention (Att)✔️✔️✔️Attention index ranges from 0 to 100. The higher the index, the higher the attention level.
Meditation (Med)✔️✔️✔️Meditation index ranges from 0 to 100. The higher the index, the higher the meditation level.
Band Power (BP)✔️✔️EEG bandpowers (in dB) index for: delta, theta, alpha, beta, and gamma.
Eye Blink Detection (Blink)✔️✔️✔️Eye blink strength (no baseline data collection will be needed).
Signal Quality✔️✔️✔️Signal quality value of the device ranges from 0 to 200. The lower the value, the better the signal.

Usage #

Add flutter_mindwave_mobile_2 as a dependency in your pubspec.yaml file:

dependencies:
  flutter_mindwave_mobile_2: '^0.1.0'

Then import the plugin into your dart file.

import 'package:flutter_mindwave_mobile_2/flutter_mindwave_mobile_2.dart';

Get Bluetooth device ID #

This plugin requires the MindWave Mobile 2 Bluetooth device ID. An easy way to accomplish this is with using FlutterBlue. For example:

import 'package:flutter_blue/flutter_blue.dart';

FlutterBlue flutterBlue = FlutterBlue.instance;

var scanSubscription = flutterBlue
    .scan()
    .listen((ScanResult scanResult) {
        var device = scanResult.device;
        var name = device.name;
        if (name == 'MindWave Mobile') {
            var deviceId = device.id.toString();
        }
    });

Create a new FlutterMindWaveMobile2 instance #

FlutterMindWaveMobile2 flutterMindWaveMobile2 = FlutterMindWaveMobile2();

Connect #

Returns MWMConnectionState

var connectionSubscription = flutterMindWaveMobile2
    .connect(deviceId, licenseKey) // licenseKey is optional for iOS EEG Algorithm
    .listen((MWMConnectionState connectionState) {
        // Handle state
    });

Disconnect #

connectionSubscription.cancel();
flutterMindWaveMobile2.disconnect();

Data streams #

Algorithm State and Reason #

Returns AlgoStateAndReason

var algoStateAndReasonSubscription = flutterMindWaveMobile2
    .onAlgoStateAndReason()
    .listen((AlgoStateAndReason algoStateAndReason) {
        // Handle algo state and reason
    });

Attention #

Returns int

var attentionSubscription = flutterMindWaveMobile2
    .onAttention()
    .listen((int attention) {
        // Handle attention
    });

Meditation #

Returns int

var meditationSubscription = flutterMindWaveMobile2
    .onMeditation()
    .listen((int meditation) {
        // Handle meditation
    });

Band Power #

Returns BandPower

var bandPowerSubscription = flutterMindWaveMobile2
    .onBandPower()
    .listen((BandPower bandPower) {
        // Handle band power
    });

Returns int

var eyeBlinkDetectionSubscription = flutterMindWaveMobile2
    .onEyeBlink()
    .listen((int eyeBlinkStrength) {
        // Handle eye blink strength
    });

Signal Quality #

Returns int

var signalQualitySubscription = flutterMindWaveMobile2
    .onSignalQuality()
    .listen((int signalQuality) {
        // Handle signal quality
    });

Classes #

AlgoStateAndReason #

PropertyType
stateAlgoState
reasonAlgoReason

BandPower #

PropertyType
deltadouble
thetadouble
alphadouble
betadouble
gammadouble

Enums #

MWMConnectionState #

Values
disconnected
scanning (not used in package, but used in example with FlutterBlue)
connecting
connected

AlgoState #

Values
inited
analysingBulkData
collectingBaseline
pause
running
stop
uninited

AlgoReason #

Values
baselineExpired
byUser
cbChanged (Android only collecting baseline changed)
configChanged
noBaseline
signalQuality
userProfileChanged
unknown

Inspiration #

This plugin is inspired by react-native-mindwave-mobile, but adds on the EGG Algorithm SDK.

Affiliation #

This plugin is not affiliated or sponsored by Neurosky in any way.

0.1.0 #

Initial release.

example/README.md

FlutterMindWaveMobile2

Setup Hardwave #

  1. Connect device to computer (will NOT connect to MindWave Mobile 2 on Android emulator and will NOT build on iOS simulator)
  2. Turn on Bluetooth
  3. Turn on MindWave Mobile 2
  4. Android will be prompted to enter authentication key when connecting. Enter 0000

Setup Example #

1. Get a local copy of the repo #

// For ssh
git clone git@github.com:mattbajorek/flutter_mindwave_mobile_2.git

// For https
git clone https://github.com/mattbajorek/flutter_mindwave_mobile_2.git

2. Go into example directory #

cd flutter_mindwave_mobile_2/example/

3. Run example #

flutter run

Running example #

  1. Press connect to automatically connect to device.
  2. When connected, values will initially show N/A.
  3. Wait a few seconds and if there is a good connection, data will start flowing and updating on the screen.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_mindwave_mobile_2: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_mindwave_mobile_2/flutter_mindwave_mobile_2.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

49 out of 49 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/mattbajorek/flutter_mindwave_mobile_2 was unreachable.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (flutter_blue).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
flutter_blue ^0.4.2 0.4.2 0.6.0+3
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
fixnum 0.10.9
meta 1.1.6 1.1.7
protobuf 0.10.8 0.13.15
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8