Skip to content

Commit

Permalink
Merge pull request #16 from GeoTecINIT/sensorDelay-bug
Browse files Browse the repository at this point in the history
[BUGFIX]: Wrong sensor delay for LOCATION sensor type.
  • Loading branch information
matey97 authored Sep 1, 2022
2 parents 2d7083e + 4915c62 commit 0d3bf0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class CollectorManagerImpl implements CollectorManager {
if (!hasCapability(node, sensor) || !this.isEnabled(sensor))
return;

const message = config ? configAsString(config) : configAsString(defaultCollectionConfiguration(sensor));
const message = config ? configAsString(sensor, config) : configAsString(sensor, defaultCollectionConfiguration(sensor));
await this.messagingClient(sensor).sendStartMessage(node, message);
}

Expand Down
16 changes: 11 additions & 5 deletions src/internal/collection/collection-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@ export function defaultCollectionConfiguration(sensorType: SensorType): Collecti
sensorInterval: NativeSensorDelay.NORMAL,
batchSize: 50
};
case SensorType.LOCATION:
case SensorType.HEART_RATE:
return {
sensorInterval: NativeSensorDelay.NORMAL,
batchSize: 5
};
case SensorType.LOCATION:
return {
sensorInterval: 1000,
batchSize: 5
};
}
}

export function configAsString(collectionConfiguration: CollectionConfiguration) {
const intervalValue = sensorIntervalToNativeValue(collectionConfiguration.sensorInterval);
export function configAsString(sensor: SensorType, collectionConfiguration: CollectionConfiguration) {
const intervalValue = sensorIntervalToNativeValue(sensor, collectionConfiguration.sensorInterval);
return `${intervalValue}#${collectionConfiguration.batchSize}`;
}

function sensorIntervalToNativeValue(sensorInterval: SensorInterval) {
function sensorIntervalToNativeValue(sensor: SensorType, sensorInterval: SensorInterval) {
switch (sensorInterval) {
case NativeSensorDelay.UI:
case NativeSensorDelay.NORMAL:
case NativeSensorDelay.GAME:
case NativeSensorDelay.FASTEST:
return sensorInterval;
default:
return sensorInterval * 1000; // Native API expects interval in microseconds
return sensor === SensorType.LOCATION
? sensorInterval
: sensorInterval * 1000; // Native sensors API expects interval in microseconds
}
}
4 changes: 2 additions & 2 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-wearos-sensors",
"version": "1.2.0",
"version": "1.2.1",
"description": "Plugin to develop smartphone apps that receive sensors' data from a paired WearOS smartwatch.",
"main": "wearos-sensors",
"typings": "index.d.ts",
Expand Down

0 comments on commit 0d3bf0c

Please sign in to comment.