Purupuru functions not working ?

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
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Purupuru functions not working ?

Post by Orion_ »

Hello,
I'm trying to use the purupuru function, but I can't get it to work :(
I have a working vibration pack in my gamepad.
And here is my code: (which produce no vibration at all)

Code: Select all

purupuru_init();  // <- Tried this but it locks the program, so I removed it

void	DC_Rumble(int value, int time)
{
	maple_device_t		*dev;
	purupuru_effect_t	rumble;

	dev = maple_enum_type(0, MAPLE_FUNC_PURUPURU);
	if (dev)
	{
		rumble.duration = time;
		rumble.effect1 = PURUPURU_EFFECT1_INTENSITY(value);
		rumble.effect2 = PURUPURU_EFFECT2_UINTENSITY(value);
		rumble.special = 0;

		purupuru_rumble(dev, &rumble);
	}
}

	DC_Rumble(1,20); // whatever value I try, I get nothing
	DC_Rumble(2,20);
	DC_Rumble(4,20);
	DC_Rumble(7,10);
KOS seems to detect my vibration pack, since it shows up on the init log
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Purupuru functions not working ?

Post by BlueCrab »

Taking a wild guess here (because each manufacturer's rumble packs are different), but you haven't set the motor in the special field. You should set rumble.special to at least PURUPURU_SPECIAL_MOTOR1.

Also, look at the header comments or documentation, because you're setting invalid values for the UINTENSITY and INTENSITY values with your examples.
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: Purupuru functions not working ?

Post by Orion_ »

Thank you, It finally works with the special flags.
I thought it was optional.
Now, playing with the values (0-7 specified in the .h) I get strange result, but I got something nice with value 7
(duration of 100 or 250 won't change anything though...)
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Purupuru functions not working ?

Post by BlueCrab »

As I said, different rumble packs act differently, unfortunately. Some third-party rumble packs act really poorly and can cause major problems if you use them too often (blowing the fuse on the controller board, for instance).

All the information in the code is based on what's in this topic.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Purupuru functions not working ?

Post by Chilly Willy »

If you want a practical example, I used FF in my port of Doom for the DC. The main code routines look like this

Code: Select all

static int ff_enable = 1;
static int ff_timeout = 0;
static int ff_frequency = 0;
static int ff_intensity = 0;
static int ff_select = 0x10;

...

// Force Feedback
void I_Tactile (int freq, int intensity, int select)
{
    ff_frequency = freq;
    ff_intensity = intensity;
    ff_select = select;
    ff_timeout = I_GetTime() + 35;

    // FF will be handled at the same time as the events
}

...

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);
        ff_intensity = 0;
    }
}
Things that make it go thump call I_Tactil(). In the main loop, as part of checking the controllers, dc_handle_ff() is called. I_GetTime() returns 1/35th sec ticks, so the timeout on the ff is one second. Calls to I_Tactile() look like this

Code: Select all

        player->damagecount += damage;  // add damage after armor / invuln

        if (player->damagecount > 100)
            player->damagecount = 100;  // teleport stomp does 10k points...

        temp = damage < 100 ? damage : 100;

        if (player == &players[consoleplayer])
            I_Tactile (20, 1+(temp>>4), 0);
Frequency is always 20, and intensity varies between 1 and 7. Select is always 0 since Doom just uses the first controller. This seemed to work pretty good for most folks... never got any complaints about it. :grin:
Post Reply