52using namespace gamepad::input;
57const std::string kBluetoothDeviceAddress =
"E4:66:E5:A2:17:06";
62 CLOGI(
"Start to connect %s", kBluetoothDeviceAddress.c_str());
65 while (!g_codex_pad_client.
Connect(kBluetoothDeviceAddress, 5000)) {
66 CLOGI(
"Retry to connect %s", kBluetoothDeviceAddress.c_str());
74 if (
const auto ble_client = g_codex_pad_client.
ble_client(); ble_client !=
nullptr) {
75 CLOGI(
"Remote Bluetooth Device Address: %s", ble_client->getPeerAddress().toString().c_str());
77 CLOGI(
"Remote Bluetooth Device Address: unknown");
88 g_codex_pad_client.
Init();
115 const gamepad::input::Tracker& it = g_codex_pad_client.
Update();
135 CLOGW(
"Disconnected, start to reconnect\n");
140 static uint32_t s_print_time = 0;
141 if (s_print_time != 0 && s_print_time + 50 > millis()) {
145 s_print_time = millis();
149 char buffer[512] = {0};
150 size_t length = snprintf(buffer,
sizeof(buffer),
"Button mask: 0x%08" PRIX32,
static_cast<uint32_t
>(it.button_mask()));
151 log.append(buffer, length);
163 length = snprintf(buffer,
sizeof(buffer),
", L(%3u, %3u), R(%3u, %3u)", it[Axis::kLeftStickX], it[Axis::kLeftStickY],
164 it[Axis::kRightStickX], it[Axis::kRightStickY]);
165 log.append(buffer, length);
176 if (it[Button::kUp]) {
180 if (it[Button::kDown]) {
181 log.append(
", Down");
184 if (it[Button::kLeft]) {
185 log.append(
", Left");
188 if (it[Button::kRight]) {
189 log.append(
", Right");
192 if (it[Button::kSquareX]) {
193 log.append(
", Square(X)");
196 if (it[Button::kTriangleY]) {
197 log.append(
", Triangle(Y)");
200 if (it[Button::kCrossA]) {
201 log.append(
", Cross(A)");
204 if (it[Button::kCircleB]) {
205 log.append(
", Circle(B)");
208 if (it[Button::kL1]) {
212 if (it[Button::kL2]) {
216 if (it[Button::kL3]) {
220 if (it[Button::kR1]) {
224 if (it[Button::kR2]) {
228 if (it[Button::kR3]) {
232 if (it[Button::kSelect]) {
233 log.append(
", Select");
236 if (it[Button::kStart]) {
237 log.append(
", Start");
240 if (it[Button::kHome]) {
241 log.append(
", Home");
244 CLOGI(
"%s", log.c_str());
const gamepad::input::Tracker & Update() noexcept
更新,需要在Loop中不断调用
const std::string & remote_device_name() const noexcept
获取CodexPad的型号
const std::array< uint8_t, 3 > & remote_firmware_version() const noexcept
获取CodexPad的固件版本
bool is_connected() const noexcept
是否连接
NimBLEClient * ble_client() const noexcept
获取 BLE 客户端对象
const std::string & remote_model_number() const noexcept
获取CodexPad的型号
bool Connect(const std::string &address, uint32_t timeout_ms=5000) noexcept
连接