Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Using the APS Accelerometer in Lenovo Laptops

, 6 Jan 2009 Public Domain
Use the accelerometer in Lenovo laptops to determine the computer's attitude and temperature.
LenovoAPS_demo.zip
AS3.swf
AxInterop.ShockwaveFlashObjects.dll
Flash.exe
Interop.ShockwaveFlashObjects.dll
LenovoAPS_src.zip
Flash
AS3.swf
bin
Release
AS3.swf
AxInterop.ShockwaveFlashObjects.dll
Flash.exe
Flash.vshost.exe
Flash.vshost.exe.manifest
Interop.ShockwaveFlashObjects.dll
Properties
Settings.settings
namespace Flash
{
    using System;
    using System.IO;
    using System.Windows.Forms;
    using MWudka;

    /// <summary>
    /// A fairly lame demo of the Lenovo APS. Wiggle the computer and the bar wiggles. I can get the ball to stay on the bar for about 8 seconds.
    /// </summary>
    public partial class Form1 : Form
    {
        /// <summary>
        /// An APS instance for talking to the APS
        /// </summary>
        private APS aps;

        /// <summary>
        /// Initializes a new instance of the Form1 class
        /// </summary>
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Called when the form loads. It sets up the APS, calibrates it, and loads the sample SWF
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">Event args</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            // Try loading the demo swf
            var demoPath = Path.GetFullPath("AS3.swf");
            if (!File.Exists(demoPath))
            {
                MessageBox.Show(
                    this,
                    "Can't load the demo. There should be a file called AS3.swf in this directory",
                    "Demo Missing",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                this.Close();
                return;
            }

            // Setup and calibrate the APS
            this.aps = new APS();
            this.aps.Calibrate();

            // Load the flash file
            var url = demoPath;
            axShockwaveFlash1.ScaleMode = 0;
            axShockwaveFlash1.LoadMovie(0, url);
        }

        /// <summary>
        /// Called when the flash file uses the external interface. It returns the current attitude.
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">Event args</param>
        private void AxShockwaveFlash1_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
        {
            var att = this.aps.ReadAttitude();

            // Convert the attitude structure into a flash object and pass it to the flash file
            var ret = "<object><property id=\"x\"><number>{0}</number></property><property id=\"y\"><number>{1}</number></property></object>";
            ret = string.Format(ret, att.Roll, att.Pitch);
            axShockwaveFlash1.SetReturnValue(ret);
        }      
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

Sigfrid3141

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 6 Jan 2009
Article Copyright 2009 by Sigfrid3141
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid