Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/PS4Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#include <esp_bt_main.h>

extern "C" {
#include "esp_bt_device.h"
#include "ps4.h"
}

#define ESP_BD_ADDR_HEX_STR "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"
#define ESP_BD_ADDR_HEX_ARR(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]

#define ESP_BD_ADDR_HEX_PTR(addr) \
(uint8_t*)addr + 0, (uint8_t*)addr + 1, (uint8_t*)addr + 2, \
(uint8_t*)addr + 3, (uint8_t*)addr + 4, (uint8_t*)addr + 5
Expand Down Expand Up @@ -56,6 +60,22 @@ bool PS4Controller::begin(const char* mac) {

void PS4Controller::end() {}

String PS4Controller::getAddress() {
String address = "";

if (btStarted()) {
char mac[18];
const uint8_t* addr = esp_bt_dev_get_address();

sprintf(mac, ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX_ARR(addr));

address = String(mac);
}

return address;
}


bool PS4Controller::isConnected() { return ps4IsConnected(); }

void PS4Controller::setLed(uint8_t r, uint8_t g, uint8_t b) {
Expand Down
2 changes: 2 additions & 0 deletions src/PS4Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class PS4Controller {
bool begin(const char* mac);
void end();

String getAddress();

bool isConnected();

void setLed(uint8_t r, uint8_t g, uint8_t b);
Expand Down