carp_mobile_sensing 0.8.6 copy "carp_mobile_sensing: ^0.8.6" to clipboard
carp_mobile_sensing: ^0.8.6 copied to clipboard

outdated

Mobile Sensing Framework for Flutter. A software framework for collecting sensor data from the phone and attached wearable devices via probes. Can be extended.

example/lib/main.dart

/*
 * Copyright 2018 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 'package:flutter/material.dart';
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
//import 'package:carp_apps_package/apps.dart';

void main() => runApp(new CARPMobileSensingApp());

class CARPMobileSensingApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'CARP Mobile Sensing Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new ConsolePage(title: 'CARP Mobile Sensing Demo'),
    );
  }
}

class ConsolePage extends StatefulWidget {
  ConsolePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  Console createState() => new Console();
}

class Console extends State<ConsolePage> {
  String _log = "";
  Sensing sensing;

  void log(String msg) {
    setState(() {
      _log += "$msg\n";
    });
  }

  void clearLog() {
    setState(() {
      _log += "";
    });
  }

  void restart() {
    log("-------------------------------------\nSensing restarted...");
    sensing.start();
  }

  @override
  void initState() {
    super.initState();
    sensing = new Sensing(this);
    sensing.start();
  }

  @override
  void dispose() {
    sensing.stop();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new SingleChildScrollView(
        child: StreamBuilder(
          stream: sensing.controller.events,
          builder: (context, AsyncSnapshot<Datum> snapshot) {
            if (snapshot.hasData) {
              _log += "${snapshot.data.toString()}\n";
              return Text(_log);
            } else if (snapshot.hasError) {
              return Text(snapshot.error.toString());
            }
            return Center(child: CircularProgressIndicator());
          },
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: restart,
        tooltip: 'Restart study & probes',
        child: new Icon(Icons.cached),
      ),
    );
  }
}

/// This class implements sensing incl. setting up a [Study] with [Task]s and [Measure]s.
///
/// This example is useful for creating a Business Logical Object (BLOC) in a Flutter app.
/// See e.g. the CARP Mobile Sensing App.
class Sensing {
  Study study;
  Console console;
  StudyController controller;

  Sensing(this.console) {
    //DataManagerRegistry.register(DataEndPointType.PRINT, new ConsoleDataManager());
    //DataManagerRegistry.register(DataEndPointType.FILE, new FileDataManager());
  }

  /// (Re)start sensing.
  void start() async {
    console.log("Setting up study...");

    // create the study
    study = Study("2", 'user@cachet.dk',
        name: 'A default / common study',
        dataEndPoint: FileDataEndPoint()
          ..bufferSize = 500 * 1000
          ..zip = true
          ..encrypt = false)
      ..addTriggerTask(
          ImmediateTrigger(),
          AutomaticTask()
            ..measures = SamplingSchema.debug().getMeasureList(
              namespace: NameSpace.CARP,
              types: [
                SensorSamplingPackage.LIGHT,
//                AppsSamplingPackage.APP_USAGE,
                DeviceSamplingPackage.MEMORY,
              ],
            ))
        ;

//    SamplingPackageRegistry.register(AppsSamplingPackage());

    console.log("Setting up '${study.name}'...");

    // print the study to the console
    console.log(study.toString());

    // Create a Study Controller that can manage this study and initialize it.
    controller = StudyController(study);
    await controller.initialize();

    // Resume (i.e. start) data sampling.
    controller.resume();
    console.log("Sensing started ...");

    // listening on all probe events from the study
    controller.events.forEach(print);

    // listening on a specific probe
    //ProbeRegistry.probes[DataType.LOCATION].events.forEach(print);
  }

  /// Stop sensing.
  void stop() async {
    controller.stop();
    study = null;
    console.log("Sensing stopped ...");
  }
}
21
likes
0
pub points
76%
popularity

Publisher

verified publishercachet.dk

Mobile Sensing Framework for Flutter. A software framework for collecting sensor data from the phone and attached wearable devices via probes. Can be extended.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

archive, async, battery, device_apps, device_info, flutter, json_annotation, light, meta, package_info, path_provider, pedometer, permission_handler, permission_handler_platform_interface, screen_state, sensors, shared_preferences, stats, system_info, uuid

More

Packages that depend on carp_mobile_sensing