Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions open_wearable/docs/pages/sensor-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- Does:
- Builds sensor cards for all active sensors across wearables.
- Supports no-graph mode and hide-empty-graphs mode.
- Can show expected and actual sampling rates on sensor charts. Labels are off by default; the preference is saved under Settings → General settings → Live data → Show sampling rates.
- Uses merged provider listenables for efficient live refresh.
- Provides:
- Live chart/value surface for all connected sensors.
Expand Down
93 changes: 93 additions & 0 deletions open_wearable/lib/assets/fonts/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2015 The Roboto Mono Project Authors (https://github.com/googlefonts/robotomono)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added open_wearable/lib/assets/fonts/RobotoMono.ttf
Binary file not shown.
23 changes: 23 additions & 0 deletions open_wearable/lib/models/app_shutdown_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AppShutdownSettings {
'app_disable_live_data_graphs';
static const String _hideLiveDataGraphsWithoutDataKey =
'app_hide_live_data_graphs_without_data';
static const String _showSamplingRatesKey = 'app_show_sampling_rates';
static const String _keepAppInForegroundKey = 'app_keep_in_foreground';

static final ValueNotifier<bool> _shutOffAllSensorsOnAppCloseNotifier =
Expand All @@ -27,6 +28,8 @@ class AppShutdownSettings {
ValueNotifier<bool>(false);
static final ValueNotifier<bool> _hideLiveDataGraphsWithoutDataNotifier =
ValueNotifier<bool>(false);
static final ValueNotifier<bool> _showSamplingRatesNotifier =
ValueNotifier<bool>(false);
static final ValueNotifier<bool> _keepAppInForegroundNotifier =
ValueNotifier<bool>(false);

Expand All @@ -36,6 +39,8 @@ class AppShutdownSettings {
_disableLiveDataGraphsNotifier;
static ValueListenable<bool> get hideLiveDataGraphsWithoutDataListenable =>
_hideLiveDataGraphsWithoutDataNotifier;
static ValueListenable<bool> get showSamplingRatesListenable =>
_showSamplingRatesNotifier;
static ValueListenable<bool> get keepAppInForegroundListenable =>
_keepAppInForegroundNotifier;

Expand All @@ -44,13 +49,15 @@ class AppShutdownSettings {
static bool get disableLiveDataGraphs => _disableLiveDataGraphsNotifier.value;
static bool get hideLiveDataGraphsWithoutData =>
_hideLiveDataGraphsWithoutDataNotifier.value;
static bool get showSamplingRates => _showSamplingRatesNotifier.value;
static bool get keepAppInForeground => _keepAppInForegroundNotifier.value;

static Future<void> initialize() async {
await Future.wait([
loadShutOffAllSensorsOnAppClose(),
loadDisableLiveDataGraphs(),
loadHideLiveDataGraphsWithoutData(),
loadShowSamplingRates(),
loadKeepAppInForeground(),
]);
}
Expand Down Expand Up @@ -97,6 +104,22 @@ class AppShutdownSettings {
return enabled;
}

/// Loads whether live graphs show their expected and actual sampling rates.
static Future<bool> loadShowSamplingRates() async {
final prefs = await SharedPreferences.getInstance();
final enabled = prefs.getBool(_showSamplingRatesKey) ?? false;
_showSamplingRatesNotifier.value = enabled;
return enabled;
}

/// Persists label visibility and updates all live graphs immediately.
static Future<bool> saveShowSamplingRates(bool enabled) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_showSamplingRatesKey, enabled);
_showSamplingRatesNotifier.value = enabled;
return enabled;
}

static Future<bool> loadKeepAppInForeground() async {
final prefs = await SharedPreferences.getInstance();
final enabled = prefs.getBool(_keepAppInForegroundKey) ?? false;
Expand Down
74 changes: 71 additions & 3 deletions open_wearable/lib/widgets/sensors/values/sensor_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:open_earable_flutter/open_earable_flutter.dart' hide logger;
import 'package:open_wearable/models/app_shutdown_settings.dart';
import 'package:open_wearable/view_models/sensor_configuration_provider.dart';
import 'package:open_wearable/view_models/sensor_data_provider.dart';
import 'package:open_wearable/view_models/wearables_provider.dart';
Expand Down Expand Up @@ -301,9 +302,40 @@ class _SensorChartState extends State<SensorChart> {
child: LiveDataGraphSurface(
settings: widget.settings,
onDisabledTap: widget.onDisabledTap,
child: LineChart(
chartData,
duration: const Duration(milliseconds: 0),
child: Stack(
fit: StackFit.expand,
children: [
LineChart(
chartData,
duration: const Duration(milliseconds: 0),
),
Positioned(
top: 4,
right: 4,
child: ValueListenableBuilder<bool>(
valueListenable:
AppShutdownSettings.showSamplingRatesListenable,
builder: (context, showSamplingRates, _) {
if (!showSamplingRates) return const SizedBox.shrink();
return IgnorePointer(
child: Text(
_samplingRateLabel(
sensor,
sensorValues,
referenceTimestamp,
sensorConfigurationProvider,
),
style: const TextStyle(
color: Colors.grey,
fontSize: 10,
fontFamily: 'RobotoMono',
),
),
);
},
),
),
],
),
),
),
Expand Down Expand Up @@ -587,6 +619,42 @@ class _SensorChartState extends State<SensorChart> {
}
}

String _samplingRateLabel(
Sensor sensor,
Queue<SensorValue> values,
int referenceTimestamp,
SensorConfigurationProvider? configurationProvider,
) {
double? expectedHz;
for (final configuration in sensor.relatedConfigurations) {
final activeValue = _activeFrequencyValueForConfiguration(
configuration,
configurationProvider,
);
if (activeValue == null) continue;
final rate = _isStreamingFrequencyValue(configuration, activeValue)
? activeValue.frequencyHz
: 0.0;
expectedHz = max(expectedHz ?? 0, rate);
}

// Use the existing rolling buffer, including silence since the last sample.
final elapsed = values.isEmpty
? 0.0
: (referenceTimestamp - values.first.timestamp) *
pow(10, sensor.timestampExponent);
final actualHz =
values.length < 2 || elapsed <= 0 ? 0.0 : (values.length - 1) / elapsed;
// Round up below the target, but only show an excess of at least 1 Hz.
final actual = expectedHz != null && actualHz < expectedHz + 1
? min(actualHz.ceil(), expectedHz.round())
: actualHz.round();
final expected = expectedHz?.round().toString() ?? '—';
// Reserve only as many digits as the expected rate needs.
return 'Expected $expected Hz · '
'Actual ${actual.toString().padLeft(expected.length)} Hz';
}

_FilterFrequencyBounds _frequencyBoundsForSensor(
Sensor sensor, {
SensorConfigurationProvider? sensorConfigurationProvider,
Expand Down
39 changes: 39 additions & 0 deletions open_wearable/lib/widgets/settings/general_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
}
}

Future<void> _setShowSamplingRates(bool enabled) async {
if (_isSaving) {
return;
}

setState(() {
_isSaving = true;
});

try {
await AppShutdownSettings.saveShowSamplingRates(enabled);
} finally {
if (mounted) {
setState(() {
_isSaving = false;
});
}
}
}

Future<void> _setAutoConnectEnabled(bool enabled) async {
if (_isSaving) {
return;
Expand Down Expand Up @@ -263,6 +283,25 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
'Hides live data graphs in Sensors › Live Data until samples arrive',
),
),
ValueListenableBuilder<bool>(
valueListenable: AppShutdownSettings
.showSamplingRatesListenable,
builder: (context, showSamplingRates, _) =>
SwitchListTile.adaptive(
value: showSamplingRates,
onChanged: _isSaving
? null
: _setShowSamplingRates,
secondary: const Icon(
Icons.speed_rounded,
size: 18,
),
title: const Text('Show sampling rates'),
subtitle: const Text(
'Show expected and actual sampling rates on live graphs',
),
),
),
],
),
],
Expand Down
6 changes: 6 additions & 0 deletions open_wearable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ flutter:
# the material Icons class.
uses-material-design: true

fonts:
- family: RobotoMono
fonts:
- asset: lib/assets/fonts/RobotoMono.ttf

# To add assets to your application, add an assets section, like this:
assets:
- lib/apps/posture_tracker/assets/
- lib/apps/heart_tracker/assets/
- lib/apps/seal_check/assets/
- lib/assets/devices/phone-app.png
- lib/assets/fonts/OFL.txt
- android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

# An image asset can refer to one or more resolution-specific "variants", seeq
Expand Down
Loading