#include "codex_pad.h"
namespace {
switch (button) {
return "Up";
}
return "Down";
}
return "Left";
}
return "Right";
}
return "Square(X)";
}
return "Triangle(Y)";
}
return "Cross(A)";
}
return "Circle(B)";
}
return "L1";
}
return "L2";
}
return "L3";
}
return "R1";
}
return "R2";
}
return "R3";
}
return "Select";
}
return "Start";
}
return "Home";
}
default: {
return {};
}
}
}
void Connect() {
printf("Start to scan and connect, button mask: 0x%08X\n", kExpectedButtonMask);
printf("Retry to scan and connect, button mask: 0x%08X\n", kExpectedButtonMask);
}
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;
}
if (g_codex_pad.pressed(button)) {
printf("Button %s: pressed\n", ButtonToString(button).c_str());
}
else if (g_codex_pad.released(button)) {
printf("Button %s: released\n", ButtonToString(button).c_str());
}
else if (g_codex_pad.holding(button)) {
printf("Button %s: holding\n", ButtonToString(button).c_str());
}
}
constexpr uint8_t kAxisValueChangeThreshold = 2;
printf("L(X: %3" PRIu8 ", Y: %3" PRIu8 "), R(X: %3" PRIu8 ", Y: %3" PRIu8 ")\n",
);
}
}
const std::array< uint8_t, 3 > remote_firmware_version() const
Get firmware version of the CodexPad.
const std::string & remote_model_number() const
Get model number of the CodexPad.
bool ScanAndConnect(const uint32_t button_mask)
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches t...
@ kLeftStickX
Left stick X axis.
@ kRightStickY
Right stick Y axis.
@ kLeftStickY
Left stick Y axis.
@ kRightStickX
Right stick X axis.
@ kTriangleY
Triangle or Y.
const std::string & remote_device_name() const
Get model number of the CodexPad.
NimBLEClient * ble_client() const
Get the BLE client object.
bool set_remote_tx_power(const TxPower power)
Set transmission power, only effective when connected, immediately effective for current connection,...