Help with purupuru

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

Help with purupuru

Post by Chilly Willy » Thu Aug 20, 2009 11:58 am

I've been trying to add rumble support to my conversion of Doom and just can't get it to work. I can get it to rumble, but nearly every time I do, the next read of the controller returns bad data. Once you quit trying to do force feedback, the controller works fine again. The code I'm using for the purupuru is taken from an example I found and the RADQuake code.

Code: Select all

static void dc_handle_ff(void)
{
    maple_device_t * jump;

    if (!ff_enable)
        return; // early out

    jump = maple_enum_type(0, MAPLE_FUNC_PURUPURU);

    if (ff_timeout && jump)
    {
        if (I_GetTime() >= ff_timeout)
        {
            static purupuru_effect_t effect;
            effect.duration = 0x00;
            effect.effect2 = 0x00;
            effect.effect1 = 0x00;
            effect.special = PURUPURU_SPECIAL_MOTOR1;
            purupuru_rumble(jump, &effect);
            ff_timeout = 0;
            ff_intensity = 0;
        }
    }

    if (ff_intensity && jump)
    {
        static purupuru_effect_t effect;
        effect.duration = 0x11;
        effect.effect2 = ff_frequency;
        effect.effect1 = PURUPURU_EFFECT1_INTENSITY(ff_intensity);
        effect.special = PURUPURU_SPECIAL_MOTOR1 | ff_select;
        purupuru_rumble(jump, &effect);
    }
}
The function is called once a "tick", which is 35 Hz. The "frequency" is 7, 10, or 20, the intensity is 0 to 7, and select is just 0 or 1 depending on whether I want a thud or a pulse. It's odd that it affects the controller as there's nothing in common between them other than whatever KOS does in the maple handling. There are no shared variables of any kind between them. As you can see in the code above, the JumpPack uses a local static struct. The controller uses the state passed back:

Code: Select all

    cstate = (cont_state_t *)maple_dev_status(cont);
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

Re: Help with purupuru

Post by Chilly Willy » Sat Sep 05, 2009 2:56 pm

In case someone else runs into something similar, the problem was in the controller/keyboard/mouse code.

Code: Select all

  if (!cont)
    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
  if (!kbd)
  {
    kbd = maple_enum_type(0, MAPLE_FUNC_KEYBOARD);
    if (kbd)
      kbd_set_queue(0); // turn off keyboard queue
  }
  if (!mky)
    mky = maple_enum_type(0, MAPLE_FUNC_MOUSE);

  if (cont)
    cstate = (cont_state_t *)maple_dev_status(cont);
  if (kbd)
    kstate = (kbd_state_t *)maple_dev_status(kbd);
  if (mky)
    mstate = (mouse_state_t *)maple_dev_status(mky);
Looks okay, right? And it works fine without the Jump Pack. The moment you try to use the Jump Pack - ERRORS!

Code: Select all

  //if (!cont)
    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
  //if (!kbd)
  {
    kbd = maple_enum_type(0, MAPLE_FUNC_KEYBOARD);
    if (kbd)
      kbd_set_queue(0); // turn off keyboard queue
  }
  //if (!mky)
    mky = maple_enum_type(0, MAPLE_FUNC_MOUSE);

  if (cont)
    cstate = (cont_state_t *)maple_dev_status(cont);
  else
    cstate = NULL;
  if (kbd)
    kstate = (kbd_state_t *)maple_dev_status(kbd);
  else
    kstate = NULL;
  if (mky)
    mstate = (mouse_state_t *)maple_dev_status(mky);
  else
    mstate = NULL;
There we go! Much better! Now you're ready to rumble! (pun intended) :lol:
Post Reply