Sorry, clicked SEND too soon. :) Chris said this:
For simple vibration, I personally think that using the QML wrappers is still
the easiest. For example:

import QtQml 2.0
import QtFeedback 5.0

QtObject {
id: root

property ThemeEffect buttonBuzz: ThemeEffect {
effect: ThemeEffect.Press
}

property HapticsEffect customBuzz: HapticsEffect {
attackTime: 500
fadeTime: 500
attackIntensity: 0.2
fadeIntensity: 0.01
intensity: 0.8
duration: 1000
onStateChanged: {
if (state == FeedbackEffect.Stopped) {
Qt.quit()
}
}
}

Component.onCompleted: customBuzz.start() // or: { buttonBuzz.play(); 
Qt.quit(); }
}

Run that with /usr/lib/qt5/bin/qmlscene and you'll get a nice buzz.
Note that the automatic quit won't work until:
https://github.com/nemomobile/qt-mobility-haptics-ffmemless/pull/6

is integrated and released - a bug I only noticed today when testing
thanks to your email!

Cheers,
Chris.
From: dr...@hotmail.com
To: devel@lists.sailfishos.org
Date: Mon, 24 Feb 2014 02:21:37 +0000
Subject: [SailfishDevel] how to activate vibration actuator




I asked this question in the DL a while ago and didn't get a reply (did get 
some helpful pointers).
I finally have the code to do this. Adapted from 
https://github.com/nemomobile/qt-mobility-haptics-ffmemlessChris Adams was also 
kind enough to say this
#include <QCoreApplication>#include <QTimer>#include <QDebug>
#include <linux/input.h>#include <sys/types.h>#include <sys/stat.h>#include 
<fcntl.h>
#define BITS_PER_LONG (sizeof(long) * 8)#define OFF(x)  
((x)%BITS_PER_LONG)#define BIT(x)  (1UL<<OFF(x))#define LONG(x) 
((x)/BITS_PER_LONG)#define test_bit(bit, array)    ((array[LONG(bit)] >> 
OFF(bit)) & 1)
#define ACTUATOR_SPIN_UP 2#define ACTUATOR_SPIN_DOWN 4#define 
ACTUATOR_RUMBLE_MIN 8191#define ACTUATOR_RUMBLE_MAX 32767#define 
ACTUATOR_MAGNITUDE_MAX 16000#define ACTUATOR_MAGNITUDE_MEAN 12000#define 
LONG_PRESS_DURATION 77#define LONG_PRESS_DELAY 4#define LONG_PRESS_MAX 
16384#define LONG_PRESS_MIN 8191#define BUTTON_PRESS_DURATION 14#define 
BUTTON_PRESS_DELAY 4#define BUTTON_PRESS_MAX 24576#define BUTTON_PRESS_MIN 
20478#define KEYPAD_PRESS_DURATION 6#define KEYPAD_PRESS_DELAY 4#define 
KEYPAD_PRESS_MAX 32767#define KEYPAD_PRESS_MIN 32767
int vibra_evdev_file_search(bool *supportsRumble, bool *supportsPeriodic){    
int i = 0;    int fp = 1;    char device_file_name[24];    unsigned long 
features[4];
    /* fail safe stop at 256 devices */    while (fp && i < 256) {        
sprintf(device_file_name, "/dev/input/event%d", i);        fp = 
open(device_file_name, O_RDWR);        if (fp == -1) {            qDebug() << 
"Unable to open input file";            break;        }
        if (ioctl(fp, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features) < 
0) {            qDebug() << "Ioctl query failed";            close(fp);         
   i++;            continue;        }
        *supportsRumble = false;        *supportsPeriodic = false;        if 
(test_bit(FF_RUMBLE, features))            *supportsRumble = true;        if 
(test_bit(FF_PERIODIC, features))            *supportsPeriodic = true;        
if (*supportsRumble || *supportsPeriodic)            return fp;
        close(fp);        i++;    }
    return -1;}
Q_DECL_EXPORT int main(int argc, char *argv[]){    QCoreApplication a(argc, 
argv);
    struct ff_effect m_themeEffect, m_customHapticEffect;
    bool supportsRumble = false, supportsPeriodic = false;    int 
m_vibraSpiDevice = -1;
    //Initialize effects    m_themeEffect.type = FF_RUMBLE;    m_themeEffect.id 
= 1;    m_themeEffect.u.rumble.strong_magnitude = KEYPAD_PRESS_MAX;    
m_themeEffect.u.rumble.weak_magnitude = KEYPAD_PRESS_MIN;    
m_themeEffect.replay.length = KEYPAD_PRESS_DURATION;    
m_themeEffect.replay.delay = KEYPAD_PRESS_DELAY;
    m_customHapticEffect.type = FF_RUMBLE;    m_customHapticEffect.id = 2;    
m_customHapticEffect.u.rumble.strong_magnitude = ACTUATOR_RUMBLE_MAX;    
m_customHapticEffect.u.rumble.weak_magnitude = ACTUATOR_RUMBLE_MIN;    
m_customHapticEffect.replay.length = 100 + ACTUATOR_SPIN_UP;    
m_customHapticEffect.replay.delay = ACTUATOR_SPIN_DOWN;
    m_vibraSpiDevice = vibra_evdev_file_search(&supportsRumble, 
&supportsPeriodic);
    qDebug() << "Supports Rumble: " << supportsRumble;    qDebug() << "Supports 
Periodic: " << supportsPeriodic;
    struct input_event playEvent;    playEvent.type = EV_FF;    playEvent.code 
= 1;    playEvent.value = 1;    {        // Write effect and let the device 
rumble        int writeRetn = write(m_vibraSpiDevice, (const void*) &playEvent, 
sizeof(playEvent));        if (writeRetn == -1) {            qDebug() << 
"Unable to write event to effect";        }        QEventLoop loop;        
QTimer::singleShot(1000, &loop, SLOT(quit()));        loop.exec();    }    
close(m_vibraSpiDevice);
    return 0;}

                                          

_______________________________________________
SailfishOS.org Devel mailing list                                         
_______________________________________________
SailfishOS.org Devel mailing list

Reply via email to