10#include "NimBLEDevice.h"
11#include "gamepad_input_tracker.h"
25class Client :
public NimBLEClientCallbacks {
75 bool Connect(
const std::string& bluetooth_device_address, uint32_t timeout_ms = 5000)
noexcept;
148 const gamepad::input::Tracker&
Update() noexcept;
212 const gamepad::input::Tracker&
input_tracker() const noexcept {
return input_tracker_; }
224 int32_t
rssi() const noexcept;
239 NimBLEClient*
ble_client() const noexcept {
return ble_client_; }
242 static constexpr size_t kInputsQueueMax = 10;
243 bool onConnParamsUpdateRequest(NimBLEClient*,
const ble_gap_upd_params*)
override {
247 void onPhyUpdate(NimBLEClient*, uint8_t tx_phy, uint8_t rx_phy)
override;
248 bool Connect(
const NimBLEAddress& address,
bool async_connect,
const uint32_t timeout_ms);
249 void OnNotify(
const NimBLERemoteCharacteristic* remote_characteristic,
const uint8_t* data,
const size_t length,
250 const bool is_notify);
253 mutable std::mutex mutex_;
254 NimBLEClient* ble_client_{
nullptr};
255 std::string remote_device_name_;
256 std::string remote_model_number_;
257 std::array<uint8_t, 3> remote_firmware_version_{0, 0, 0};
258 std::queue<gamepad::input::State> inputs_queue_;
259 gamepad::input::Tracker input_tracker_;
Client() noexcept
Constructor.
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.
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.
void Init() noexcept
Initialize.
void Disconnect() noexcept
Disconnect.
bool ScanAndConnect(gamepad::input::Button buttons) noexcept
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches t...
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.
const gamepad::input::Tracker & input_tracker() const noexcept
Get the input tracker object.
int32_t rssi() const noexcept
Get the RSSI of the CodexPad.
~Client() noexcept
Destructor.