Help with Wii Remote to vJoy mapping

Official forum for open source FreePIE discussion and development.
Post Reply
Polite Master
One Eyed Hopeful
Posts: 4
Joined: Fri Sep 18, 2015 3:56 am

Help with Wii Remote to vJoy mapping

Post by Polite Master »

Hello FreePIE Community,

I am trying to write a script that maps Wii Remote (no Nunchuck) buttons to vJoy virtual buttons. It involves reserving the A and B buttons as toggles to switch mappings (of just the Wii Remote's One and Two buttons, at the moment). Everything seems to work save the following problem:

After holding down a toggle, holding down either the One or Two button, and releasing the toggle; the One/Two button will continue to fire after its own release. In order to stop One/Two from firing, a toggle button has to be repressed (or released after the release of One/Two). I would like One/Two to not continuously fire regardless of the button release order. Thank you kindly in advance for your thoughts and comments!

I am running Windows 7 Home Premium SP1 64-bit, FreePIE 1.9.611.0, vJoy 2.0.5-050515 (latest), and the WIDCOMM (Broadcom) Bluetooth Stack 6.5.0.3200 that came with my ASUS Maximus V Formula motherboard and its integrated Bluetooth solution. I am using a RVL-CNT-01 (non -TR), black, Wii MotionPlus Wii Remote. I have tested with ppJoy but only have one of vJoy or ppJoy installed at a given time.

Disclaimer: I am not a programmer nor very knowledgeable about Python.

Code: Select all

#Mapping between a Player 1 Wii Remote and vJoy 2. Requires 15 vJoy buttons.

#No Toggle
def noTogglePair(vJoyButton, WiimoteButton):
	vJoy[1].setButton(vJoyButton, wiimote[0].buttons.button_down(WiimoteButton))

#This mapping will be used when not pressing a toggle.
def noToggleMap():
	noTogglePair(0, WiimoteButtons.DPadUp)
	noTogglePair(1, WiimoteButtons.DPadDown)
	noTogglePair(2, WiimoteButtons.DPadLeft)
	noTogglePair(3, WiimoteButtons.DPadRight)
	noTogglePair(4, WiimoteButtons.A)
	noTogglePair(5, WiimoteButtons.B)
	noTogglePair(6, WiimoteButtons.One)
	noTogglePair(7, WiimoteButtons.Two)
	noTogglePair(8, WiimoteButtons.Minus)
	noTogglePair(9, WiimoteButtons.Plus)
	noTogglePair(10, WiimoteButtons.Home)



#Toggle 1
Toggle1 = WiimoteButtons.A

def Toggle1Pair(vJoyButton, WiimoteButton):
	vJoy[1].setButton(vJoyButton, wiimote[0].buttons.button_down(Toggle1 and WiimoteButton))

#This mapping will be used when holding the above toggle.
def Toggle1Map():
	Toggle1Pair(0, WiimoteButtons.DPadUp)
	Toggle1Pair(1, WiimoteButtons.DPadDown)
	Toggle1Pair(2, WiimoteButtons.DPadLeft)
	Toggle1Pair(3, WiimoteButtons.DPadRight)
	Toggle1Pair(4, WiimoteButtons.A)
	Toggle1Pair(5, WiimoteButtons.B)
	Toggle1Pair(11, WiimoteButtons.One)
	Toggle1Pair(12, WiimoteButtons.Two)
	Toggle1Pair(8, WiimoteButtons.Minus)
	Toggle1Pair(9, WiimoteButtons.Plus)
	Toggle1Pair(10, WiimoteButtons.Home)



#Toggle 2
Toggle2 = WiimoteButtons.B

def Toggle2Pair(vJoyButton, WiimoteButton):
	vJoy[1].setButton(vJoyButton, wiimote[0].buttons.button_down(Toggle2 and WiimoteButton))

#This mapping will be used when holding the above toggle.
def Toggle2Map():
	Toggle2Pair(0, WiimoteButtons.DPadUp)
	Toggle2Pair(1, WiimoteButtons.DPadDown)
	Toggle2Pair(2, WiimoteButtons.DPadLeft)
	Toggle2Pair(3, WiimoteButtons.DPadRight)
	Toggle2Pair(4, WiimoteButtons.A)
	Toggle2Pair(5, WiimoteButtons.B)
	Toggle2Pair(13, WiimoteButtons.One)
	Toggle2Pair(14, WiimoteButtons.Two)
	Toggle2Pair(8, WiimoteButtons.Minus)
	Toggle2Pair(9, WiimoteButtons.Plus)
	Toggle2Pair(10, WiimoteButtons.Home)



#Update subroutine
def updateWiimote():
	if wiimote[0].buttons.button_down(Toggle2):
		Toggle2Map()
	elif wiimote[0].buttons.button_down(Toggle1):
		Toggle1Map()
	else:
		noToggleMap()

#Actually apply update subroutine at start up
if starting:
	wiimote[0].buttons.update += updateWiimote
Last edited by Polite Master on Fri Oct 02, 2015 7:06 am, edited 10 times in total.
Polite Master
One Eyed Hopeful
Posts: 4
Joined: Fri Sep 18, 2015 3:56 am

Re: Help with Wii Remote to vJoy mapping

Post by Polite Master »

Hello again FreePIE forums,

I am still looking for a solution to the above problem. To restate it in other words, I need a toggle to switch button mappings. I have edited my code above, as I noticed the and booleans were unnecessary.

Code: Select all

#Mapping between a Player 1 Wii Remote and vJoy 2. Requires 15 vJoy buttons.

toggle1 = wiimote[0].buttons.button_down(WiimoteButtons.A)
toggle2 = wiimote[0].buttons.button_down(WiimoteButtons.B)

def pair(vJoyButton, WiimoteButton):
	vJoy[1].setButton(vJoyButton, wiimote[0].buttons.button_down(WiimoteButton))

#This mapping will be used when not pressing a toggle.
def noToggleMap():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(6, WiimoteButtons.One)
	pair(7, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)

#This mapping will be used when holding toggle1.
def toggle1Map():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(11, WiimoteButtons.One)
	pair(12, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)

#This mapping will be used when holding toggle2.
def toggle2Map():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(13, WiimoteButtons.One)
	pair(14, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)

#Update subroutine
def updateWiimote():
	if toggle2:
		toggle2Map()
	elif toggle1:
		toggle1Map()
	else:
		noToggleMap()

#Actually apply update subroutine at start up
if starting:
	wiimote[0].buttons.update += updateWiimote
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with Wii Remote to vJoy mapping

Post by CyberVillain »

I do not know the exact problem but lets say you hold Button X down While pressing ToggleOne now you release ToggleOne and Button X. vjoy will continue send Button X state to the game.
Polite Master
One Eyed Hopeful
Posts: 4
Joined: Fri Sep 18, 2015 3:56 am

Re: Help with Wii Remote to vJoy mapping

Post by Polite Master »

CyberVillain wrote:I do not know the exact problem but lets say you hold Button X down While pressing ToggleOne now you release ToggleOne and Button X. vjoy will continue send Button X state to the game.
Thank you for the reply, CyberVillain. That is correct, and there are two cases. If you release ButtonX and then ToggleOne, both stop firing (desired). Alternatively, if you release ToggleOne and then ButtonX, ButtonX will continue firing until you press ToggleOne again. I have a feeling it is a simple error in my script's logic. I just tried an equivalent conditional statement (to the one under #Update subroutine) in GlovePIE/PPJoy. The same effect occurs. Note that I am testing with Window's Game Controllers UI (C:\Windows\system32\joy.cpl); I've updated my first post with my hardware/software configuration.

GlovePIE script (same problem):

Code: Select all

wiimote1.Led1=true
wiimote1.Led2=false
wiimote1.Led3=false
wiimote1.Led4=false

ppjoy1.Digital0 = wiimote1.Up
ppjoy1.Digital1 = wiimote1.Down
ppjoy1.Digital2 = wiimote1.Left
ppjoy1.Digital3 = wiimote1.Right
ppjoy1.Digital4 = wiimote1.A
ppjoy1.Digital5 = wiimote1.B
//ppjoy1.Digital6 = wiimote1.One
//ppjoy1.Digital7 = wiimote1.Two
ppjoy1.Digital8 = wiimote1.Minus
ppjoy1.Digital9 = wiimote1.Plus
ppjoy1.Digital10 = wiimote1.Home

if HeldDown(wiimote1.A,0.1) {
	ppjoy1.Digital11 = wiimote1.One
	ppjoy1.Digital12 = wiimote1.Two
else if HeldDown(wiimote1.B,0.1)
	ppjoy1.Digital12 = wiimote1.One
	ppjoy1.Digital13 = wiimote1.Two
else
	ppjoy1.Digital6 = wiimote1.One
	ppjoy1.Digital7 = wiimote1.Two
}
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with Wii Remote to vJoy mapping

Post by CyberVillain »

Consider this code

Code: Select all

if starting:
	vJoy[0].setButton(0, True)
jvoy will only receive once that it should press button zero. But it will keep it pressed until you send vJoy[0].setButton(0, False) to it


You need to make sure you send false when you toggle so the button does not stay pressed

Code like this will always work because it will make sure to update vjoy with false when button is not pressed

Code: Select all

vJoy[0].setButton(0, mouse.getButton(0))
Polite Master
One Eyed Hopeful
Posts: 4
Joined: Fri Sep 18, 2015 3:56 am

Re: Help with Wii Remote to vJoy mapping

Post by Polite Master »

Thank you CyberVillain.

I think I found a solution with your help. I am not sure it is exactly what you suggested, but I used

Code: Select all

vJoy[1].setButton(vJoyButton, False)
four times in each map to explicitly make the unnecessary vJoy buttons false when holding a given toggle. The code is not concise because it goes though each possibility; however, it seems to work well.



You are much appreciated,

Polite Master

Updated script:

Code: Select all

#Mapping between a Player 1 Wii Remote and vJoy 2. Requires 15 vJoy buttons.

toggle1 = wiimote[0].buttons.button_down(WiimoteButtons.A)
toggle2 = wiimote[0].buttons.button_down(WiimoteButtons.B)

def pair(vJoyButton, WiimoteButton):
	vJoy[1].setButton(vJoyButton, wiimote[0].buttons.button_down(WiimoteButton))

#This mapping will be used when not pressing a toggle.
def noToggleMap():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(6, WiimoteButtons.One)
	pair(7, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)
	vJoy[1].setButton(11, False)
	vJoy[1].setButton(12, False)
	vJoy[1].setButton(13, False)
	vJoy[1].setButton(14, False)

#This mapping will be used when holding toggle1.
def toggle1Map():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(11, WiimoteButtons.One)
	pair(12, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)
	vJoy[1].setButton(6, False)
	vJoy[1].setButton(7, False)
	vJoy[1].setButton(13, False)
	vJoy[1].setButton(14, False)

#This mapping will be used when holding toggle2.
def toggle2Map():
	pair(0, WiimoteButtons.DPadUp)
	pair(1, WiimoteButtons.DPadDown)
	pair(2, WiimoteButtons.DPadLeft)
	pair(3, WiimoteButtons.DPadRight)
	pair(4, WiimoteButtons.A)
	pair(5, WiimoteButtons.B)
	pair(13, WiimoteButtons.One)
	pair(14, WiimoteButtons.Two)
	pair(8, WiimoteButtons.Minus)
	pair(9, WiimoteButtons.Plus)
	pair(10, WiimoteButtons.Home)
	vJoy[1].setButton(6, False)
	vJoy[1].setButton(7, False)
	vJoy[1].setButton(11, False)
	vJoy[1].setButton(12, False)

#Update subroutine
def updateWiimote():
	if toggle2:
		toggle2Map()
	elif toggle1:
		toggle1Map()
	else:
		noToggleMap()

#Actually apply update subroutine at start up
if starting:
	wiimote[0].buttons.update += updateWiimote
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Help with Wii Remote to vJoy mapping

Post by CyberVillain »

You could have a method called resetState that sets all buttons to false. Call that method first
Post Reply

Return to “FreePIE”