WM Tactile/Haptic feedback API - Windows Mobile Development and Hacking General

Does anyone know how to invoke the tactile feedback from an app. Specifically, I am writing my own keyboard but i would like to generate the little pulses when my virtual keys are pressed. I cant find anything on how to actually do this. presumably it's just one system call.
I have a HTC touch pro 2, so i want to get it working on this at first.
thanks for any help,

You just have to vibrate the phone for a very small time, around 20-50ms.
I don't think there's an API for "haptic feedback", it's just a vibration.

It is just touch-vibrate like you said
Just a tip:
The vibration motor is like the led on your device to handle.
Also the vibration/led id is different on different devices!

Hi,
That's what i was thinking too. I'm going to try the WM Vibrate/VibrateGetDeviceCaps/VibrateStop functions to see if they will do it.
If anyone knows if there's more too it than this, please advise.
thanks,

Unfortunately the Vibrate API does not work. These smartphones are actually pocketPC which doesnt support the API.
Intead i use the NLED interface with led=1. This seems to work to create a basic pulse, but i dont know of any way to adjust the strength of the pulse or even if that's possible.
this is what im doing:
Code:
static void LedOn(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 1;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
static void LedOff(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 0;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
static void key_hepatic_feedback()
{
LedOn(1);
Sleep(20);
LedOff(1);
}

No, the strength isn't adjustable. You can only control the duration.

Related

Turn off the phone part of the XDA

I am writing an application for the XDA using eVC++ 3.0 with the Pocket PC 2002 SDK.
What I need to do is turn on/off the phone part of the XDA programatically without displaying the progress bubbles that normally appear.
I have thought about sending keydown and keyup events if I can find the correct key codes but the progress bubbles still appear.
Any thoughts?
Code:
//-------------------------------------------------------------
HINSTANCE hCCoreUtlDll;
typedef void (__cdecl *PSRSFN)(int state);
PSRSFN SetRadioState;
BOOL LoadCCoreUtl()
{
hCCoreUtlDll= LoadLibrary(_T("ccoreutl.dll"));
if (hCCoreUtlDll==INVALID_HANDLE_VALUE)
return FALSE;
SetRadioState= (PSRSFN)GetProcAddress(hCCoreUtlDll, (TCHAR*)0x10);
return (SetRadioState != NULL);
}
void TurnRadioOn()
{
SetRadioState(2);
}
void TurnRadioOff()
{
SetRadioState(1);
}
From reverse engineering rsupgrade.exe.
Code not tested, but I think this is how to do it.
are there other functions for getting the current radio state? presumably so. can someone publish a complete list of funtion ordinals for ccoreutl.dll? sounds like it might have some useful stuff in it.
on a related note - does anyone know where the functionality for entering the SIM pin code lives? Ideally I want to be able to programmatically turn the radio on and input the PIN code without being pestered for it.
thanks,
nick.
Ah those were the days...
Just happen to make it to the last page of this forum. This thread is an example of what was on our minds then.....5 years ago.
WB

tip: how to vibrate

Code:
#include <windows.h>
#include <nled.h>
// from the platform builder <Pwinuser.h>
extern "C" {
BOOL WINAPI NLedGetDeviceInfo( UINT nInfoId, void *pOutput );
BOOL WINAPI NLedSetDevice( UINT nDeviceId, void *pInput );
};
void LedOn(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 1;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
void LedOff(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 0;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
for (int i=0 ; i<10 ; i++)
{
LedOn(1);
Sleep(400);
LedOff(1);
Sleep(200);
}
return 0;
}
led '0' is the radio led
led '1' is the vibrator
Thanks for this tip!
I was just looking for a way to make the phone vibrate. We're doing applications for the deaf community so vibration is absolutely necessary!
/Christer
With settings.LedNum=0 i can do the things with the Radio LED.
But my MDA 2 has a third LED for Bluetooth. And when i query Device Info i get a count of two(starting at 0). But i canĀ“t do something with the 3rd LED. Somebody knows why?
I also would like to know hot the let the first LED flash green and not Red?
Ok this thread is ancient, but I am resurrecting it to ask a relevant question. This is the method that I am currently using to vibrate. The problem is that when the cpu is being used for other tasks, this will tend to make it vibrate longer than expected. For instance if I switch screen orientation and they try this the vibration will be longer because other threads are doing some processing. The following:
LedOn(1);
Sleep(400);
LedOff(1);
is not a reliable method because if the CPU is busy more than 400ms may elapse between the two calls. Sometimes a lot more. Is it possible to use the blink mode for the vibrator, as in using 2 for the OffOnBlink value as in this msdn article?
http://msdn.microsoft.com/en-us/library/ms905326.aspx
So far all I can get it to do is vibrating without stopping. Any help would be appreciated. Thanks.
JKingDev said:
Ok this thread is ancient, but I am resurrecting it to ask a relevant question. This is the method that I am currently using to vibrate. The problem is that when the cpu is being used for other tasks, this will tend to make it vibrate longer than expected. For instance if I switch screen orientation and they try this the vibration will be longer because other threads are doing some processing. The following:
LedOn(1);
Sleep(400);
LedOff(1);
is not a reliable method because if the CPU is busy more than 400ms may elapse between the two calls. Sometimes a lot more. Is it possible to use the blink mode for the vibrator, as in using 2 for the OffOnBlink value as in this msdn article?
http://msdn.microsoft.com/en-us/library/ms905326.aspx
So far all I can get it to do is vibrating without stopping. Any help would be appreciated. Thanks.
Click to expand...
Click to collapse
actually putting the thread to sleep is kinda not recommended, i usually create another thread to vibrate and set it to sleep then stop the vibration and exit the thread.
maybe i can create a class for that, but it will be a C# class, not C++
anaadoul said:
actually putting the thread to sleep is kinda not recommended, i usually create another thread to vibrate and set it to sleep then stop the vibration and exit the thread.
maybe i can create a class for that, but it will be a C# class, not C++
Click to expand...
Click to collapse
I am not exactly sure what you mean by this. Do you do the exact same thing but all in another thread? Or do you start the vibration, create a new thread that just sleeps then stop the vibration when the thread returns? I got even worse results when trying it all in another thread.
Is there no other way to do this than start vibration then stop it after sleeping? There is no way to give it the duration you want?

[REQ]Remapping Camera shot key to volume button?

Hi there,
First of all I tried searching on google and also in this forum itself but I cant find anything related and so i decided to create a new thread on this.
If there anyway via tweaking the registry that i can make use of the volume key on the blackstone to take pictures instead of using the touchscreen? I believe this is possible
I find taking picture using a touchscreen is really difficult.
I read from http://wiki.xda-developers.com/index.php?pagename=HTC_Blackstone_Overview that this is possible by remapping the volume rocker.
Does any know how?
Will anyone be able to help?
I'm requesting this also. HTC should have made an option for us to choose for this from the beginning.
Request also here!
Sorry, I added this "remap volume rocker Solution" because I thought it was possible, but I actually didn't try it. So let's keep this thread to find a way to do it.
Remapping keys is through AE Button Plus or MobileMagic.
Right now we only have the choice of "touch" or "touch and hold" the virtual on-screen button to "auto-focus + shot".
We need to find out if there is any keyboard shortcut associated to that function.
I tried to use the "enter key" fonction remaped to Volume Up with AE Button Plus, but it didn't work.
Does the HTC Touch Pro have HTC's Camera application? maybe they know a keyboard shortcut? Let's ask.
I guess it will be possible.... just that we need the experts here to show us how to...
[APP] CameraButton
To solve this problem. I thought of a very simple solution:
Instead of us clicking the on-screen camera button, we need an application "CameraButton", which will click on the screen for us, then we just need to map a hardware button to that application.
Simple isn't it?
So here is the C# code for the CameraButton application:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace CameraButton
{
class Program
{
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern bool SetCursorPos(int X, int Y);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
static void Main(string[] args)
{
IntPtr cameraHandle;
cameraHandle = FindWindow(null, "Camera");//search camera app
if (cameraHandle == IntPtr.Zero)// cannot find it then launch it
{
Process cam = Process.Start(new ProcessStartInfo("Camera.exe", ""));
//cameraHandle = cam.MainWindowHandle;
}
else // can find it then set position then click
{
//SetForegroundWindow(cameraHandle);// we assume we already have the focus on the camera app
SetCursorPos(240, 750 );//set position to the on-screen camera button
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
}
}
}
}
Why do I give the code rather than the binary?
Because unfortunately this code doesn't work (yet).
Let me explain a bit more:
This application doesn't need to keep running in the background, it just can do 2 things. Start the camera app if it's not already started, or just click at a specifically chosen position.
If I set the position to (0,0), my program will click at the upper-left corner of the screen, and hit the start button, therefore the start menu appears.
However if I try to click on the camera application, it doesn't have any effect!
Actually if I click somewhere else than the on-screen camera button, it should still react to the click: the little cross should move to the clicked place as part of the Touch Focus feature of HTC's camera app.
But here again, nothing happen.
Since it's my first app on WiMo, I might have done a mistake somewhere, but I can't see where.
Any XDA-developer can spot what's wrong with my code?
please see http://forum.xda-developers.com/showthread.php?t=471321
The Problem is the HTC Application, it blocks any keydown event
I did it Application released soon!
http://www.scilor.com/leocameraanykey.html

[Q] HW Button, Finger Gesture, Bluetooth & input panel for HTC HD2

Help...!! I'm new with WM developing,
There are 4 questions I'm about to ask about HTC HD2 using WM6.5:
1. How to disable hardware function and handle their event 'on press' for every HW button (such as Home, Window, Talk, End and Back button)?
So far, I just able to disable it using :
[DllImport("coredll.dll")]
private static extern bool UnregisterFunc1(KeyModifiers modifiers, int keyID);
[DllImport("coredll.dll", SetLastError = true)]
public static extern bool RegisterHotKey(IntPtr hWnd, // handle to window
int id, // hot key identifier
KeyModifiers Modifiers, // key-modifier options
int key //virtual-key code
);
Buttons that I can successfully disable are Volume Up, Volume Down, Back, and Talk.
There is no way I can handle or disable Windows, Home and end button.
I have a trick by disable Window button:
IntPtr hTaskBar = FindWindow("HHTaskBar", null);
EnableWindow(hTaskBar, false);
But when I try to lock and unlock the screen using end button, Window button function will not disable anymore.
So far, some forums mention about SHCMBM_OVERRIDEKEY and handle the message by using Microsoft.WindowsCE.Forms.MessageWindow,
and again I still don't know how to attach MessageWindow to my foreground application
2. I'd like if my panel finger gesture behavior works as well as ListView or DataGrid. So, I found a library that can help me.
code.msdn.microsoft.com/gestureswm/Release/ProjectReleases.aspx?ReleaseId=3146
Unfortunatelly, it makes my controls in panel flicker badly. Do you have any other alternative?
3. To handle bluetooth, I'm using
[DllImport("BthUtil.dll")]
public static extern int BthGetMode(out BluetoothMode dwMode);
[DllImport("BthUtil.dll")]
public static extern int BthSetMode(BluetoothMode dwMode);
and InTheHand.Net Library to send data.
But since I'm starting with this device, I even cannot deactive the Bluetooth.
Can you help me with this Bluetooth control and data communication?
4. Since I'm using virtual keyboard as my input, How to define what kind of input panel it will show?
For Example, if my Textbox1 is focused, I have to show Numeric Keypad.
But if Textbox2 is focused, I have to show Qwerty keyboard.
Thank you very much.
PS : I'm using C# for developing the application. It'll be very good if you give me a C# example for those questions.
I know this is a few months old, and I don't wanna ressurect it per-say - and i'm not farmiliar with the rules as it relates to posting on these forums, but i've been viewing them forever, and as a member for a few months at least, and i've got to say that disabling the END key is a must for the HTC HD2, especially for Android NAND. At present with my phone, and thousands of others, everytime we press the END button, the screen stops being responsive. Funny thing is, if i NEVER press the end button, my screen works great. I end calls using the screen, and i've installed 'Button Saviour' from the market to use the 'END' button virtually on-screen, and I wake the phone using any of the other 4 buttons, save for 'END', and i get no problems. It's the Damned signal sent to the screen from the END button that causes the screen to disable and never re-enable the digitizer - I am just supposing these things, I'm in no way or shape a developer... Just something to think about?
This could be the end to thousands of HTC HD2 end user issues relating to lockscreen lock up in Android or otherwise...

MotionEvent.ACTION_CANCEL is blocking subsequent ACTION_UP on my button

Hey guys,
I am not getting any response on Stack Overflow so I thought I would try here.
At this point I am suspicious that it is a Samsung device specific problem. A very basic app with just a single button produces the same issue on my S4 development device.
Here is me SO question:
I have a button on one of my fragments, that sits inside a relative layout.
It's a rather large button, and when I fat finger it I get a ACTION_CANCEL motion event rather than ACTION_DOWN (it works perfectly fine with finger tips). This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail.
Here is my onTouch implementation:
Code:
@Override
public boolean onTouch(View view, MotionEvent event) {
//debugging
Log.v("TOUCH EVENT", event.toString());
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mButton.getParent().requestDisallowInterceptTouchEvent(true);
//Do stuff...
return true;
} else if (action == MotionEvent.ACTION_UP) {
//Do other stuff...
return true;
} else if (action == MotionEvent.ACTION_CANCEL){
return false;
//Toast.makeText(context, "Your thumb is too fat.", Toast.LENGTH_SHORT).show();
}
return false;
}
Note that the button also uses custom background resources. I start an AsyncTask when the button is pressed and the background changes based on the progress of that task. I'm not sure if that has anything to do with the problem or not.
EDIT: I walked all the way up the View hierarchy to ViewRootImpl, and still no luck in calling requestDisallowInterceptTouchEvent() on it. Weird thing is this shows in the log when my button sticks:
Code:
08-26 11:06:15.287: D/ViewRootImpl(5428): [ViewRootImpl] action cancel - 1, s:31 s(atmel):-1.0 eccen:1.3333334
So obviously it seems that the action is either being cancelled before it even gets inside the ViewRootImpl or right after. How is this even possible?
Update: Still no progress on this... anyone?
masterjeff said:
Hey guys,
I am not getting any response on Stack Overflow so I thought I would try here.
At this point I am suspicious that it is a Samsung device specific problem. A very basic app with just a single button produces the same issue on my S4 development device.
Here is me SO question:
I have a button on one of my fragments, that sits inside a relative layout.
It's a rather large button, and when I fat finger it I get a ACTION_CANCEL motion event rather than ACTION_DOWN (it works perfectly fine with finger tips). This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail.
Here is my onTouch implementation:
Code:
@Override
public boolean onTouch(View view, MotionEvent event) {
//debugging
Log.v("TOUCH EVENT", event.toString());
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mButton.getParent().requestDisallowInterceptTouchEvent(true);
//Do stuff...
return true;
} else if (action == MotionEvent.ACTION_UP) {
//Do other stuff...
return true;
} else if (action == MotionEvent.ACTION_CANCEL){
return false;
//Toast.makeText(context, "Your thumb is too fat.", Toast.LENGTH_SHORT).show();
}
return false;
}
Note that the button also uses custom background resources. I start an AsyncTask when the button is pressed and the background changes based on the progress of that task. I'm not sure if that has anything to do with the problem or not.
EDIT: I walked all the way up the View hierarchy to ViewRootImpl, and still no luck in calling requestDisallowInterceptTouchEvent() on it. Weird thing is this shows in the log when my button sticks:
Code:
08-26 11:06:15.287: D/ViewRootImpl(5428): [ViewRootImpl] action cancel - 1, s:31 s(atmel):-1.0 eccen:1.3333334
So obviously it seems that the action is either being cancelled before it even gets inside the ViewRootImpl or right after. How is this even possible?
Update: Still no progress on this... anyone?
Click to expand...
Click to collapse
Mmmh strange problem you've got there... Just an idea, maybe try to always return true in your onTouchEvent() method since you may be losing the event when an ACTION_MOVE event comes up and you return false. Other than that, could you show us your layout file? I doubt the change in background color has any effect on this, but it could be that some part of your layout is causing this.
SimplicityApks said:
Mmmh strange problem you've got there... Just an idea, maybe try to always return true in your onTouchEvent() method since you may be losing the event when an ACTION_MOVE event comes up and you return false. Other than that, could you show us your layout file? I doubt the change in background color has any effect on this, but it could be that some part of your layout is causing this.
Click to expand...
Click to collapse
Does anyone have a solution to this yet? More specifically, I think it's the Samsung's own implementation of ViewRootImpl that is causing this problem. I've been trying to figure out for a long time how to either pre-empt ViewRootImpl to intercept MotionEvents, or completely override ViewRootImpl. I found no success in either of these.
I also thought about reading from /dev/input/eventX directly, but this isn't feasible since it requires the phone to be rooted first. For myself it's ok, but if I'm writing an app for other devices that's not a solution.
Can someone from Samsung help?

Categories

Resources