Skip to content

Commit 55084d2

Browse files
committed
2 parents fc662a7 + 05e3980 commit 55084d2

78 files changed

Lines changed: 2624 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.flutter-plugins-dependencies
30+
/build/
31+
/coverage/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "f6ff1529fd6d8af5f706051d9251ac9231c83407"
8+
channel: "stable"
9+
10+
project_type: package
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 1.0.0
2+
3+
Initial release supporting:
4+
5+
* scan for Movensense devices (and stop scanning again)
6+
* connect and disconnect to a device
7+
* get device and state information
8+
* get a stream of the following data from a device:
9+
* heart rate
10+
* ECG
11+
* IMU
12+
* temperature
13+
* state events (movement, battery, connectors, double tap, tap, free fall)

packages/movesense_flutter/LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License.
2+
3+
Copyright 2025 the Technical University of Denmark (DTU).
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ”Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED ”AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
A Flutter plugin for accessing the [Movesense](https://www.movesense.com/) family of ECG devices. This is a developer-friendly wrapper of the [mdsflutter](https://pub.dev/packages/mdsflutter) plugin.
2+
3+
## Features
4+
5+
This plugin supports the following features, which is the most commonly used sub-set of the total [Movensene API](https://www.movesense.com/docs/esw/api_reference/):
6+
7+
* scan for Movensense devices (and stop scanning again)
8+
* connect and disconnect to a device
9+
* get device and state information
10+
* get a stream of the following data from a device:
11+
* heart rate
12+
* ECG
13+
* IMU
14+
* temperature
15+
* state events (movement, battery, connectors, double tap, tap, free fall)
16+
17+
## Getting started
18+
19+
Similar to the [mdsflutter](https://pub.dev/packages/mdsflutter) plugin, the Movesense library needs to be installed in your app.
20+
21+
### iOS
22+
23+
Install the Movesense iOS library using CocoaPods with adding this line to your app's Podfile:
24+
25+
```shell
26+
pod 'Movesense', :git => 'ssh://git@altssh.bitbucket.org:443/movesense/movesense-mobile-lib.git'
27+
```
28+
29+
Then set up your `ios/Podfile` as follows:
30+
31+
```pod
32+
target 'Runner' do
33+
use_modular_headers!
34+
use_frameworks! :linkage => :static
35+
36+
pod 'Movesense', :git => 'https://bitbucket.org/movesense/movesense-mobile-lib.git'
37+
38+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
39+
end
40+
```
41+
42+
This will ensure that the MDS library is linked correctly. If you need to use frameworks that demand dynamic linking, [follow the instructions here](https://bitbucket.org/movesense/movesense-mobile-lib/issues/119/cannot-use-health-and-mdsflutter-depending).
43+
44+
### Android
45+
46+
Download `mdslib-x.x.x-release.aar` from the [movesense-mobile-lib](https://bitbucket.org/movesense/movesense-mobile-lib/src/master/) repository and put it somewhere under 'android' folder of your app. Preferably create a new folder named `android/libs` and put it there.
47+
48+
In the `build.gradle` of your android project, add the following lines (assuming `.aar` file is in `android/libs`):
49+
50+
```graddle
51+
allprojects {
52+
repositories {
53+
...
54+
flatDir{
55+
dirs "$rootDir/libs"
56+
}
57+
}
58+
}
59+
```
60+
61+
## Usage
62+
63+
### Scanning for devices
64+
65+
The singleton `Movesense` can be used for scanning devices:
66+
67+
```dart
68+
/// Listen for discovered devices
69+
Movesense().devices.listen((device) {
70+
debugPrint('Discovered device: ${device.name} [${device.address}]');
71+
});
72+
/// Start scanning.
73+
Movesense().scan();
74+
75+
/// Stop scanning at some later point.
76+
Movesense().stopScan();
77+
```
78+
79+
### Connecting to a device
80+
81+
Scanning return a `MovesenseDevice` which can be used to connect to the device, like:
82+
83+
```dart
84+
if (!device.isConnected) {
85+
device.connect();
86+
}
87+
```
88+
89+
A `MovesenseDevice` can either be obtained using the scan method above, or can be create if the address of the device is know:
90+
91+
```dart
92+
final MovesenseDevice device = MovesenseDevice(address: '0C:8C:DC:1B:23:BF');
93+
94+
device.connect();
95+
```
96+
97+
Connection status is available in the `status` can is emitted in the `statusEvents` stream.
98+
99+
```dart
100+
print(device.status);
101+
102+
device.statusEvents.listen((status) {
103+
print('Device connection status changed: ${status.name}');
104+
});
105+
```
106+
107+
### Accessing device information and battery status
108+
109+
The following device information and status is available as getter methods:
110+
111+
* `getDeviceInfo` - get the full [device info](https://www.movesense.com/docs/esw/api_reference/#info) of this Movesense device.
112+
* `getBatteryStatus` - get the [battery level](https://www.movesense.com/docs/esw/api_reference/#systemstates) ("OK" or "LOW") from the device.
113+
* `getState` - get the [system state](https://www.movesense.com/docs/esw/api_reference/#systemstates) from the device (movement, connectors, doubleTap, tap, freeFall).
114+
115+
For example, getting device info and battery level:
116+
117+
```dart
118+
var info = await device.getDeviceInfo();
119+
print('Product name: ${info?.productName}');
120+
121+
var battery = await device.getBatteryStatus();
122+
print('Battery level: ${battery.name}');
123+
```
124+
125+
### Streaming sensor data
126+
127+
The following sensor data is available as streams:
128+
129+
* `hr` - Heart rate as an `int` at 1 Hz.
130+
* `ecg` - Electrocardiography (ECG) as a sample of reading at 125 Hz.
131+
* `imu` - 9-axis Inertial Movement Unit (IMU) at 13 Hz.
132+
* `temperature` - Surface temperature of the device in Kelvin.
133+
134+
For example, you can listen to the heart rate stream like this:
135+
136+
```dart
137+
// Start listening to the stream of heart rate readings
138+
var hrSubscription = device.hr.listen((hr) {
139+
print('Heart Rate: $hr');
140+
});
141+
142+
// Stop listening.
143+
hrSubscription?.cancel();
144+
```
145+
146+
The example app shows streaming heart rate data, once connected to a device.
147+
148+
### Streaming state change events
149+
150+
You can also listen to a stream of [system state](https://www.movesense.com/docs/esw/api_reference/#systemstates) from the device (movement, connectors, doubleTap, tap, freeFall). For example, listening for 'tap' events like this:
151+
152+
```dart
153+
stateSubscription = device
154+
.getStateEvents(SystemStateComponent.tap)
155+
.listen((state) {
156+
print('State: $state');
157+
});
158+
```
159+
160+
Note, however, that listening to system state events on a Movensense device comes with a lot of limitations. First of all, you can only listen to one type of state events at a time. Second, not all Movesense devices seems to support subscription of all types of state events. For example, it seems like only the 'connectors' and 'tap' states are supported on the Movesense MD and HR2 devices.
161+
162+
## Example App
163+
164+
The included example app is very simple. It shows how to connect to a device with a known `address` and once connected, it listens to the heart rate (`hr`) stream and shows it in the app. Use the floating button to (i) connect, (ii) start streaming heart rate data, and (iii) stop streaming again.
165+
166+
## Features and bugs
167+
168+
Please read about existing issues and file new feature requests and bug reports at the issue tracker.
169+
170+
## License
171+
172+
This software is copyright (c) the [Technical University of Denmark](https://dtu.dk/) (DTU) and is part of the [Copenhagen Research Platform](https://carp.dk/). This software is available 'as-is' under a [MIT license](LICENSE).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "f6ff1529fd6d8af5f706051d9251ac9231c83407"
8+
channel: "stable"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
17+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
18+
- platform: android
19+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
20+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
21+
- platform: ios
22+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
23+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
24+
25+
# User provided section
26+
27+
# List of Local paths (relative to this file) that should be
28+
# ignored by the migrate tool.
29+
#
30+
# Files that are not part of the templates will be ignored by default.
31+
unmanaged_files:
32+
- 'lib/main.dart'
33+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# movesense_flutter_example
2+
3+
A new Flutter project.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml

0 commit comments

Comments
 (0)