Forum Archive

Vibrate module

userista

if possible I would like to request vibrate module - would be nice for games etc.

omz

It's relatively easy to trigger a simple vibration using ctypes, but there's no API to control the duration, intensity etc.

import ctypes
import time
c = ctypes.CDLL(None)

def vibrate():
    p = c.AudioServicesPlaySystemSound
    p.restype, p.argtypes = None, [ctypes.c_int32]
    vibrate_id = 0x00000fff
    p(vibrate_id)

if __name__ == '__main__':
    for i in xrange(3):
        vibrate()
        time.sleep(0.5)
userista

Sweet! That's perfect for my use case.

Webmaster4o

Is this now easier with objc_util?

JonB

Pure c calls are basically the same with or without objc. Since the vibrate api is pure c, and not part of an objc class, the code would be the same.

Webmaster4o

Ok, just wondering. Thanks.

dream945

@omz Thank you for your Vibrate module.
The process went successfully when done according to your instructions.
At a time such as when you are on the phone and the alarm goes off, can it vibrate for a long time?
Objective-C seems to write in this way.
http://stackoverflow.com/questions/1490028/iphone-dev-performselectorwithobjectafterdelay-or-nstimer