carp_esense_package 0.20.3 copy "carp_esense_package: ^0.20.3" to clipboard
carp_esense_package: ^0.20.3 copied to clipboard

outdated

The CARP eSense sampling package. Samples sensor and device events from the eSense ear plug device.

example/lib/example.dart

import 'package:carp_core/carp_core.dart';
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_esense_package/esense.dart';

/// This is a very simple example of how this sampling package is used with
/// CARP Mobile Sensing (CAMS).
/// NOTE, however, that the code below will not run.
/// See the documentation on how to use CAMS:
/// https://github.com/cph-cachet/carp.sensing-flutter/wiki
void main() async {
  // register this sampling package before using its measures
  SamplingPackageRegistry().register(ESenseSamplingPackage());

  // Create a study protocol using a local file to store data
  CAMSStudyProtocol protocol = CAMSStudyProtocol()
    ..name = 'Track patient movement'
    ..owner = ProtocolOwner(
      id: 'AB',
      name: 'Alex Boyon',
      email: 'alex@uni.dk',
    )
    ..dataEndPoint = FileDataEndPoint(
      bufferSize: 500 * 1000,
      zip: true,
      encrypt: false,
    );

  // define which devices are used for data collection - both phone and eSense
  Smartphone phone = Smartphone(roleName: 'The main phone');
  DeviceDescriptor eSense = ESenseDevice(roleName: 'The left eSense earplug');

  protocol
    ..addMasterDevice(phone)
    ..addConnectedDevice(eSense);

  // Add an automatic task that immediately starts collecting eSense button and sensor events.
  protocol.addTriggeredTask(
      ImmediateTrigger(),
      AutomaticTask()
        ..addMeasures([
          ESenseMeasure(
              type: ESenseSamplingPackage.ESENSE_BUTTON,
              measureDescription: {
                'en': MeasureDescription(
                  name: 'eSense - Button',
                  description: "Collects button event from the eSense device",
                )
              },
              deviceName: 'eSense-0332'),
          ESenseMeasure(
              type: ESenseSamplingPackage.ESENSE_SENSOR,
              measureDescription: {
                'en': MeasureDescription(
                  name: 'eSense - Sensor',
                  description:
                      "Collects movement data from the eSense inertial measurement unit (IMU) sensor",
                )
              },
              deviceName: 'eSense-0332',
              samplingRate: 5),
        ]),
      phone);

  // deploy this protocol using the on-phone deployment service
  StudyDeploymentStatus status =
      await CAMSDeploymentService().createStudyDeployment(protocol);

  // at this time we can register an eSensee device which are connected to this phone (master device)
  CAMSDeploymentService().registerDevice(
    status.studyDeploymentId,
    'The left eSense earbud',
    DeviceRegistration('some device id'),
  );

  // now ready to get the device deployment configuration for this phone
  CAMSMasterDeviceDeployment deployment = await CAMSDeploymentService()
      .getDeviceDeployment(status.studyDeploymentId);

  // Create a study deployment controller that can manage this deployment
  StudyDeploymentController controller = StudyDeploymentController(deployment);

  // initialize the controller and resume sampling
  await controller.initialize();
  controller.resume();

  // listening and print all data events from the study
  controller.data.forEach(print);
}
1
likes
0
pub points
66%
popularity

Publisher

verified publishercachet.dk

The CARP eSense sampling package. Samples sensor and device events from the eSense ear plug device.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

carp_core, carp_mobile_sensing, esense_flutter, flutter, json_annotation, permission_handler

More

Packages that depend on carp_esense_package