Skip to content

Instantly share code, notes, and snippets.

@AVapps
Last active November 30, 2018 22:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save AVapps/473dd8c45690863952dd to your computer and use it in GitHub Desktop.
Save AVapps/473dd8c45690863952dd 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. Wiimote 1 maps to vJoy 2, etc... because vJoy does not work on my windows install...
"""
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, 7 buttons (or keep your wiimote + nunchuck virtual joysticks configuration).
version: 1.0
author: Jahdrien
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)
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, 9 buttons and 1 "Continuous" POV
version: 1.0
author: Jahdrien
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)
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, 9 buttons and 1 "4 Directions" POV
version: 1.0
author: Jahdrien
gist: https://gist.github.com/Jahdrien/473dd8c45690863952dd
"""
def map_pov(n):
if wiimote[n].buttons.button_down(WiimoteButtons.DPadUp):
vJoy[n+1].setDigitalPov(0, VJoyPov.Up)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadDown):
vJoy[n+1].setDigitalPov(0, VJoyPov.Down)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadLeft):
vJoy[n+1].setDigitalPov(0, VJoyPov.Left)
elif wiimote[n].buttons.button_down(WiimoteButtons.DPadRight):
vJoy[n+1].setDigitalPov(0, VJoyPov.Right)
else:
vJoy[n+1].setDigitalPov(0, VJoyPov.Nil)
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)
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
@cjonasw
Copy link

cjonasw commented Jun 3, 2015

Hey! I'm getting "Maximum buttons are -1. You need to incrase number of buttons in vJoy config"

Did you encounter this?

@nerdshowandtell
Copy link

I think there is an error in the wiimote+nunchuck_to_vJoy_analog_pov.py script. vJoy uses -1 for the neutral position of the POV. So in map_pov() when at rest val should be -1, not maxVal.. Initial val should also be -1 not 0. 0 should only be used when the dpad is being pushed UP.

@X-Raym
Copy link

X-Raym commented Feb 5, 2016

Thanks for sharing, it was very helpful !

@gggiovanny
Copy link

Thanks! You help me lots, there's no many good freepie scrips around, and the last one is perfect to play Ocarina of Time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment