@unicorns-and-unicorns/capacitor-sensors
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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(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

Readme

Keywords

Package Sidebar

Install

npm i @unicorns-and-unicorns/capacitor-sensors

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

25.5 kB

Total Files

25

Last publish

Collaborators

  • githubctss
  • uu-development