Entries:
Comments:
Discussions:

Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

There's a new Windows Phone 7 project place in town...

CodePlex is one of the more (most?) common place you'll find hosting Windows Phone 7 projects. It's a a prefect match for many developers, given that it's free, can host source, binaries, docs, work items and discussions and plugs directly into Visual Studio. That said, everyone is different and have different needs and likes.

There's a new, for Windows Phone 7 dev's anyway, project hosting location in town. One that many in the Microsoft sphere might not have considered or ever heard off, but in hindsight makes sense...

Who's hosting this mystery project site? Nokia! Yep, that Nokia.

SNAGHTML37f18b24

And surprisingly enough, today's project is hosted there and comes to us via a comment left on a previous post.

Bubble Level Silverlight

Simple Silverlight example demonstrating use of accelerometer sensors to calculate the inclination of the device and presents this as a traditional bubble level.

General

BubbleLevel Silverlight is a port of Qt Bubble Level Qt application, more information about the port can be found from the porting story page.

BubbleLevelSilverlight

Of special note is the wiki pages where you'll find a great story on how this project was built and also how the porting was done.

SNAGHTML37f85630

SNAGHTML37f8d712

It's a simple app, but sometimes simple is all you need (less is more and all that). Here's a snap of the project and a code snip.

SNAGHTML37fee545

/// <summary>
/// Updates the position of the bubble in the glass tube.
/// </summary>
/// <param name="e">Contains the accelerometer reading value.</param>
protected void UpdateBubble(AccelerometerReadingEventArgs e)
{
     const double RADIANS_TO_DEGREE = 57.2957795;
     double divider = Math.Sqrt(e.X * e.X + e.Y * e.Y + e.Z * e.Z);

     // Calculating the angle + using low pass factor 20 %.
     // Values from all three accelerometers are used to get more precise reading on y-axis.
     m_Angle += (Math.Acos(e.Y / divider) * RADIANS_TO_DEGREE - 90 - m_Angle) * 0.2;

     double angle;

     // Depending on the orientation, invert the accelerometer value
     if (Orientation == PageOrientation.LandscapeLeft)
     {
         angle = -m_Angle + m_CalibrationFactor;
     }
     else
     {
         angle = m_Angle - m_CalibrationFactor;
     }

     const double MAX_ANGLE = 20.0;

     // Restrict the angle value to the range -20 and 20 degrees.
     if (angle > MAX_ANGLE)
     {
         angle = MAX_ANGLE;
     }
     else if (angle < -MAX_ANGLE)
     {
         angle = -MAX_ANGLE;
     }

     // Set the bubble position.
     BubbleTransform.X = angle / MAX_ANGLE * (Reflection.Width / 2 - Bubble.Width / 2);
}

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Remove this comment

Remove this thread

Close

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.