Community: Wiki

你在这里: You Are Here: Olet tässä: Vous êtes ici: Sie befinden sich hier: Tu sei qui: 現在のページ: Você está aqui: Вы здесь: Usted está aquí:
This page was last modified 17:02, 26 October 2008.

Using accelerometer - Hourglass

From Forum Nokia Wiki

Contents

Overview

This application uses the accelerometer simulating a real hourglass in a Nokia N95. Every time you change device's position, an observer updates the acceleration values in each axis, ranging from -360 to 360. The following code snippet shows how to detect sensors in the device.

Header

//SensorApi header
#include <rrsensorapi.h>
 
//CGravitation class inherits an interface MRRSensorDataListener
class CGravitationAppView : public CHourglass,...,MRRSensorDataListener
{
	public:
	   ...
	   //Virtual function inherits from MRRSensorDataListener
	   void  HandleDataEventL (TRRSensorInfo aSensor, TRRSensorEvent aEvent);
	   ...
 
	private:
	   //Instance of CRRSensorApi
	   CRRSensorApi* iSensorApi;

Source

void CGravitationAppView::ConstructL( const TRect& aRect )
{
   ...	
 
   //Creating an array of sensors 
   RArray< TRRSensorInfo > sensorInfoArray;
 
   //Using FindSensorsL to find all sensors in the device and
   //fill the array with the available sensors
   CRRSensorApi::FindSensorsL(sensorInfoArray);
 
   if(sensorInfoArray.Count() > 0)
   {
         //Constructs the iSensorApi with an sensor in the array
         iSensorApi = CRRSensorApi::NewL(sensorInfoArray[1]);
         iSensorApi -> AddDataListener(this);
   }
   else
      User::Leave(KErrNotSupported);
      ...
}
 
CgravitationAppView::~CGravitationAppView()
{
   ...
   //releases memory allocated 
   if(iSensorApi)
   {
      delete iSensorApi;
      iSensorApi = NULL;
   }
   
   ...
}
 
 
//HandleDataEventL's implementation, Callback that updates the acceleration
void CGravitationAppView::HandleDataEventL (TRRSensorInfo aSensor, TRRSensorEvent aEvent)
{
 
   TInt i;
 
   for(i = 0; i < iGrains.Count(); i++)
   {
      iGrains[i]->SetAcelXY(-aEvent.iSensorData2, -aEvent.iSensorData1);
   }
 
}

Application

Image:Newnewamp.JPG

More information

See More: http://efforts.embedded.ufcg.edu.br/symbiancpp/

Related Discussions

Thread Thread Starter Forum Replies Last Post
[announce]mouse control in linux with accelerometer clem-vangelis Python 1 2008-11-01 17:37
Nokia 5500 ssandor Mobile Java General 5 2007-10-09 22:03
Nokia 5500 Accelerometer extension GodPascal Python 1 2007-09-25 14:51
Gesture recognition djsid Python 9 2008-08-12 22:14
Accelerometer is a bit shakey!! dinnerdog Python 7 2008-09-16 11:02

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Invite a friend Invite a friend
E-mail Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us Regional websites: Chinese Japanese © 2008 Nokia 
RDF Facets: qfnZtopicQUqfnTopicZsensorQ qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX