Jump to content

[solved] G-Sensor with DeviceIoControl


Recommended Posts

Hi all,

one more question about Omnia 2, I'll try to make it quick this time.

I'm trying to use DeviceIoControl method to access Omnia 2 g-sensor as Koushik explains it in his excellent unified sensor API articles.

For sensor initialization, it gives something like that :


#define ACCOnRot 0x44E // on

HANDLE hFile = CreateFile(L"ACS1:", 0, 0, NULL, OPEN_EXISTING, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
return;

DWORD bytesReturned = 0;
DWORD InBuffer = 0;
DWORD InSize = sizeof(DWORD);
DWORD OutBuffer = 0;
DWORD OutSize = sizeof(DWORD);
BOOL result = DeviceIoControl(hFile, ACCOnRot, &InBuffer, InSize, &OutBuffer, OutSize, &bytesReturned, NULL);

...
[/codebox]

However, this doesn't work anymore on the Omnia 2, and the application can't create a valid handler through CreateFile. Seems the method has been locked or the handler removed... don't know.

I guess I should look into windows API or some documentation to find a workaround, but I don't really know where...

any idea ?

Thanks :D

Edited by MMoi
Link to comment
Share on other sites

Guest GinKage

You have three options.

First: use Samsung SDK.

Second: use my HTCSensorSDK.dll for Omnia 2.

Third: implement it like I did. :D

HANDLE hSensorDevice = CreateFile(_T("ACC1:"), 0, 0, NULL, OPEN_EXISTING, 0, NULL);

if (hSensorDevice != INVALID_HANDLE_VALUE)

{

	short data[3];

	DWORD BytesReturned;

	if (DeviceIoControl(hSensorDevice, 0x80122EF0, 0, 0, data, 6, &BytesReturned, NULL))

	{

		TiltX = data[0] - 2048;

		TiltY = data[1] - 2048;

		TiltZ = 2048 - data[2];

	}

	CloseHandle(hSensorDevice);

}

Note: for B7610 you'll need to invert Y and Z readings...

Link to comment
Share on other sites

GinKage again ! Is there something you don't know about this device ? :(

1st option is possible, but i'd like to avoid it... it would mean create one exe for each device I want to support

2nd option means also one SDK for each machine, what I'd like to avoid for something as "trivial" as g-sensor (I do it for 3d renderer, though, using a wrapping DLL for each API - OGLES or D3DM)

3d option seems the best, that's what I was looking for but I still have few questions :

- the drive code has been changed from ACS1 in Omnia to ACC1 in Omnia 2, as well as operation codes (from 0x3F7 to 0x80122EF0 in the read values example). Is there a way to know (programatically or some doc) what codes are used in a device ? It would allow me to adapt each values for each device.

It would help me also to get the other codes, since I'm using a little different process from yours : I first init the sensor one time (with ACCOnRot, see below), then read the sensors (with ACCGetStateRot) and finaly uninit it once (ACCOffRot)

- if such information is unavailable, could you please give me the remaining operation codes I shall use for Omnia 2 ? Omnia 1 operation codes I use are as follows :

#define ACCGetStateRot 0x460 // get on/off state

#define ACCOnRot 0x44E // on

#define ACCOffRot 0x44F // off

#define ACCReadValues 0x3F7 // compute value

Thanks a lot :D

Note: FYI here is the way I read data (Koushik way once again)


#define DIMENSION 3
#define samsungScaleFactor (1.0 / 1000.0 * 9.8 * 3.3793103448275862068965517241379)
const int inReadSize = sizeof(int);
const int outReadSize = sizeof(int) * DIMENSION;

int outBuffer[DIMENSION];
int inBuffer[1];
DWORD bytesReturned = 0;
if (!DeviceIoControl(readFile, ACCReadValues, inBuffer, inReadSize, outBuffer, outReadSize, &bytesReturned, NULL))
{
CWarning(_T("[CSamsungGSensor] error in g-sensor\n"));
return Ret;
}

// compute normalized float value
Ret.value = TVector3F((float)outBuffer[0], (float)outBuffer[1], -(float)outBuffer[2]) * (float)samsungScaleFactor;
[/codebox]

Ret being just a structure to store my vector...

Edited by MMoi
Link to comment
Share on other sites

Guest GinKage
1st option is possible, but i'd like to avoid it... it would mean create one exe for each device I want to support

Quite the contrary, you'll only need to load Samsung's dll, which will work, for example, on Omnia 1, 2 and Pro, without any recompilation.

- the drive code has been changed from ACS1 in Omnia to ACC1 in Omnia 2, as well as operation codes (from 0x3F7 to 0x80122EF0 in the read values example). Is there a way to know (programatically or some doc) what codes are used in a device ? It would allow me to adapt each values for each device.

All of this is undocumented and is acquired from Samsung's test programs and SDK.

It would help me also to get the other codes, since I'm using a little different process from yours : I first init the sensor one time (with ACCOnRot, see below),

CreateFile()

then read the sensors (with ACCGetStateRot)

DeviceIoControl()

and finaly uninit it once (ACCOffRot)

CloseHandle()

See, no difference. :D

- if such information is unavailable, could you please give me the remaining operation codes I shall use for Omnia 2 ? Omnia 1 operation codes I use are as follows :

#define ACCGetStateRot 0x460 // get on/off state

#define ACCOnRot 0x44E // on

#define ACCOffRot 0x44F // off

#define ACCReadValues 0x3F7 // compute value

I'll need to dig into Samsung's dll's for that... I'm currently a bit both busy and lazy to find all of these, and I'm not quite sure why you need all of them.

Link to comment
Share on other sites

Quite the contrary, you'll only need to load Samsung's dll, which will work, for example, on Omnia 1, 2 and Pro, without any recompilation.

Ha yeah, you're right, still it woudn't work on HTC... I guess in this case I should create a plugin for g-sensor that would load the needed DLL on runtime with LoadLibrary (as I did for renderer and audio API)... but I'm pretty lazy to do it for g-sensor (and short of time, this would need me something like 2 or 3 days of implementation), maybe I'll do it when I'll have to support more than 2 or 3 devices :D

CreateFile()

DeviceIoControl()

CloseHandle()

See, no difference. :(

...

I'll need to dig into Samsung's dll's for that... I'm currently a bit both busy and lazy to find all of these, and I'm not quite sure why you need all of them.

Sure, I didn't express my thoughts correctly. What I meant is :

- first I call CreateFile AND DeviceIoControl (with AccOnRot) once to initialize the sensor

- then on (almost) each update I call DeviceIoControl (with AccReadValues) to get the values, as you do

- finally I call DeviceIoControl (with AccOfRot) and then CloseHandle() to uninit the sensor

The main differences between our implementations are that

- I CreateFile only once and not each time I want to get the data. Isn't it a lack of optimization in your implementation ? I actually don't know if CreateFile is much time consuming, but I try to have as much "global" (or at least member) variables as I can to save time on the CPU (except heavy elements such as sound/textures, that I unload as soon as I can to stay far from the frightening virtual mem cap)

- I use 3 different calls to DeviceIoControl. This is the part I just scrapped from Koushik work, I thought it was needed but it seems you don't use them at all... thus i'm not quite sure myself why I need them ;)

Link to comment
Share on other sites

Guest GinKage
The main differences between our implementations are that

- I CreateFile only once and not each time I want to get the data. Isn't it a lack of optimization in your implementation ? I actually don't know if CreateFile is much time consuming, but I try to have as much "global" (or at least member) variables as I can to save time on the CPU (except heavy elements such as sound/textures, that I unload as soon as I can to stay far from the frightening virtual mem cap)

- I use 3 different calls to DeviceIoControl. This is the part I just scrapped from Koushik work, I thought it was needed but it seems you don't use them at all... thus i'm not quite sure myself why I need them :(

My code was just an example of how you can do it. Of course, I don't open the device every time I need to read data, I do it once!

It's just that OnRot and OffRot calls are not needed at all! Again, there's actually no difference. :D

Link to comment
Share on other sites

Guest wakeupneo
You have three options.

First: use Samsung SDK.

Second: use my HTCSensorSDK.dll for Omnia 2.

Third: implement it like I did. :D

Note: for B7610 you'll need to invert Y and Z readings...

Just a small note to second option:

Your sensor SDK does not work for some applications like Resco Photo Manager (aka Photo Viewer) and Kinoma Play and I had problems with it when I tried to use it when I tried to code a pocket-detector app (proximity sensor triggered and g sensor is 1800-2200 ~2800 ~2000).

Edited by wakeupneo
Link to comment
Share on other sites

My code was just an example of how you can do it. Of course, I don't open the device every time I need to read data, I do it once!

It's just that OnRot and OffRot calls are not needed at all! Again, there's actually no difference. :D

Got it, thanks again for the tips :(

Link to comment
Share on other sites

  • 2 months later...

Can I ask you to share the code used for the omnia II and omnia. The source for the omnia on codeplex look a bit out of date and doesn't work on my omniaII.

I downloaded the SDK and the test program worked. Maybe you can help?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.