Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Forked from AVapps/horizontal_wiimote_to_vJoy.py
Last active March 1, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save X-Raym/caada7ebc4b76fb01dcd to your computer and use it in GitHub Desktop.
Save X-Raym/caada7ebc4b76fb01dcd to your computer and use it in GitHub Desktop.
FreePIE script to use up tu 4 wiimotes and nunchucks with vJoy. Configure your virtual joysticks with x and y axis, 1 "4 directions" POV and 9 buttons.
"""
Horizontal Wiimote to vJoy FreePIE script
Maps up to 4 wiimotes to 4 virtual joysticks using vJoy.
Before running this script define 4 virtual joysticks with x and y axis, 13 buttons (or keep your wiimote + nunchuck virtual joysticks configuration).
version: 1.1
author: Jahdrien
mod: X-Raym
gist: https://gist.github.com/X-Raym/caada7ebc4b76fb01dcd
source gist: https://gist.github.com/Jahdrien/473dd8c45690863952dd
"""
def map_pov(n):
if wiimote[n].buttons.button_down(WiimoteButtons.DPadUp):
vJoy[n+1].x = -vJoy[n+1].axisMax
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadDown):
vJoy[n+1].x = vJoy[n+1].axisMax
else:
vJoy[n+1].x = 0
if wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
vJoy[n+1].y = vJoy[n+1].axisMax
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadRight):
vJoy[n+1].y = -vJoy[n+1].axisMax
else:
vJoy[n+1].y = 0
def map_button(n, wiimote_button, vjoy_button):
vJoy[n+1].setButton(vjoy_button, wiimote[n].buttons.button_down(wiimote_button))
def map_buttons(n):
map_button(n, WiimoteButtons.A, 0)
map_button(n, WiimoteButtons.B, 1)
map_button(n, WiimoteButtons.One, 2)
map_button(n, WiimoteButtons.Two, 3)
map_button(n, WiimoteButtons.Minus, 4)
map_button(n, WiimoteButtons.Plus, 5)
map_button(n, WiimoteButtons.Home, 6)
map_button(n, WiimoteButtons.DPadUp, 9)
map_button(n, WiimoteButtons.DPadDown, 10)
map_button(n, WiimoteButtons.DPadLeft, 11)
map_button(n, WiimoteButtons.DPadRight, 12)
def updateWiimote1():
# Wiimote 1
map_buttons(0)
map_pov(0)
def updateWiimote2():
# Wiimote 2
map_buttons(1)
map_pov(1)
def updateWiimote3():
# Wiimote 3
map_buttons(2)
map_pov(2)
def updateWiimote4():
# Wiimote 4
map_buttons(3)
map_pov(3)
# If we're starting up, then hook up our update function.
if starting:
wiimote[0].buttons.update += updateWiimote1
wiimote[1].buttons.update += updateWiimote2
wiimote[2].buttons.update += updateWiimote3
wiimote[3].buttons.update += updateWiimote4
"""
Wiimote + Nunchuck to vJoy FreePIE script (Analog/Continuous POV)
Maps up to 4 wiimotes with nunchucks to 4 virtual joysticks using vJoy.
Before running this script define 4 virtual joysticks with x and y axis, 13 buttons and 1 "Continuous" POV
version: 1.1
author: Jahdrien
mod: X-Raym
gist: https://gist.github.com/X-Raym/caada7ebc4b76fb01dcd
source gist: https://gist.github.com/Jahdrien/473dd8c45690863952dd
"""
def map_pov(n):
val = 0
maxVal = vJoy[n+1].continuousPovMax
if wiimote[n].buttons.button_down(WiimoteButtons.DPadUp):
val = 0 # UP
if wiimote[n].buttons.button_down(WiimoteButtons.DPadRight):
val += maxVal/8 # UP/RIGHT
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
val = 7 * maxVal/8 # UP/LEFT
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadRight):
val = maxVal/4 # RIGHT
if wiimote[n].buttons.button_down(WiimoteButtons.DPadDown):
val += maxVal/8 # DOWN/RIGHT
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadDown):
val = maxVal/2 # DOWN
if wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
val += maxVal/8 # DOWN/LEFT
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
val = 3 * maxVal/4 # LEFT
else:
val = maxVal
vJoy[n+1].setAnalogPov(0, val)
def map_axis(n):
vJoy[n+1].x = filters.mapRange(filters.deadband(wiimote[n].nunchuck.stick.x, 5), -95, 95, -vJoy[n+1].axisMax, vJoy[n+1].axisMax)
vJoy[n+1].y = -filters.mapRange(filters.deadband(wiimote[n].nunchuck.stick.y, 5), -95, 95, -vJoy[n+1].axisMax, vJoy[n+1].axisMax)
def map_button(n, wiimote_button, vjoy_button):
vJoy[n+1].setButton(vjoy_button, wiimote[n].buttons.button_down(wiimote_button))
def map_nunchuck_button(n, nunchuck_button, vjoy_button):
vJoy[n+1].setButton(vjoy_button, wiimote[n].nunchuck.buttons.button_down(nunchuck_button))
def map_buttons(n):
map_button(n, WiimoteButtons.A, 0)
map_button(n, WiimoteButtons.B, 1)
map_button(n, WiimoteButtons.One, 2)
map_button(n, WiimoteButtons.Two, 3)
map_button(n, WiimoteButtons.Minus, 4)
map_button(n, WiimoteButtons.Plus, 5)
map_button(n, WiimoteButtons.Home, 6)
map_button(n, WiimoteButtons.DPadUp, 9)
map_button(n, WiimoteButtons.DPadDown, 10)
map_button(n, WiimoteButtons.DPadLeft, 11)
map_button(n, WiimoteButtons.DPadRight, 12)
def map_nunchuck_buttons(n):
map_nunchuck_button(n, NunchuckButtons.C, 7)
map_nunchuck_button(n, NunchuckButtons.Z, 8)
def updateWiimote1():
# Wiimote 1
map_buttons(0)
map_pov(0)
def updateNunchuck1():
map_axis(0)
map_nunchuck_buttons(0)
def updateWiimote2():
# Wiimote 2
map_buttons(1)
map_pov(1)
def updateNunchuck2():
map_axis(1)
map_nunchuck_buttons(1)
def updateWiimote3():
# Wiimote 3
map_buttons(2)
map_pov(2)
def updateNunchuck3():
map_axis(2)
map_nunchuck_buttons(2)
def updateWiimote4():
# Wiimote 4
map_buttons(3)
map_pov(3)
def updateNunchuck4():
map_axis(3)
map_nunchuck_buttons(3)
# If we're starting up, then hook up our update function.
if starting:
wiimote[0].buttons.update += updateWiimote1
wiimote[1].buttons.update += updateWiimote2
wiimote[2].buttons.update += updateWiimote3
wiimote[3].buttons.update += updateWiimote4
wiimote[0].nunchuck.update += updateNunchuck1
wiimote[1].nunchuck.update += updateNunchuck2
wiimote[2].nunchuck.update += updateNunchuck3
wiimote[3].nunchuck.update += updateNunchuck4
"""
Wiimote + Nunchuck to vJoy FreePIE script (4 Directions POV)
Maps up to 4 wiimotes with nunchucks to 4 virtual joysticks using vJoy.
Before running this script define 4 virtual joysticks with x and y axis, 13 buttons and 1 "4 Directions" POV
version: 1.1
author: Jahdrien
mod: X-Raym
gist: https://gist.github.com/X-Raym/caada7ebc4b76fb01dcd
source gist: https://gist.github.com/Jahdrien/473dd8c45690863952dd
"""
def map_pov(n):
if wiimote[n].buttons.button_down(WiimoteButtons.DPadUp):
vJoy[n].setDigitalPov(0, VJoyPov.Up)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadDown):
vJoy[n].setDigitalPov(0, VJoyPov.Down)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
vJoy[n].setDigitalPov(0, VJoyPov.Left)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadRight):
vJoy[n].setDigitalPov(0, VJoyPov.Right)
else:
vJoy[n].setDigitalPov(0, VJoyPov.Nil)
def map_axis(n):
vJoy[n].x = filters.mapRange(filters.deadband(wiimote[n].nunchuck.stick.x, 5), -95, 95, -vJoy[n+1].axisMax, vJoy[n+1].axisMax)
vJoy[n].y = -filters.mapRange(filters.deadband(wiimote[n].nunchuck.stick.y, 5), -95, 95, -vJoy[n+1].axisMax, vJoy[n+1].axisMax)
def map_button(n, wiimote_button, vjoy_button):
vJoy[n].setButton(vjoy_button, wiimote[n].buttons.button_down(wiimote_button))
def map_nunchuck_button(n, nunchuck_button, vjoy_button):
vJoy[n].setButton(vjoy_button, wiimote[n].nunchuck.buttons.button_down(nunchuck_button))
def map_buttons(n):
map_button(n, WiimoteButtons.A, 0)
map_button(n, WiimoteButtons.B, 1)
map_button(n, WiimoteButtons.One, 2)
map_button(n, WiimoteButtons.Two, 3)
map_button(n, WiimoteButtons.Minus, 4)
map_button(n, WiimoteButtons.Plus, 5)
map_button(n, WiimoteButtons.Home, 6)
map_button(n, WiimoteButtons.DPadUp, 9)
map_button(n, WiimoteButtons.DPadDown, 10)
map_button(n, WiimoteButtons.DPadLeft, 11)
map_button(n, WiimoteButtons.DPadRight, 12)
def map_nunchuck_buttons(n):
map_nunchuck_button(n, NunchuckButtons.C, 7)
map_nunchuck_button(n, NunchuckButtons.Z, 8)
def updateWiimote1():
# Wiimote 1
map_buttons(0)
map_pov(0)
def updateNunchuck1():
map_axis(0)
map_nunchuck_buttons(0)
def updateWiimote2():
# Wiimote 2
map_buttons(1)
map_pov(1)
def updateNunchuck2():
map_axis(1)
map_nunchuck_buttons(1)
def updateWiimote3():
# Wiimote 3
map_buttons(2)
map_pov(2)
def updateNunchuck3():
map_axis(2)
map_nunchuck_buttons(2)
def updateWiimote4():
# Wiimote 4
map_buttons(3)
map_pov(3)
def updateNunchuck4():
map_axis(3)
map_nunchuck_buttons(3)
# If we're starting up, then hook up our update function.
if starting:
wiimote[0].buttons.update += updateWiimote1
wiimote[1].buttons.update += updateWiimote2
wiimote[2].buttons.update += updateWiimote3
wiimote[3].buttons.update += updateWiimote4
wiimote[0].nunchuck.update += updateNunchuck1
wiimote[1].nunchuck.update += updateNunchuck2
wiimote[2].nunchuck.update += updateNunchuck3
wiimote[3].nunchuck.update += updateNunchuck4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment