Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem integrating the code in ESP-IDF #76

Open
Melek-Cherif opened this issue Jul 22, 2024 · 0 comments
Open

problem integrating the code in ESP-IDF #76

Melek-Cherif opened this issue Jul 22, 2024 · 0 comments

Comments

@Melek-Cherif
Copy link

Melek-Cherif commented Jul 22, 2024

I tried the library on Arduino and it works correctly. Now I tried to use it on esp-idf project it didn't work. First i got many compilation errors. After that I checked on every code file and tried to customize the library as I wish. This is my project tree:
Screenshot from 2024-07-22 18-41-18
I managed to successfully build the project. So here is the main file code:

`
#include <esp_bt_defs.h>
#include <esp_bt_main.h>
#include "esp_system.h"
#include "esp_mac.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "ps4.h"
#include "ps4_init.h"

#define PS4_TAG "PS4"

void event_callback(ps4_t ps4, ps4_event_t event) {
// Handle PS4 controller events here
ESP_LOGI(PS4_TAG, "PS4 event received");
}

void connection_callback(uint8_t isConnected) {
// Handle PS4 controller connection changes here
if (isConnected) {
ESP_LOGI(PS4_TAG, "PS4 controller connected");
} else {
ESP_LOGI(PS4_TAG, "PS4 controller disconnected");
}
}

bool ps4_controller_begin(const char* mac) {
esp_bd_addr_t addr;

// Convert the MAC address string to a byte array
if (sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
           &addr[0], &addr[1], &addr[2],
           &addr[3], &addr[4], &addr[5]) != 6) {
    ESP_LOGE(PS4_TAG, "Could not convert %s to a MAC address", mac);
    return false;
}

ps4SetBluetoothMacAddress(addr);

// Set the event and connection callbacks
ps4SetEventCallback(event_callback);
ps4SetConnectionCallback(connection_callback);

// Initialize NVS — it is used by the PS4 library to store the paired devices list
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
    ESP_ERROR_CHECK(nvs_flash_erase());
    ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

// Initialize and enable Bluedroid stack if necessary
esp_bluedroid_status_t btState = esp_bluedroid_get_status();
if (btState == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
    if (esp_bluedroid_init() != ESP_OK) {
        ESP_LOGE(PS4_TAG, "esp_bluedroid_init failed");
        return false;
    }
}

if (btState != ESP_BLUEDROID_STATUS_ENABLED) {
    if (esp_bluedroid_enable() != ESP_OK) {
        ESP_LOGE(PS4_TAG, "esp_bluedroid_enable failed");
        return false;
    }
}

// Initialize the PS4 controller
ps4Init();
return true;

}

bool ps4_controller_init() {
esp_bluedroid_status_t btState = esp_bluedroid_get_status();

if (btState == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
    if (esp_bluedroid_init()) {
        ESP_LOGE(PS4_TAG, "esp_bluedroid_init failed");
        return false;
    }
}

if (btState != ESP_BLUEDROID_STATUS_ENABLED) {
    if (esp_bluedroid_enable()) {
        ESP_LOGE(PS4_TAG, "esp_bluedroid_enable failed");
        return false;
    }
}

return true;

}

void app_main()
{
if (ps4_controller_init())
{
ps4_controller_begin("5c:96:56:ab:fa:40");
}
//ps4_controller_begin("b8:94:36:5a:96:8e");

// while(1)
// {
//     if (ps4IsConnected())
//     {
//         printf("connected successfully");
//     }
//     else printf("failed to connect");

// }

}
`
and here is the output:
Screenshot from 2024-07-22 18-46-30
So this is a problem in bluetooth configd. But I already tried all kind of configs and i have the same error.
I know that i am using ps4 controller library not ps3. However i believe it is similar issue. (also the ps4 repo is not active anymore so you are my last resort)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant