-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: allow custom value for sensors' reporting interval
- Loading branch information
Showing
4 changed files
with
57 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
import {SensorType} from "../sensors/sensor-type"; | ||
import { SensorType } from "../sensors/sensor-type"; | ||
|
||
export type SensorInterval = NativeSensorDelay | number; | ||
|
||
export interface CollectionConfiguration { | ||
sensorDelay: SensorDelay; | ||
sensorInterval: SensorInterval; | ||
batchSize: number; | ||
} | ||
|
||
export enum SensorDelay { | ||
export enum NativeSensorDelay { | ||
UI = android.hardware.SensorManager.SENSOR_DELAY_UI, | ||
NORMAL = android.hardware.SensorManager.SENSOR_DELAY_NORMAL, | ||
GAME = android.hardware.SensorManager.SENSOR_DELAY_GAME, | ||
FASTEST = android.hardware.SensorManager.SENSOR_DELAY_FASTEST, | ||
} | ||
|
||
export function configAsString(collectionConfiguration: CollectionConfiguration) { | ||
return `${collectionConfiguration.sensorDelay}#${collectionConfiguration.batchSize}`; | ||
} | ||
|
||
export function defaultCollectionConfiguration(sensorType: SensorType): CollectionConfiguration { | ||
switch (sensorType) { | ||
case SensorType.ACCELEROMETER: | ||
case SensorType.GYROSCOPE: | ||
case SensorType.MAGNETOMETER: | ||
return { | ||
sensorDelay: SensorDelay.NORMAL, | ||
sensorInterval: NativeSensorDelay.NORMAL, | ||
batchSize: 50 | ||
}; | ||
case SensorType.LOCATION: | ||
case SensorType.HEART_RATE: | ||
return { | ||
sensorDelay: SensorDelay.NORMAL, | ||
sensorInterval: NativeSensorDelay.NORMAL, | ||
batchSize: 5 | ||
}; | ||
} | ||
} | ||
|
||
export function configAsString(collectionConfiguration: CollectionConfiguration) { | ||
const intervalValue = sensorIntervalToNativeValue(collectionConfiguration.sensorInterval); | ||
return `${intervalValue}#${collectionConfiguration.batchSize}`; | ||
} | ||
|
||
function sensorIntervalToNativeValue(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 | ||
} | ||
} |