44using namespace gamepad::input;
63constexpr auto kExpectedButtonMask = Button::kStart | Button::kCrossA;
75std::string ButtonToString(Button button) {
86 case Button::kRight: {
89 case Button::kSquareX: {
92 case Button::kTriangleY: {
95 case Button::kCrossA: {
98 case Button::kCircleB: {
119 case Button::kSelect: {
122 case Button::kStart: {
125 case Button::kHome: {
135 printf(
"Start to scan and connect, button mask: 0x%08X\n", kExpectedButtonMask);
138 printf(
"Retry to scan and connect, button mask: 0x%08X\n", kExpectedButtonMask);
146 if (
const auto ble_client = g_codex_pad.
ble_client(); ble_client !=
nullptr) {
147 printf(
"Remote Bluetooth Device Address: %s\n", ble_client->getPeerAddress().toString().c_str());
149 printf(
"Remote Bluetooth Device Address: unknown\n");
160 printf(
"Set remote tx power to 0dBm successfully\n");
163 printf(
"Connected\n");
168 Serial.begin(115200);
198 const gamepad::input::Tracker& it = g_codex_pad.
Update();
214 printf(
"Disconnected, start to reconnect\n");
236 for (
auto button : {Button::kUp, Button::kDown, Button::kLeft, Button::kRight, Button::kSquareX, Button::kTriangleY,
237 Button::kCrossA, Button::kCircleB, Button::kL1, Button::kL2, Button::kL3, Button::kR1, Button::kR2,
238 Button::kR3, Button::kSelect, Button::kStart, Button::kHome}) {
239 if (it.pressed(button)) {
240 printf(
"Button %s: pressed\n", ButtonToString(button).c_str());
241 }
else if (it.released(button)) {
242 printf(
"Button %s: released\n", ButtonToString(button).c_str());
243 }
else if (it.holding(button)) {
244 printf(
"Button %s: holding\n", ButtonToString(button).c_str());
259 constexpr uint8_t kAxisValueChangeThreshold = 2;
261 if (it.AxisChanged(Axis::kLeftStickX, kAxisValueChangeThreshold) || it.AxisChanged(Axis::kLeftStickY, kAxisValueChangeThreshold) ||
262 it.AxisChanged(Axis::kRightStickX, kAxisValueChangeThreshold) ||
263 it.AxisChanged(Axis::kRightStickY, kAxisValueChangeThreshold)) {
264 printf(
"L(X: %3" PRIu8
", Y:%3" PRIu8
"), R(X: %3" PRIu8
", Y: %3" PRIu8
")\n", it[Axis::kLeftStickX],
265 it[Axis::kLeftStickY], it[Axis::kRightStickX], it[Axis::kRightStickY]);
bool is_connected() const noexcept
Is connected.
const std::array< uint8_t, 3 > & remote_firmware_version() const noexcept
Get firmware version of the CodexPad.
const gamepad::input::Tracker & Update() noexcept
Update, need to be called in Loop.
const std::string & remote_model_number() const noexcept
Get model number of the CodexPad.
void Init() noexcept
Initialize.
NimBLEClient * ble_client() const noexcept
Get the BLE client object.
const std::string & remote_device_name() const noexcept
Get model number of the CodexPad.
bool set_remote_tx_power(TxPower power) noexcept
Set transmission power, only effective when connected, immediately effective for current connection,...
bool ScanAndConnect(gamepad::input::Button buttons) noexcept
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches t...