Skip to content

A Plugin that provides a Flutter interface for Neurosky Mindwave Mobile 2 headset.

License

Notifications You must be signed in to change notification settings

PrinceEGY/mindwave_mobile2

Repository files navigation

mindwave_mobile2

Pub Version

A plugin that provides a Flutter interface for connecting with Neurosky MindWave Mobile 2 Headset. This plugin is built over the Android SDK provided by NeuroSky Android Developer Tools 4.2, utilizing both Stream SDK and AlgoSDK.

Note that: The plugin is currently only supports android, feel free to contribute to add IOS support or any other functionalties.

Note that: The plugin is not offical or sponsored by Neurosky.

Example

You can try an example utilizing this plugin.

cd ./example
flutter run

scan screen..disconnected screen

connected raw screen..connected algo screen

Usage

To use this plugin, add mindwave_mobile2 as a dependency in your pubspec.yaml file

dependencies:
  ......
  mindwave_mobile_2: '^1.0.0'

The plugin requires the MindWave mobile 2 device ID to initialize, you can get this using any Bluetooth package such as FlutterBluePlus.

Initializing MindWave

import 'package:flutter_blue_plus/flutter_blue_plus.dart';

await FlutterBluePlus.startScan(timeout: const Duration(seconds: 15));

FlutterBluePlus.scanResults.listen((List<ScanResult> results) {
  results.forEach((result) {
    final deviceID = result.device.platformName;
    if (deviceID == "MindWave Mobile") {
      MindwaveMobile2.instance.init(deviceID);
    }
  });
});

Connect & Disconnect

Must be executed after init

MindwaveMobile2.instance.connect();

MindwaveMobile2.instance.disconnect();

Events Streamers

Most of the plugin functions are built as event streamers, every headset state or data is emitted as events.

Note that: the plugin provides all events interfaces for both StreamSDK and AlgoSDK, there are common events between both SDKs that return exactly the same results, you shall use any of them.

- Headset State

Emits the current state of the Headset.

_headsetStateSubscription = MindwaveMobile2.instance.onStateChange().listen((state) {
  _headsetState = state;
  if (state == HeadsetState.DISCONNECTED) {
    MindwaveMobile2.instance.disconnect();
  }
  if (mounted) {
    setState(() {});
  }
});

- StreamSDK events

var signalQualitySubscription = MindwaveMobile2.instance.onSignalQualityUpdate()
  .listen((int signalQuality) {
      // Handle signalQuality
  });

var attentionSubscription = MindwaveMobile2.instance.onAttentionUpdate()
  .listen((int attention) {
      // Handle attention
  });

var meditationSubscription = MindwaveMobile2.instance.onMeditationUpdate()
  .listen((int meditation) {
      // Handle meditation
  });

var bandPowerSubscription = MindwaveMobile2.instance.onBandPowerUpdate()
  .listen((BandPower bandPower) {
      // Handle bandPower
  });

var rawSubscription = MindwaveMobile2.instance.onRawUpdate()
  .listen((List<int> rawData) {
      // Handle rawData
  });

- AlgoSDK events

var algoStateReasonSubscription = MindwaveMobile2.instance.onAlgoStateReasonChange()
  .listen((Map stateReason) {
      // Handle stateReason
      // The returned map is of the form
      // {"State": AlgoState, "Reason": AlgoReason}
  });

var algoAttentionSubscription = MindwaveMobile2.instance.onAlgoAttentionUpdate()
  .listen((int attention) {
      // Handle attention
  });

var algoMeditationSubscription = MindwaveMobile2.instance.onAlgoMeditationUpdate()
  .listen((int meditation) {
      // Handle meditation
  });

var algoBandPowerSubscription = MindwaveMobile2.instance.onAlgoBandPowerUpdate()
  .listen((AlgoBandPower algoBandPower) {
      // Handle algoBandPower
  });

var algoSignalQualitySubscription = MindwaveMobile2.instance.onAlgoSignalQualityUpdate()
  .listen((int signalQuality) {
      // Handle signalQuality
  });

var algoBlinkSubscription = MindwaveMobile2.instance.onBlink()
  .listen((int blinkStrength) {
      // Handle blinkStrength
  });

Credits

This project includes parts of code that implements and wraps native Stream and Algo SDKs from NeuroSyncCore created by Mohamed Medhat. We are grateful for their work and the impact it has had on this plugin.

Contribution

Feel free to contribute to this plugin to add, update, and suggest other features.

About

A Plugin that provides a Flutter interface for Neurosky Mindwave Mobile 2 headset.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published