| 1 | import wmplugin |
|---|
| 2 | import cwiid |
|---|
| 3 | import math |
|---|
| 4 | |
|---|
| 5 | Mode = 0 |
|---|
| 6 | Enabled = 0 |
|---|
| 7 | lastCube = 240 |
|---|
| 8 | |
|---|
| 9 | def wmplugin_info(): |
|---|
| 10 | return [], [], \ |
|---|
| 11 | [("Mode", wmplugin.PARAM_INT, Mode), \ |
|---|
| 12 | ("Enabled", wmplugin.PARAM_INT, Enabled), \ |
|---|
| 13 | ] |
|---|
| 14 | |
|---|
| 15 | def 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 | |
|---|
| 27 | def 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 [], [] |
|---|