Skip to content

Commit

Permalink
fix: use the correct sensorDelay for the SensorType.LOCATION
Browse files Browse the repository at this point in the history
  • Loading branch information
matey97 committed Sep 1, 2022
1 parent 2d7083e commit 363bda1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 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
}
}

0 comments on commit 363bda1

Please sign in to comment.