Ticket #65: rumble.py

File rumble.py, 1.0 KB (added by nickishappy, 5 years ago)

A Rumble Plugin for wminput. Mode 2 doesn't work that great, but it does work.

Line 
1import wmplugin
2import cwiid
3import math
4
5Mode = 0
6Enabled = 0
7lastCube = 240
8
9def wmplugin_info():
10        return [], [], \
11          [("Mode", wmplugin.PARAM_INT, Mode), \
12           ("Enabled", wmplugin.PARAM_INT, Enabled), \
13           ]
14
15def wmplugin_init(id, wiimote_arg):
16        global wiimote
17       
18        wiimote = wiimote_arg
19
20        if Mode == 1:
21                wmplugin.set_rpt_mode(id, cwiid.RPT_BTN)
22        elif Mode == 2: 
23                wmplugin.set_rpt_mode(id, cwiid.RPT_ACC)
24
25        return
26
27def wmplugin_exec(mesg):
28        global wiimote
29        global lastCube
30
31        if Enabled:
32                for m in mesg:
33                        if m[0] == cwiid.MESG_BTN and Mode == 1:
34                                if wiimote.state['rumble'] == 0:
35                                        wiimote.rumble = 1
36                                else:
37                                        wiimote.rumble = 0
38                       
39                        elif m[0] == cwiid.MESG_ACC and Mode == 2:
40                                acc = wiimote.state['acc']
41                                cube = math.sqrt(acc[0]**2 + acc[1]**2 + acc[2]**2 - 1)
42
43                                if cube > 240:
44                                        wiimote.rumble = 1
45                                        lastCube = cube
46                                elif cube < (lastCube - 30): #If rumble is toggled to fast,
47                                        wiimote.rumble = 0   #it screws with data transfers
48
49        return [], []