#include "codex_pad.h"
namespace {
const std::string kBluetoothDeviceAddress = "E4:66:E5:A2:24:5D";
void Connect() {
printf("Start to connect %s\n", kBluetoothDeviceAddress.c_str());
while (!g_codex_pad.
Connect(kBluetoothDeviceAddress, 5000)) {
printf("Retry to connect %s\n", kBluetoothDeviceAddress.c_str());
}
printf("Remote firmware revision: %u.%u.%u\n",
if (
const auto ble_client = g_codex_pad.
ble_client(); ble_client !=
nullptr) {
printf("Remote Bluetooth Device Address: %s\n", ble_client->getPeerAddress().toString().c_str());
} else {
printf("Remote Bluetooth Device Address: unknown\n");
}
printf("Set remote tx power to 0dBm successfully\n");
}
printf("Connected\n");
}
}
void setup() {
Serial.begin(115200);
printf("Init\n");
g_codex_pad.Init();
Connect();
}
void loop() {
g_codex_pad.Update();
if (!g_codex_pad.is_connected()) {
printf("Disconnected, start to reconnect\n");
Connect();
return;
}
static uint32_t s_print_time = 0;
if (s_print_time == 0 || s_print_time + 30 < millis()) {
s_print_time = millis();
printf(
"Up:%u, Down:%u, Left:%u, Right:%u, Square(X):%u, Triangle(Y):%u, Cross(A):%u, Circle(B):%u, L1:%u, L2:%u, L3:%u, R1:%u, R2:%u, "
"R3:%u, Select:%u, "
"Start:%u, Home:%u, L(X:%3u, Y:%3u), R(X:%3u, Y:%3u)\n",
}
}
const std::array< uint8_t, 3 > remote_firmware_version() const
获取CodexPad的固件版本
const std::string & remote_model_number() const
获取CodexPad的型号
bool Connect(const std::string &bluetooth_device_address, const uint32_t timeout_ms=5000)
连接
const std::string & remote_device_name() const
获取CodexPad的型号
NimBLEClient * ble_client() const
获取 BLE 客户端对象
bool set_remote_tx_power(const TxPower power)
设置发射功率,连接状态下调用,立即生效于当前连接,下次连接生效