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");
92 const int8_t local_tx_power = 9;
93 g_codex_pad_client.
Init(local_tx_power);
120 const gamepad::input::Tracker& it = g_codex_pad_client.
Update();
140 CLOGW(
"Disconnected, start to reconnect\n");
145 static uint32_t s_print_time = 0;
146 if (s_print_time != 0 && s_print_time + 50 > millis()) {
150 s_print_time = millis();
154 char buffer[512] = {0};
155 size_t length = snprintf(buffer,
sizeof(buffer),
"Button mask: 0x%08" PRIX32,
static_cast<uint32_t
>(it.button_mask()));
156 log.append(buffer, length);
168 length = snprintf(buffer,
sizeof(buffer),
", L(%3u, %3u), R(%3u, %3u)", it[Axis::kLeftStickX], it[Axis::kLeftStickY],
169 it[Axis::kRightStickX], it[Axis::kRightStickY]);
170 log.append(buffer, length);
181 if (it[Button::kUp]) {
185 if (it[Button::kDown]) {
186 log.append(
", Down");
189 if (it[Button::kLeft]) {
190 log.append(
", Left");
193 if (it[Button::kRight]) {
194 log.append(
", Right");
197 if (it[Button::kSquareX]) {
198 log.append(
", Square(X)");
201 if (it[Button::kTriangleY]) {
202 log.append(
", Triangle(Y)");
205 if (it[Button::kCrossA]) {
206 log.append(
", Cross(A)");
209 if (it[Button::kCircleB]) {
210 log.append(
", Circle(B)");
213 if (it[Button::kL1]) {
217 if (it[Button::kL2]) {
221 if (it[Button::kL3]) {
225 if (it[Button::kR1]) {
229 if (it[Button::kR2]) {
233 if (it[Button::kR3]) {
237 if (it[Button::kSelect]) {
238 log.append(
", Select");
241 if (it[Button::kStart]) {
242 log.append(
", Start");
245 if (it[Button::kHome]) {
246 log.append(
", Home");
249 CLOGI(
"%s", log.c_str());
const gamepad::input::Tracker & Update() noexcept
Update, need to be called in Loop.
const std::string & remote_device_name() const noexcept
Get model number of the CodexPad.
void Init(int8_t local_tx_power=3) noexcept
Initialize.
const std::array< uint8_t, 3 > & remote_firmware_version() const noexcept
Get firmware version of the CodexPad.
bool is_connected() const noexcept
Is connected.
NimBLEClient * ble_client() const noexcept
Get the BLE client object.
bool Connect(const std::string &bluetooth_device_address, uint32_t timeout_ms=5000) noexcept
Connect.
const std::string & remote_model_number() const noexcept
Get model number of the CodexPad.