Giter Site home page Giter Site logo

freefalldetection's Introduction

Free Fall Detector

An Android Library to detect free fall of the phone. The library implements a very simple algorithm to detect the free fall of a phone using the accelerometer readings

Methodology

During a free fall the magnitude of the acceleration vector should approach 0 and when it lands somewhere, a spike in the magnitude should be encountered. So we can set a threshold magnitude, and when the magnitude drops below that threshhold we can mark the start of the fall, and thereafter when the magnitude rises back above the threshold, that can be marked as the end of fall. The algorithm in not fully robust, but can easily eliminate the other movements of phone like shaking, rotating etc. The algorithm can lead (but not limited) to some false records if a temporary obstruction is placed between the fall or the phone is dropped on a elastic surface.

What the Library Does

  • Runs a foreground service which detects the falls which can be started and stopped by the caller
  • Stores the fall details in a SQLite database
  • Pushes a notification to device at the end of fall
  • Publishes the history of falls stored in the DB to be consumed by the caller

Usage

Call the init() function of FreeFallDetector(singleton object) passing the context. This has to be the very first step before using the library

try{
 FreeFallDetector.init(applicationContext)
 }
 catch(ex : NoAccelerometerException){
 // Handle exception
 }
 

To start the Fall Detection Service call the startDetection method with optional parameters to customize magnitude threshold and sensor delay

FreeFallDetector.startDetection(threshold = 1.5, sensorDelay = SensorManager.SENSOR_DELAY_UI)

To stop the Fall Detection Service call the stopDetection method

FreeFallDetector.stopDetection()

To know the status of whether the service is running or not, you can observe the livedata exposed by

FreeFallDetector.getIsFallDetectionRunning(): LiveData<Boolean>

To get all the history of the falls, you can observe the livedata exposed by

FreeFallDetector.allFalls(): LiveData<List<Fall>>

To clear the database, you may call the coroutine method

FreeFallDetector.clear()

A demo app which uses the functionality of the library is also included

freefalldetection's People

Contributors

abhishekab avatar

Watchers

James Cloos avatar  avatar

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.