Giter Site home page Giter Site logo

ponchonov / rxmotionkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rsobolewski/rxmotionkit

0.0 1.0 0.0 4.14 MB

RxMotionKit - reactive motion sensors managing library ๐Ÿƒ

License: MIT License

Ruby 1.66% Swift 97.67% Objective-C 0.67%

rxmotionkit's Introduction

RxMotionKit

Platform CocoaPods Compatible Carthage compatible

RxMotionKit is a motion sensors managing library written in Swift.

Features

  • CoreMotion RxSwift support
  • Swifty interface
  • Pleasant data model

Description

Library wraps CoreMotion and RxSwift frameworks and provides pleasant way to obtain data from sensors.

Requirements

  • Xcode 8.1+
  • Swift 3.0+

Installation

CocoaPods

RxMotionKit is available through CocoaPods. To install it, simply specify it in your Podfile:

pod 'RxMotionKit', '~> 0.7.0'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate RxMotionKit into your Xcode project using Carthage, specify it in your Cartfile:

github "rsobolewski/RxMotionKit" ~> 0.7.0

Run carthage update to build the frameworks and drag them into your Xcode project.

Usage

Start motions source updates

To start updating data from sensors import RxMotionKit module and get reference to singleton instance of MotionManager:

import RxSwift
import RxMotionKit

unowned let motionManager = MotionManager.shared

subscribe an Observable:

motionManager.rx_didUpdateMotionData
	.subscribe(onNext: { (data) in
		// Handle received data
	})

and start updating selected sources:

motionManager.startUpdating([
    .accelerometr,
    .gyroscope,
    .magnetometer,
    .deviceMotion
    ],
    withInterval: 5.0
)

For convenient usage when you want to obtain few updates you can use take to automatically stop updates when defined limit is reached:

motionManager.rx_didUpdateMotionData
	.take(4)
	.subscribe(onNext: { (data) in
		// Handle received data
	})

Stop motions source updates

To stop updates from selected sources:

motionManager.stopUpdating([
    .accelerometr,
    .gyroscope,
    .magnetometer,
    .deviceMotion
])

Types of motion source

All motion sources that are available:

  • accelerometr - Accelerometer
  • gyroscope - Gyroscope
  • magnetometer - Magnetometer
  • deviceMotion - DeviceMotion

Also you can conveniently specify all motion sources using MotionSourceType.all.

Types of Observables

There are several types of Observables provided by MotionManager:

  • rx_didUpdateMotionData - general observable for motion data updates, that merges all events from all source updates
  • rx_didUpdateAccelerometerData - accelerometer updates
  • rx_didUpdateGyroscopeData - gyroscope updates
  • rx_didUpdateMagnetometerData - magnetometer updates
  • rx_didUpdateDeviceMotionData - device motion updates

Updates configuration

All sources require the update time interval, that must be provided in method which start updates:

let updateTimeInterval = 1.0 // 1 sec
startUpdating([.accelerometer], withInterval: updateTimeInterval)

For device motion updates you can choose a reference frame for attitude, which will be default if you not provide any.

startUpdating([.accelerometer], withInterval: updateTimeInterval, referenceFrame: .xArbitraryZVertical)

Communication

If you want to contribute, please submit a pull request. For code consistency please use SwiftLint with configuration from this repository.

Author

Robert Sobolewski, contact me on Twitter

License

RxMotionKit is available under the MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.