movisens_flutter 0.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 66

movisens_flutter_plugin #

pub package

A plugin for connecting and collecting data from a Movisens sensor. This plugin excelusively works for Android.

Install #

Add movisens_flutter as a dependency in pubspec.yaml. For help on adding as a dependency, view the documentation.

Android permissions #

Add the following to your manifest

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Example Usage #

A Movisens object is instantiated by providing a UserData object, which is, in essence a Map structure containing a list of required fields for the Movisens sensor. These include: Weight, height, age, sensor address and sensor name.

Intialization: #

Movisens _movisens;
StreamSubscription<MovisensDataPoint> _subscription;
LogManager logManager = new LogManager();
List<MovisensDataPoint> movisensEvents = [];
String address = 'unknown', name = 'unknown';
int weight, height, age;

Start Listening #

Data from the sensor is streamed continuously, which is done by calling the listen() method on a Movisens object. An exception will be thrown if the listen method is invoked on a platform other than Android.

void startListening() {
    address = '88:6B:0F:82:1D:33';
    name = 'Sensor 02655';
    weight = 100;
    height = 180;
    age = 25;
    
    UserData userData = new UserData(
        weight, height, Gender.male, age, SensorLocation.chest, address, name);
    
    _movisens = new Movisens(userData);
    
    try {
      _subscription = _movisens.movisensStream.listen(onData);
    } on MovisensException catch (exception) {
      print(exception);
    }
}

Additionally, it can be a good idea to have a separate method for handling incoming data, such as the onData method shown below:

void onData(MovisensDataPoint d) {
    setState(() {
      movisensEvents.add(d);
      logManager.writeLog('$d');
    });
}

Stop Listening #

The subscription can be cancelled again, by invoking the cancel method:

void stopListening() {
    _subscription.cancel(); 
}

image# movisens_plugin

##0.1.6

  • Code clean-up and documentation

##0.1.5

  • Changed path provider from ^0.5.0 to 1.2.0

##0.1.4

  • Fixed Movisens core Android library for foreground service and notification error. Now notification is removed on app kill

##0.1.3

  • Changed Movisens core Android library for foreground service notification on Android>8.1

0.1.2 #

  • MovisensDataPoint removed and replaced with a Map.

0.1.1 #

  • Initial release.

example/lib/main.dart

/*
 * Copyright 2019 Copenhagen Center for Health Technology (CACHET) at the
 * Technical University of Denmark (DTU).
 * Use of this source code is governed by a MIT-style license that can be
 * found in the LICENSE file.
 */
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:movisens_flutter/movisens_flutter.dart';
import 'file_io.dart';

ThemeData darkTheme = ThemeData(
  // Define the default Brightness and Colors
  brightness: Brightness.dark,
  primaryColor: Colors.lightBlue[800],
  accentColor: Colors.cyan[600],

  // Define the default Font Family
  fontFamily: 'Montserrat',

  // Define the default TextTheme. Use this to specify the default
  // text styling for headlines, titles, bodies of text, and more.
  textTheme: TextTheme(
    headline: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
    title: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
    body1: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
  ),
);

void main() => runApp(MovisensApp());

class MovisensApp extends StatefulWidget {
  @override
  _MovisensAppState createState() => _MovisensAppState();
}

class _MovisensAppState extends State<MovisensApp> {
  Movisens _movisens;
  StreamSubscription<Map<String, dynamic>> _subscription;
  LogManager logManager = new LogManager();
  List<Map<String, dynamic>> movisensEvents = [];
  String address = 'unknown', name = 'unknown';
  int weight, height, age;

  @override
  void initState() {
    super.initState();
    startListening();
  }

  void onData(Map<String, dynamic> d) {
    print(" onData_flutter: " + "$d");
    setState(() {
      movisensEvents.add(d);
      logManager.writeLog('$d');
    });
  }

  void stopListening() {
    _subscription.cancel();
  }

  void startListening() {
    //address = '88:6B:0F:82:1D:33';// move4

    address = '88:6B:0F:CD:E7:F2'; // ECG4

    name = 'Sensor 02655';
    weight = 100;
    height = 180;
    age = 25;

    UserData userData = new UserData(weight, height, Gender.male, age, SensorLocation.chest, address, name);

    _movisens = new Movisens(userData);

    try {
      _subscription = _movisens.movisensStream.listen(onData);
    } on MovisensException catch (exception) {
      print(exception);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Movisens Log App',
      theme: darkTheme,
      home: Scaffold(
        body: ListView.builder(
            itemCount: this.movisensEvents.length, itemBuilder: (context, index) => this._buildRow(index)),
      ),
    );
  }

  _buildRow(int index) {
    Map<String, dynamic> d = movisensEvents[index];
    return new Container(
        child: new ListTile(
          leading: Icon(_getIcon(d)),
          title: new Text(
            d.toString(),
            style: TextStyle(fontSize: 12),
          ),
        ),
        decoration: new BoxDecoration(border: new Border(bottom: new BorderSide())));
  }

  IconData _getIcon(Map<String, dynamic> d) {
    if (d.containsKey("TapMarker")) return Icons.touch_app;
    if (d.containsKey("MovementAcceleration")) return Icons.arrow_downward;
    if (d.containsKey("BodyPosition")) return Icons.accessibility;
    if (d.containsKey("Met")) return Icons.cached;
    if (d.containsKey("StepCount")) return Icons.directions_walk;
    if (d.containsKey("BatteryLevel")) return Icons.battery_charging_full;
    if (d.containsKey("ConnectionStatus"))
      return Icons.bluetooth_connected;
    else
      return Icons.device_unknown;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  movisens_flutter: ^0.1.6

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:movisens_flutter/movisens_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:movisens_flutter/movisens_flutter.dart]

Package does not support Flutter platform macos

Because of import path [package:movisens_flutter/movisens_flutter.dart]

Package does not support Flutter platform web

Because of import path [package:movisens_flutter/movisens_flutter.dart]

Package does not support Flutter platform windows

Because of import path [package:movisens_flutter/movisens_flutter.dart]

Package not compatible with SDK dart

because of import path [movisens_flutter]

Health suggestions

Fix lib/movisens_flutter.dart. (-0.50 points)

Analysis of lib/movisens_flutter.dart reported 1 hint:

line 10 col 8: Unused import: 'dart:convert'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path_provider ^1.2.0 1.6.11
Transitive dependencies
collection 1.14.12 1.14.13
file 5.2.1
intl 0.16.1
meta 1.1.8 1.2.0
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
xdg_directories 0.1.0
Dev dependencies
flutter_test