Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Events not working as expected #35

Open
av4625 opened this issue Nov 24, 2021 · 0 comments
Open

Events not working as expected #35

av4625 opened this issue Nov 24, 2021 · 0 comments

Comments

@av4625
Copy link

av4625 commented Nov 24, 2021

Issue

I was trying to use the event callback method that this library provides.
I have a callback that gets called when the controller is connected and this works fine.

I then have a callback for controller events void event().

event seems to get called over and over as fast as it can even when I am not touching the controller. This doesn't seem correct?

The button_down and button_up events don't behave properly either. When I press the circle button with the code below. Nothing happens. When I let go of the button Down gets printed. Then after a ~second multiple Up's will get printed. I would expect one Down to get printed and one Up. Also multiple ups get printed just after the controller connects before touching any buttons.

Code Change in Library

I had to change a define or the library wouldn't build.

In ps4_int.h I changed:
#define CONFIG_IDF_COMPATIBILITY IDF_COMPATIBILITY_MASTER_21165ED
to:
#define CONFIG_IDF_COMPATIBILITY IDF_COMPATIBILITY_MASTER_21AF1D7

Code

#include <PS4Controller.h>

void setup()
{
    Serial.begin(115200);
    PS4.attach(event);
    PS4.begin("01:01:01:01:01:01");
    PS4.attachOnConnect(connected);
    Serial.println("Ready.");
}

void event()
{
    if(PS4.event.button_down.circle)
    {
        Serial.println("Down");
    }
    if(PS4.event.button_up.circle)
    {
        Serial.println("Up");
    }
}

void connected()
{
    if (PS4.Charging())
    {
        Serial.println("The controller is charging");
    }

    Serial.printf("Battery Level : %d\n", PS4.Battery());
    Serial.println();
}

void loop()
{
    vTaskDelete(NULL);
}

Output

I connected the controller. Then pressed and released circle 5 times.

Ready.
Battery Level : 0

Up
Up
Up
Up
Up
Up
Up
Down
Down
Down
Down
Down
// 1 to 2 second gap of not touching controller
Up
Up
Up
Up
Up
Up
Up
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant