PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

G-Sensor: interest in a class?

CodeFlatter · 11 Apr 2009, 22:08 UTC
Features:
- Ready to use in PocketHAL/PocketFrog (GapiDraw is untested)
- Simple callback handler connction system (if u want)
- You can connect your own callback handlers for orientation changing and sensor data receving from d-pad (gesture sensor and pad's)
- or you can polling all of data
- internal exception handling
- all events handled internal, no external window resource needed
- threaded event and message handling

Special Features:
- EMULATOR Mode
data polling and callback handlers is working
emu mode simulate the sensors with user defined data

received sensor data:
- gesture, d-pad and all other pad's
- tilt sensor (X,Y,Z, Angle X/Y)
- orientation changing (landscape, portrait ...)

sry 4 my bad english :wink:
CodeFlatter · 12 Apr 2009, 10:40 UTC
Usage of G-Sensor at PocketFrog

pleace check GSensor.h and GSensor.cpp, the code is well documented. (i hope it!)

1. create data members at your myGame.h and include the G-Sensor declaration
Code:

#include "GSensor.h"

class myGame : public Game
{
...
public:
HINSTANCE m_hInstance;
GSensor m_GSensor;
};


2. save the hInstance to m_hInstance
Code:

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
_Module.Init( 0, hInstance );

myGame game;
myGame.m_hInstance = hInstance;

myGame.Run();

return 0;
}


3. initialize G-Sensor at myGame.cpp
Code:

bool myGame::GameInit()
{
Display* pDisplay = GetDisplay();

...

m_gSensor.Initialize( g_hInstance ); // initialize G-Sensor system
m_gSensor.WaitToInitialize( 1 ); // wait 1 second

return true;
}


How to get data from G-Sensor

the class offers many methods.

Tilt-Sensor:

DWORD GetSensorData( PSENSORDATA a_pSensordata );
DWORD GetAngleX( void );
DWORD GetAngleY( void );
SHORT GetTiltX( void );
SHORT GetTiltY( void );
SHORT GetTiltZ( void );

gesture, touchpad and d-pad sensor

bool IsPaneTouched( void );
bool IsPaneLeftTouched( void );
bool IsPaneRightTouched( void );
bool IsPaneWheelTouched( void );
bool IsPaneWheelCenterTouched( void );
BYTE GetPaneLeftTouchedX( void );
BYTE GetPaneLeftTouchedY( void );
BYTE GetPaneRightTouchedX( void );
BYTE GetPaneRightTouchedY( void );
BYTE GetPaneWheelAngle( void );

orientation data

ENUM_ORIENTATION GetOrientation( void );

How to use the callback handler event system

first, an event handler prototype has this signature:
Code:
void OnMyEvent( void );


now: define for each desired event one function.

connect a callback handler

the class has 3 callback handler systems:

A: orientation changing events

enum ENUM_ORIENTATION
{
ORIENTATION_LANDSCAPE = 0,
ORIENTATION_REVERSE_LANDSCAPE = 1,
ORIENTATION_PORTRAIT = 2,
ORIENTATION_UPSIDE_DOWN = 3,
ORIENTATION_FACE_DOWN = 4,
ORIENTATION_FACE_UP = 5,
ORIENTATION_UNKNOWN = 6
};

B: gesture (d-pad) events

enum ENUM_GESTURE
{
GESTURE_ROTATION_CLOCKWISE = 0,
GESTURE_ROTATION_COUNTERWISE = 1
};

C: touch pad events

enum ENUM_TOUCH
{
TOUCH_PANE = 0, // One 4 all!
// or separate, don't use TOUCH_PANE and following to the same time
TOUCH_PANE_LEFT = 1,
TOUCH_PANE_RIGHT = 2,
TOUCH_PANE_WHEEL = 3, // gesture pane
TOUCH_PANE_WHEEL_CENTER = 4
};

each event type has its system connector.

example for orientation changing:
connect the handler
Code:

m_GSensor.ConnectCallbackHandler( GSensor::ORIENTATION_PORTRAIT, OnOrientationPortrait );

your event handler has this signature:
void OnOrientationPortrait( void );

example for gesture changing:
Code:

m_GSensor.ConnectCallbackHandler( GSensor::GESTURE_ROTATION_CLOCKWISE, OnRotateClockwise );


and example for touch pad:
Code:

m_GSensor.ConnectCallbackHandler( GSensor::TOUCH_PANE_LEFT, OnLeftPaneTouched );


notice: the tilt-sensor has no callback system!

Usage of the G-Sensor emulator mode at windows mobile device emulator


uncomment line 7 at GSensor.h, that's all!

if you do this, the emulator mode offers many more methods to control of the g-sensor data.

bool SetOrientation( ENUM_ORIENTATION a_enumOrientation );
void SetSensorData( PSENSORDATA a_pSensordata );
void SetAngleX( DWORD a_dwAngleX );
void SetAngleY( DWORD a_dwAngleY );
void SetTiltX( SHORT a_sTiltX );
void SetTiltY( SHORT a_sTiltY );
void SetTiltZ( SHORT a_sTiltZ );
void SetPaneTouched( bool a_bIsPaneTouched = true );
void SetPaneLeftTouched( bool a_bIsPaneLeftTouched = true );
void SetPaneRightTouched( bool a_bIsPaneRightTouched = true );
void SetPaneWheelTouched( bool a_bIsPaneWheelTouched = true );
void SetPaneWheelCenterTouched( bool a_bIsPaneWheelCenterTouched = true );
void SetPaneLeftTouchedX( BYTE a_byPaneLeftTouchedX );
void SetPaneLeftTouchedY( BYTE a_byPaneLeftTouchedY );
void SetPaneRightTouchedX( BYTE a_byPaneRightTouchedX );
void SetPaneRightTouchedY( BYTE a_byPaneRightTouchedY );
void SetPaneWheelAngle( BYTE a_byPaneWheelAngle );

if you change values, all connected event handlers are called!
you can test how the application behaves if sensor-specific data received.



i hope the class is usefull for you.
good luck and have fun!

regards CF

sorry, this is only german available:
Image

sry, downloads no longer available.
CodeFlatter · 26 Apr 2009, 11:45 UTC — Version 1.3 available
Version 1.3 is available.
CodeFlatter · 27 Apr 2009, 11:55 UTC — feadback?
feedback would have been nice... :wink:
CodeFlatter · 26 May 2009, 09:05 UTC
this and new versions are no longer available,
thanks for the "lively" participation...

can closed.
LOL?

Feeling better?