@unicorns-and-unicorns/capacitor-sensors
v0.0.2
Published
Reading motion sensors.
Downloads
2
Readme
How to use
First build the plugin
npm install
npm run build
In the ionic project install it like this (just change path to yours)
npm install /{path-to-plugin}/capacitor-sensors
And then
ionic capacitor sync android
ionic capacitor sync ios
You can use the Sensors like this
import { Sensors, SensorData } from 'sensors';
useEffect(() => {
Sensors.addListener('magnetometerChange', (res: SensorData) => {
setMangetometerX(res.x);
setMangetometerY(res.y);
setMangetometerZ(res.z);
});
Sensors.addListener('gyroscopeChange', (res: SensorData) => {
setGyroscopeX(res.x);
setGyroscopeY(res.y);
setGyroscopeZ(res.z);
});
Sensors.addListener('accelerometerChange', (res: SensorData) => {
setAccelerometerX(res.x);
setAccelerometerY(res.y);
setAccelerometerZ(res.z);
});
}, []);
sensors
Reading motion sensors.
Install
npm install sensors
npx cap sync
API
addListener('magnetometerChange', ...)
addListener('accelerometerChange', ...)
addListener('gyroscopeChange', ...)
- Interfaces
addListener('magnetometerChange', ...)
addListener(eventName: 'magnetometerChange', listenerFunc: (magnetometerData: SensorData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Listens for magnetometer data change.
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------- |
| eventName
| 'magnetometerChange' |
| listenerFunc
| (magnetometerData: SensorData) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
addListener('accelerometerChange', ...)
addListener(eventName: 'accelerometerChange', listenerFunc: (magnetometerData: SensorData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Listens for accelerometer data change.
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------- |
| eventName
| 'accelerometerChange' |
| listenerFunc
| (magnetometerData: SensorData) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
addListener('gyroscopeChange', ...)
addListener(eventName: 'gyroscopeChange', listenerFunc: (magnetometerData: SensorData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Listens for gyroscope data change.
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------- |
| eventName
| 'gyroscopeChange' |
| listenerFunc
| (magnetometerData: SensorData) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |
SensorData
| Prop | Type |
| ------- | ------------------- |
| x
| number |
| y
| number |
| z
| number |