DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Detecting a Windows Phone physical drop - Part 2 - Detecting the fall

Detecting a Windows Phone physical drop - Part 2 - Detecting the fall

Denzel D. user avatar by
Denzel D.
·
Aug. 13, 11 · Mobile Zone · Interview
Like (0)
Save
Tweet
6.05K Views

Join the DZone community and get the full member experience.

Join For Free

As you already know the theory behind the falling process, it is time to work with the code that will be able to detect the fall itself on the phone.

When the phone is free falling, the value of the composite (net) force is getting really close to zero - that is clearly see on the graph, when the size of the rectangles is shrinking in a matter of seconds.

That being said, I need to detect when the value drops and a threshold is hit. To begin with, I am setting the threshold to 0.5 and it can ultimately be adjusted to a lower value (for example, if the phone falls from a bigger altitude). I am also introducing a new flag - thresholdHit, that holds a Boolean value, determining whether the low threshold is hit and the phone is in a state of a free fall.

The default value is set to false, and I am checking both the current value of the net force and the flag each time the accelerometer reports value changes:

if ((f < 0.5) && (!thresholdHit))
{
    thresholdHit = true;
}

Once I get the flag ready, I need to check when the phone finally hits the ground. This is visible on the graph by a large spike:

This spike goes higher than the stationary graph on collision. So I set the default criticial threshold to be 1.5 and I am checking against it if the lower threshold was hit:

else if ((f > 1.5) && (thresholdHit))
{
    acc.Stop();
    Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show("Hit the ground."); }));
}

After the collision, I can either wait for the graph to normalize, so that the net force value is returned to 1G, or I can perform a specific action directly after the hit.

You should be careful here, because in this case I am making one very important assumption - the phone doesn't hit anything else while falling, which might not always be case. That's why it is important sometimes to check for a constant value on the graph on the completion of the fall.

DO NOT TRY TO DROP YOUR PHONE. Instead, use this custom accelerometer motion and use it with the Windows Phone Emulator.

Some limitations that are present in the platform that might limit the functionality of the application, are the following:

  • No full-fledged background processes that can allow the application to timely alert about a fall.
  • No automated calls to a specific number, so the scenario shown in the initial project, where the owner might become unconscious/hurt and the phone will dial somebody for helpĀ  is not possible at the moment.
Windows Phone Drops (app)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Ultra-Fast Microservices: When Microstream Meets Wildfly
  • Synchronization Methods for Many-To-Many Associations
  • OpenTelemetry in Action: Identifying Database Dependencies
  • Memory Debugging and Watch Annotations

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo