From e61d57484931ace32f25bc6a4fcf5ab57082c0f7 Mon Sep 17 00:00:00 2001 From: Simpler1 Date: Mon, 25 Jun 2018 08:35:37 -0400 Subject: [PATCH] feat(plugin): add Sensors plugin (#2268) * feat(sensors): New plugin for sensors * refactor * refactor --- src/@ionic-native/plugins/sensors/index.ts | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/@ionic-native/plugins/sensors/index.ts diff --git a/src/@ionic-native/plugins/sensors/index.ts b/src/@ionic-native/plugins/sensors/index.ts new file mode 100644 index 000000000..23cd185ef --- /dev/null +++ b/src/@ionic-native/plugins/sensors/index.ts @@ -0,0 +1,82 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; + +export const enum TYPE_SENSOR { + PROXIMITY = 'PROXIMITY', + ACCELEROMETER = 'ACCELEROMETER', + GRAVITY = 'GRAVITY', + GYROSCOPE = 'GYROSCOPE', + GYROSCOPE_UNCALIBRATED = 'GYROSCOPE_UNCALIBRATED', + LINEAR_ACCELERATION = 'LINEAR_ACCELERATION', + ROTATION_VECTOR = 'ROTATION_VECTOR', + STEP_COUNTER = 'STEP_COUNTER', + GAME_ROTATION_VECTOR = 'GAME_ROTATION_VECTOR', + GEOMAGNETIC_ROTATION_VECTOR = 'GEOMAGNETIC_ROTATION_VECTOR', + MAGNETIC_FIELD = 'MAGNETIC_FIELD', + MAGNETIC_FIELD_UNCALIBRATED = 'MAGNETIC_FIELD_UNCALIBRATED', + ORIENTATION = 'ORIENTATION', + AMBIENT_TEMPERATURE = 'AMBIENT_TEMPERATURE', + LIGHT = 'LIGHT', + PRESSURE = 'PRESSURE', + RELATIVE_HUMIDITY = 'RELATIVE_HUMIDITY', + TEMPERATURE = 'TEMPERATURE', +} + +/** + * @name Sensors + * @description + * This plugin enables sensors on Android devices + * + * @usage + * ```typescript + * import { Sensors, TYPE_SENSOR } from '@ionic-native/sensors'; + * + * + * constructor(private sensors: Sensors) { } + * + * ... + * + * + * this.sensors.enableSensor(TYPE_SENSOR.LIGHT); + * + * ``` + */ +@Plugin({ + pluginName: 'Sensors', + plugin: 'https://github.com/fabiorogeriosj/cordova-plugin-sensors.git', + pluginRef: 'sensors', + repo: 'https://github.com/fabiorogeriosj/cordova-plugin-sensors.git', + platforms: ['Android'], +}) +@Injectable() +export class Sensors extends IonicNativePlugin { + + /** + * This function enables the sensor + * @param {string} TYPE_SENSOR Specify the sensor to enable + * @return {Promise} Returns a promise that resolves when something happens + */ + @Cordova() + enableSensor(TYPE_SENSOR: string): Promise { + return; + } + + /** + * This function disables the sensor + * @return {Promise} Returns a promise that resolves when something happens + */ + @Cordova() + disableSensor(): Promise { + return; + } + + /** + * This function calls the success callback + * @return {Promise} Returns sensor state + */ + @Cordova() + getState(): Promise { + return; + } + +}