Using Samsung Omnia's Accelerometer/G-Sensor from Managed Code

Many months ago, I wrote an API to access the HTC Touch Diamond's Accelerometer from managed code. Those who investigated the code a bit deeper probably noticed that I had stubbed out an interface, IGSensor. I did that in anticipation that many Windows Mobile devices in the coming months would include an accelerometer. It turns out I was right. The idea behind the IGSensor interface was to provide a generic unified API that a developer could use to access the accelerometer of any device without having to worry about which device it was.

Anyhow, I'd gotten several requests to investigate the Samsung API, if there was one. Not an Omnia owner myself, I wasn't particularly motivated. Then yesterday, one of the requestors informed me that Spelomaniac from modaco.com had figured out how to access the Samsung Omnia's accelerometer.

We happened to have an Omnia at my workplace, Kiha, so I grabbed that, and ported the code so it was supported by my API. So yeah, it's all working!

I highly recommend that all developers to download the updated API and make the minor changes necessary so that Omnia users can make use of the HTC Touch Diamond accelerometer applications! Here are the new breaking changes in the API:

  • HTCGSensor is now a private class.
  • SamsungGSensor is a new private class.
  • Instead of creating a HTCGSensor or SamsungGSensor explicitly, developers should use the new GSensorFactory.CreateGSensor method to get the appropriate IGSensor object for the phone the application is running on.
  • IGSensor is now IDisposable. Developers should Dispose of the object once they are finished using it. Not doing so may leave resources or a thread hanging and the application may fail to exit.

That's it! The code changes you need to make should only take you a few minutes.

Click here to download the new Windows Mobile Unified Sensor API.

I'll be making the changes necessary to Klaxon this weekend so it runs on the Omnia. :)

Here is the original C++ code I for the HTC GSensor emulator in case you are interested. I would not recommend using the HTC Accelerometer emulator, because it does not support Orientation Change notifications through the Windows registry.

20 comments:

Anonymous said...

may be speleomaniac from modaco.com

source : http://www.modaco.com/index.php?s=f0a415a97ad69f532dadef02252f1d84&showtopic=272252&view=findpost&p=919306

Anonymous said...

How do i place the file into my omnia phone? Help me please

Anonymous said...

is there any way to get this running in c++?

Koush said...

Not easily, no. A couple ways you could maybe do it:
Wrap IGSensor in a COM object and pass it to C++.
Create a managed exe that loads the sensor, and writes the outputs to a memory location. Read that from your C++ code.
Rewrite all the managed code from scratch in C++...

Anonymous said...

Hey Koush,

your work is great! You are great!
I hope that you don't see me as an opponent or something like that.
To name the truth: without your work I would have never start to program WM games and tools.
I just wanted to thank you - I included the new SDK for Omnia into my projects.
Keep it up!
ageye

Koush said...

Thanks!
I don't think anything of the sort- variety and choice is a good thing. :)

Anonymous said...

I have a problem.When commpiling program with GSensor API this errors occurs:
error CS0234: The type or namespace name 'WindowsMobile' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

But when compiling your sources - no problem. What is the problem?

Thanks in advance.

Koush said...

You shouldn't compile the G-Sensor API into your application- add a reference to it. That way if new phones come out, people can just download a new Sensors.dll that supports their phone and install that, rather than require every developer to reupdate their application.

Microsoft.WindowsMobile.* are assemblies that ship with the Windows Mobile SDKs. You are missing the assembly reference.

Anonymous said...

Hey there,

thanks for the Omnia Sensor SDK.

I tried to replace the sensor references with the HTC Sensors in "Diamond Beer v.1".

But it won't compile anymore.
It says:

Sensors.HTCSensor doesn't contain a definition for GetGVector.

I made a reference to the /obj/release/Sensors.dll, wrote the "using Sensors;" and now I can't quite imagine what's going wrong.

Thanks for your help in advance,

LilaQ

Anonymous said...

Ok, got it finally working. No clue what went wrong, IntelliSense didn't pick up the "CreateGSensor" Function from "GSensorFactory".
Finally it's all good. Just recompiled the HTC 'Seismo' app with a few changes like resolution and a more realistic needle instead of the pen, all to fit to the Omnia. Going to test it when I'm at home.

So far, big thx koush for the SDK.

LilaQ

Anonymous said...

nice but i got a question how do you install or link the file to the existing ones just how do i get it working on my omnia

greetzz

Anonymous said...

Thanks! very good job!!
I have a question, the coordinates system are same with htc diamond?
You posted the diamond's x,y,z direction, but I want to know I can use this same x,y,z direction.

Thank you for your work.

Anonymous said...

I have M490 - Omnia Korean version. It has different screen resolution(480x800). So some exception error occured in specific position.
Is it related with screen DPI or resolution?
If yes, which value modify in SamsungGsensor.cs file with 480x800 resolution?

Anonymous said...

hmm... am I the only one who is downloading an EMPTY sensors.zip file with only sensors.txt file in it!?

theDUEPER said...

ok check it koush im illiterate when it comes to this stuff in need help i wanna play teeter and g flow ive downloaded everthing i need to make it work but it dont work in dont understand what c++ means or patch or COM do you have a link i could go for dummies lol cause im confused ive downloaded the following:

HTCSensorSDK
HTCAPI
sensor test?(it works)
deneme (it to works)
HTC GSensor emulator
games

now what
HELP!!!!!!PLZ!!!

Anonymous said...

anonymous: How can i run accelerometer applications and games on my Omnia phone please help....

Leslie said...

Hello,

Would you be able to cater for the new Asus P835 accelerometer as well? What kind of info would you need from the phone?

I tried using speleomaniac's wrapper for the Omnia, and use the SensorMaze program to test. It doesn't work but I did noticed that there is a dynamic moving blank rectangular area above the maze (some graphic artifacts perhaps). When I placed the device on the table, it stays but when I rotate the device, the rectangular area seems to move but in a random order. Somehow, it did detect some calls from the g-sensor but doesn't know what to do with it. too bad, I am not a programmer and don't have the tools to dig in.

Anonymous said...

is there any chance to have asus p835 sensor included in this api?

Anonymous said...

hi, can I use the sensor in my acer F900?
thx

Adam Eisfeld said...

Im beginning to program games in VB for my Samsung Omnia. Am I correct in assuming this SDK will allow me to access the gsensor in my Omnia with Visual Basic and the Windows Mobile 6 Professional SDK?