carp_mobile_sensing 0.3.3 copy "carp_mobile_sensing: ^0.3.3" to clipboard
carp_mobile_sensing: ^0.3.3 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_mobile_sensing/core/core.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 the sensing incl. setting up a [Study] with [Task]s and [Measure]s.
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('DF#4dD', 'user@cachet.dk',
        name: 'A default / common study',
        dataEndPoint: FileDataEndPoint()
          ..bufferSize = 500 * 1000
          ..zip = true
          ..encrypt = false)
      ..addTask(Task()..measures = SamplingSchema.common(namespace: NameSpace.CARP).measures.values.toList());

    //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, initialize it, and start it.
    controller = StudyController(study, samplingSchema: SamplingSchema.maximum());
    await controller.initialize();
    controller.start();
    console.log("Sensing started ...");

    print('listening on streams...');

    // 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 ...");
  }
}
19
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.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

app_usage, archive, async, battery, connectivity, device_apps, device_info, flutter, flutter_blue, json_annotation, light, path_provider, pedometer, screen_state, sensors, simple_permissions, stats, system_info, uuid

More

Packages that depend on carp_mobile_sensing