March 21, 2012

owenzhao owenzhao
Lab Rat
61 posts

[Solved] qtMobility.feedback HapticsEffect does not do what I want

 

I want to get 30 seconds vibration like what a call is coming does.
My code is

  1. import QtQuick 1.1
  2. import com.nokia.symbian 1.1
  3. import QtMobility.feedback 1.1
  4.  
  5. Page {
  6.     id: mainPage
  7.     Text {
  8.         id:helloWordText
  9.         anchors.centerIn: parent
  10.         text: qsTr("Hello world!")
  11.         color: platformStyle.colorNormalLight
  12.         font.pixelSize: 20
  13.     }
  14.  
  15.     Button {
  16.         anchors.horizontalCenter: parent.horizontalCenter
  17.         anchors.top: helloWordText.bottom
  18.         text: qsTr("Vibration")
  19.         HapticsEffect {
  20.             id: rumbleEffect
  21.  
  22.             intensity: 1.0
  23.             duration: 30000
  24.  
  25.         }
  26.         MouseArea {
  27.             onClicked: {
  28.             rumbleEffect.start();  // plays a rumble effect
  29.             }
  30.         }
  31.     }
  32. }

And my .pro file is

  1. # Add more folders to ship with the application, here
  2. folder_01.source = qml/testOfVibration
  3. folder_01.target = qml
  4. DEPLOYMENTFOLDERS = folder_01
  5.  
  6. # Additional import path used to resolve QML modules in Creator's code model
  7. QML_IMPORT_PATH =
  8.  
  9. symbian:TARGET.UID3 = 0xE335C713
  10.  
  11. # Smart Installer package's UID
  12. # This UID is from the protected range and therefore the package will
  13. # fail to install if self-signed. By default qmake uses the unprotected
  14. # range value if unprotected UID is defined for the application and
  15. # 0x2002CCCF value if protected UID is given to the application
  16. #symbian:DEPLOYMENT.installer_header = 0x2002CCCF
  17.  
  18. # Allow network access on Symbian
  19. symbian:TARGET.CAPABILITY += NetworkServices
  20.  
  21. # If your application uses the Qt Mobility libraries, uncomment the following
  22. # lines and add the respective components to the MOBILITY variable.
  23. # CONFIG += mobility
  24. # MOBILITY +=
  25.  
  26. # Speed up launching on MeeGo/Harmattan when using applauncherd daemon
  27. # CONFIG += qdeclarative-boostable
  28.  
  29. # Add dependency to Symbian components
  30. CONFIG += qt-components
  31. CONFIG += mobility
  32. MOBILITY = feedback
  33.  
  34. # The .cpp file which was generated for your project. Feel free to hack it.
  35. SOURCES += main.cpp
  36.  
  37. # Please do not modify the following two lines. Required for deployment.
  38. include(qmlapplicationviewer/qmlapplicationviewer.pri)
  39. qtcAddDeployment()

However, what I get is, when I press the button, the phone will vibrate, but only for a very small period of time, something like when you type in the native virtual keyboard. I have set duration to 30 seconds, but it does work. Anyone know why?

Thank you.

5 replies

March 22, 2012

Damian Jansen Damian Jansen
Lab Rat
18 posts

You may be exceeding the maximum time for an effect. I don’t recall exactly how it works for Symbian, but it may be defaulting to a small number and discarding the 300000.
Try three seconds and if that works, then that’s likely the issue.

 Signature 

QtQuick Quality Engineer / Lab Monkey
Nokia Brisbane

March 22, 2012

owenzhao owenzhao
Lab Rat
61 posts

Then what should I do if I want to do a 30 seconds vibration? The feedback api is not fit for me? Is there any other api can do this?

March 22, 2012

Damian Jansen Damian Jansen
Lab Rat
18 posts

Here’s the docs on Symbian Haptics.
http://library.developer.nokia.com/topic/GUID-E35887BB-7E58-438C-AA27-97B2CDE7E069/GUID-251A35C1-CC66-4DE4-9EBE-964026E89E7F/GUID-2D2EBEA7-4E61-30AF-A09A-153F4C55BB53.html

The part of interest is

  1. Duration of the effect. Unit is milliseconds.
  2.  
  3. To specify an infinite duration, the effect duration should be set to InfiniteDuration(). For a finite duration, the effect duration is clamped to a value from 0 to the value returned by GetDeviceCapability() for the EHWRMHapticsMaxEffectDuration capability type.

Both the Symbian and Qt docs suggest that an infinite value can be used for an ongoing effect, so try:

  1.   HapticsEffect {
  2.       id: rumbleEffect
  3.       intensity: 1.0
  4.       duration: Feedback.Infinite
  5.       Timer { id: stoptimer; interval: 30000; onTriggered: rumbleEffect.stop() }
  6.   }
  7.   MouseArea {
  8.       onClicked: {
  9.           rumbleEffect.start();  // plays a rumble effect
  10.           stoptimer.restart();   // Kill after 30s if not re-fired
  11.       }
  12.   }

using a Timer to control the stop() behaviour.

Otherwise, if the above fails, you would likely need to fire off in succession enough HapticsEffect loops to get the vibration time you want.
Unfortunately it seems the API is unable to give you that magic duration – and chances are it’s device specific. Choosing a small number, e.g. 2000ms and repeating that might be ok.

 Signature 

QtQuick Quality Engineer / Lab Monkey
Nokia Brisbane

March 23, 2012

owenzhao owenzhao
Lab Rat
61 posts

The duration is an int property. So I get the error here:“duration: Feedback.Infinite”

  1. Unable to assign [undefined] to int duration

But the vibration this time is much stronger.

March 24, 2012

owenzhao owenzhao
Lab Rat
61 posts

I find a project for this.
here.QVibra
www.developer.nokia.com/Community/Wiki/How_to_use_QVibra_to_enable_vibration_in_QML

 
  ‹‹ [SOLVED] Iteration of QML elements      QML QtWebKit flickable... ››

You must log in to post a reply. Not a member yet? Register here!