Nunchuck Analog stick delay

Official forum for open source FreePIE discussion and development.
Post Reply
User avatar
NopeU
One Eyed Hopeful
Posts: 31
Joined: Sat Dec 21, 2013 12:43 pm

Nunchuck Analog stick delay

Post by NopeU »

My Wiimote+Nunchuck everything works fine with the following script but the analog stick is being treated like rapid fire instead of single touches, in notepad it shows up as

IIIIIIIIIIIIIIIIJJJJJJJJJJJJJJJJJJJJJJJJJJKKKKKKKKKKKKKKKKKKKKLLLLLLLLLLLLLLLLLL​LL instead of just IJKL.
Do I need to add anything extra like deadzones or timing interval?

Code: Select all

def analogStick():
   if wiimote[0].nunchuck.stick.y > 40:
      keyboard.setPressed(Key.I)
   if wiimote[0].nunchuck.stick.y < -40:
      keyboard.setPressed(Key.K)
   if wiimote[0].nunchuck.stick.x > 40:
      keyboard.setPressed(Key.L)
   if wiimote[0].nunchuck.stick.x < -40:
      keyboard.setPressed(Key.J)

def map_wiimote_to_key(wiimote_index, wiimote_button, key):
    # Check the global wiimote object's button state and set the global
    # keyboard object's corresponding key.
    if wiimote[wiimote_index].buttons.button_down(wiimote_button):
        keyboard.setKeyDown(key)
    else:
        keyboard.setKeyUp(key)
        
def map_nunchuck_to_key(wiimote_index, wiimote_button, key):
    # Check the global nunchuck object's button state and set the global
    # keyboard object's corresponding key.
    if wiimote[wiimote_index].nunchuck.buttons.button_down(wiimote_button):
        keyboard.setKeyDown(key)
    else:
        keyboard.setKeyUp(key)
        
def update():
    # Sideways controls (DPad). Map each of our desired keys.
    map_wiimote_to_key(0, WiimoteButtons.DPadRight, Key.D)
    map_wiimote_to_key(0, WiimoteButtons.DPadLeft, Key.A)
    map_wiimote_to_key(0, WiimoteButtons.DPadUp, Key.W)
    map_wiimote_to_key(0, WiimoteButtons.DPadDown, Key.S)
    
    # 1 button --> 1 key
    map_wiimote_to_key(0, WiimoteButtons.One, Key.D1)
    # 2 button --> 2 key
    map_wiimote_to_key(0, WiimoteButtons.Two, Key.D2)
    
    # - button --> - key
    map_wiimote_to_key(0, WiimoteButtons.Minus, Key.Minus)
    # + button --> + key
    map_wiimote_to_key(0, WiimoteButtons.Plus, Key.NumberPadPlus)
    
    # A button --> X key
    map_wiimote_to_key(0, WiimoteButtons.A, Key.X)
    # B button --> B key
    map_wiimote_to_key(0, WiimoteButtons.B, Key.B)
    
    # Home button --> Return key
    map_wiimote_to_key(0, WiimoteButtons.Home, Key.Return)
    
    #nunchuck
    map_nunchuck_to_key(0, NunchuckButtons.C, Key.C)
    map_nunchuck_to_key(0, NunchuckButtons.Z, Key.Z)
    
# If we're starting up, then hook up our update function.
if starting:
    global previous
    previous = False
    wiimote[0].nunchuck.update += analogStick
    wiimote[0].buttons.update += update
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Nunchuck Analog stick delay

Post by CyberVillain »

Hi

Code: Select all

   if wiimote[0].nunchuck.stick.y > 40:
      keyboard.setPressed(Key.I)
This code will keep sending keypresses until y goes below 40 If you want to only send once and then reset when go under 40 you have to implement that yourself.

I might fix a setPressedOnce(Key key, bool state) in the future that will fix this for you
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Nunchuck Analog stick delay

Post by CyberVillain »

In next version of FreePIE you will be able todo

keyboard.setPressed(Key.I, wiimote[0].nunchuck.stick.y > 40)

This will only trigger key once if wiimote[0].nunchuck.stick.y > 40 and then wait until wiimote[0].nunchuck.stick.y > 40 is false to reset its state
User avatar
NopeU
One Eyed Hopeful
Posts: 31
Joined: Sat Dec 21, 2013 12:43 pm

Re: Nunchuck Analog stick delay

Post by NopeU »

Thanks look forward to it, also would it be possible to map the wiiimote+nunchuck as a fake xbox360 controller like scp xinput wrapper for the ds3/4? analog stick registering as xbox360 analog ranges rather than the digital keyboard presses?
Is more than analog stick analog on the wiimote+nunchuck analog? the B and Z shoulder buttons?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Nunchuck Analog stick delay

Post by CyberVillain »

There is no built in support to fake xbox, but look in the xbox thread, there are a plugin there XOutput that you can use
Post Reply

Return to “FreePIE”