HTC Touch Diamond Nav Sensor API

diamondnav

Scott, from scottandmichelle.net, figured out how to detect which way the nav sensor was being moved. I did some further investigation with the data output and managed to figure the rotation per second readings that were also being returned with it.

The new HTCNavSensor has a single event:

Rotated

This event fires whenever the Nav sensor event is detected. The rotation event will provide the user with an approximate rotation per second value and a radial delta. The radial delta is a double value that describes how much the user has moved along the nav sensor since the last time the event was fired. I.e, a radial delta value of .25 would mean that the user moved his finger around a quarter rotation since the last the last time the nav sensor event fired.

As usual, the updated API can be downloaded here. The other sensor APIs (accelerometer and light sensor) are also available in the same zip file. So that wraps up accessing all the different sensors on the HTC Touch Diamond!

Let me know if you find any bugs!

Edit: I found a bug where the nav sensor was reporting clockwise movement when actually moving clockwise. Fixed that. Also updated the Nav Sensor Test to show a red line that rotates as you rotate around the sensor.

34 comments:

Anonymous said...

Hi,

First off all very nice work on the Wrappers, first clas man!

I was playing with the HTCNavSensor and I was wondering if there is any way to know if the "Center" button is touched (the one used to focus when taking pictures) would that be hard to implement in your API?

Thanks Ramon

Koush said...

Oh, very good point. I completely forgot about the center sensor! I'll have to look into that and try to figure it out.

Houser said...

Have found your SDK here and it is really great what can be done on the diamond.
Thanks for your work! :)

andrec said...

I don't think you have covered them all yet :)
How about the Pen Remove sensor?
It is not just a hardware sensor that turns on the device, since it also opens up the Notes application when in a call.

crafty said...

Hi Koush, thanks for the sensor SDKs and the great blog posts - i've learned a lot from them! I was wondering if you had seen the HTC debug tools, specifically the NavDbgTool.exe which shows that the whole bottom panel is a capacitive touch sensor, supporting multi touch.

Any plans to dig into this and help us out with a managed wrapper?

The programmer said...

Great work! Your sample shows intercepting events at a form level. Is it possible to intercept these events as well if your application is the background (to respond to various actions even if your application is not the foremost app)

Koush said...

Nope, it only sends events to your form when it has focus.

JDBarclay said...

Hi Koush, I was wondering if its possible to get G-sensor event notifications through SNAPI? (instead of constantly looping which leaks battery) Any approach to this?

Thanks!

Denis Salanta said...
This comment has been removed by the author.
Denis Salanta said...

actually it gets the first position but it does not change.

i have a timer starting on form_load then on timertick i want to check screenOrientation. It is always the first tick.


sorry for double post but i don't know how to edit the previous one.

Brando said...

Hi,

This is a great Wrapper, It has allowed me to make some awesome programs. Just a curiousity, is this Wrapper compatible with other HTC phones? Although, I'm not sure whether other htc phones have these sensors.

Anonymous said...

I can't seem to load up and of the sdks in vs208, it says "an application is not loaded for one of the projects". When I check the project browser it all has nothing loaded. Any ideas?

Koush said...

I know for sure that the wrapper works on Omnia, Touch Diamond, Touch Pro, and will probably work on the Touch HD as well.

Regarding the person having issues with the project: verify you have Windows Mobile 6 SDK installed.

Koush said...

theprogrammer: By subclassing a window, you can intercept all events, even if you are in the background. Keep in mind though, that no form can receive key/mouse events in the background.

David said...

Hi, I am having the same problem as an earlier poster. The GSensor never ever fires an OrientationChanged event, and the Orientation is never updated in the loop, so the orientation displayed is always the same. The orientation is the orientation of the device during the first painting of the screen. But it never updates again after this.

Any thoughts on what might be wrong?

Thanks!

David said...

I guess it looks like the registry value holding orientation does change because if I start the program in a new orientation, that is shown in the string. But it looks like the myOrientationState.Changed event is never firing while the program is running. I have put a break point on the first line of the handler, and it is never reached...

Could the program get a lock on the registry key so that it cannot be changed when you move the device?

Thanks again.

David said...

Alternatively, could listening for the GSensor in order to build the G vector interfere with the process which uses the GSensor to update the registry?

This is a very odd bug. I think I will just write my own code to determine the orientation from the vector.

Thanks.

Koush said...

Hi David, that bug is fixed in the latest version of the SDK. The sensor is now using a polling mechanism instead of a registry key.

Koush said...

Also, you can convert a GVector to an orientation using GVector.ToScreenOrientation()

David said...

Thanks for the reply. I saw that method after I programmed something almost identical! That is a very useful method.

My program also uses your OpenGLES wrapper (which is also great, thanks!) and I poll the GVector within the OpenGL animation loop, and it all ends up working fine.

I do have a question about the OpenGLES wrapper also. There seems to be a bug. If I load a number of textures, I very quickly get an exception that says:

Not enough storage space to complete this operation at OpenGLES.Texture.BeginLoadBitmap(...

But when I call

GC.GetTotalMemory(true);

I am using only 344100 bytes of memory. The images I am trying to load are each under 100Kb and all have some transparency, if that matters. I am using a Diamond Touch and should have lots more memory available...

I have tried to follow the debugger into this function but I figure it might be a lot easier just to ask if this is something that you have seen before etc. or if there is some sort of OpenGL specific memory buffer which I can make bigger etc.

Thanks again! Sorry to ask this question in the wrong section of the blog!

Koush said...

Hi, you can email me at

koushikdutta at hotmail dot com

Anonymous said...

Hi, thanks for your share. And I have download your code. But I met a problem when I tried to build them. only LightSensor project works well, other projects, such as SylusSensorTest throw an errow said "Unable to start program '%CSIDL_PROGRAM_FILES%\StylusSensorTest\StylusSensorTest.exe'. The system cannot find the file specified."

do you have any idea about this error?

I checked the "bin\debug\", and there was a StulysSensorTest.exe

Thank you!

Anonymous said...

Hi, I'm the up one. I just want to say I have fixed the problem that cannot find the special files by coping debug to device, and all your demos work well!

Thank you very much!

Julien Cayzac said...

HI Koushik,
I've mailed you some changes I made to your code to get notified when the center button gets touched, at your hotmail mailbox.

Cheers,
Julien

Koush said...

Hi Julien,

I received your email. I will be updating the Sensor API again shortly, with support for a new device family! I'll integrate your code then.

Julien Cayzac said...

Is the new family the Aquos, by any chance? :)

Julien Cayzac said...

Btw, under which licence is the sensors api distributed? Is it BSD-like? I could not find any info...

Koush said...

All code found on this site is licensed under the Do What The Fuck You Want To Public License (WTFPL). Yes, it is a legitimate license.

http://sam.zoy.org/wtfpl/

Anonymous said...

Hey, great work, and even better that you're sharing it...

Noting that the entire area for the Hardware Buttons on the diamond is touch sensitive (take GScroll as a program that utilises it) have you figured out how to access the whole area...?

As opposed jsut to the cernter part...

Cheers

Peadey said...

Hi, thanks for the great work! I'm a musician and wrote a metronom program. So now I can use the nav-sensor to change the metronom value up and down. Wonderful! :-)

Fernando said...

thanks

Minh said...

sorry but i can't download it from both your blog & codeplex. i'm very interested in your work here, so please send me the .cab file to mad_gear123@yahoo.com ....thanks:D

Joshua Smith said...

Thanks for useful info! For industry solutions it is the right way to get outsource software development.

Joshua Smith said...

A lot of thanks for this great tips. Casino affiliates always search for casino programs for partners to increase their revenue income from best casinos or poker rooms.