mindwave_mobile2 1.0.0+1 mindwave_mobile2: ^1.0.0+1 copied to clipboard
A Plugin that provides a Flutter interface for Neurosky Mindwave Mobile 2 headset.
mindwave_mobile2 #
A plugin the provides a Flutter interface for connecting with Neurosky MindWave Mobile 2 Headset. This plugin is built over the android SDK provided from NeuroSky Android Developer Tools 4.2, utlizing both Stream SDK and AlgoSDK.
Example #
You can try an example utlizing this plugin.
cd ./example
flutter run
..
..
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 in order to initialize, you can get this using any bluetooth package such as FlutterBluePlus.
Initalizing 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 functionalties are built as event streamers, every headset state or data are emitted as events.
Note that: the plugin provides all events interfaces for both StreamSDK and AlgoSDK, there is common events between both SDK's that returns 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
});
Contribution #
Feel free to contribute to this plugin to add, update, suggest other features.