Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/crossgeeks/devicesensorsplugin

Device Sensors Notification Plugin for Xamarin, Tizen and Windows
https://github.com/crossgeeks/devicesensorsplugin

accelerometer android barometer device gyroscope ios magnetometer pedometer plugin sensors tizen uwp xamarin

Last synced: 2 months ago
JSON representation

Device Sensors Notification Plugin for Xamarin, Tizen and Windows

Awesome Lists containing this project

README

        

## DeviceSensors Plugin for Xamarin iOS, Android, UWP and Tizen
Simple cross platform plugin to access device sensors.

## Features

- Access to accelerometer
- Access to gyroscope
- Access to magnetometer
- Access to barometer
- Access to pedometer

### Setup
* Available on NuGet: http://www.nuget.org/packages/Plugin.DeviceSensors [![NuGet](https://img.shields.io/nuget/v/Plugin.DeviceSensors.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.DeviceSensors/)
* Install into your PCL project and Client projects.

**Platform Support**

|Platform|Version|
| ------------------- | :------------------: |
|Xamarin.iOS|iOS 7+|
|Xamarin.Android|API 13+|
|Windows 10 UWP|10+|
|Tizen|4.0+|

### API Usage

Call **CrossDeviceSensors.Current** from any project or PCL to gain access to APIs.

#### iOS Setup

Add to your Info.plist **NSMotionUsageDescription** key:

```xml
NSMotionUsageDescription
This app needs to be able to access your motion use
```

#### Getting Started

Device Sensor interface

```cs
public interface IDeviceSensor
{
///
/// Check if sensor supported
///
bool IsSupported { get; }
///
/// Check if sensor is active
///
bool IsActive { get; }
///
/// Get latest sensor reading
///
T LastReading {get;}
///
/// Sets/get sensor report interval
///
int ReadingInterval { get; set; }
///
/// Starts sensor reading
///
void StartReading(int readingInterval = -1);
///
/// Stops sensor reading
///
void StopReading();

///
/// Sensor reading changes event
///
event EventHandler> OnReadingChanged;
}
```

Available sensors

```cs
public interface IDeviceSensors
{
IDeviceSensor Accelerometer {get; }
IDeviceSensor Gyroscope { get; }
IDeviceSensor Magnetometer { get; }
IDeviceSensor Barometer { get; }
IDeviceSensor Pedometer { get; }
}
```
Usage sample:

Accelerometer
```csharp
if(CrossDeviceSensors.Current.Accelerometer.IsSupported)
{
CrossDeviceSensors.Current.Accelerometer.OnReadingChanged += (s,a)=>{

};
CrossDeviceSensors.Current.Accelerometer.StartReading();
}

```

Gyroscope
```csharp
if(CrossDeviceSensors.Current.Gyroscope.IsSupported)
{
CrossDeviceSensors.Current.Gyroscope.OnReadingChanged += (s,a)=>{

};
CrossDeviceSensors.Current.Gyroscope.StartReading();
}

```

Magnetometer
```csharp
if(CrossDeviceSensors.Current.Magnetometer.IsSupported)
{
CrossDeviceSensors.Current.Magnetometer.OnReadingChanged += (s,a)=>{

};
CrossDeviceSensors.Current.Magnetometer.StartReading();
}

```

#### Contributors

* [Rendy Del Rosario](https://github.com/rdelrosario)
* [Jong Heon Choi](https://github.com/JongHeonChoi)
* [Dimitri Jevic](https://github.com/dimitrijevic)