10#include "NimBLEDevice.h"
11#include "gamepad_input_tracker.h"
25class Client :
public NimBLEClientCallbacks {
57 void Init(int8_t local_tx_power = 3)
noexcept;
77 bool Connect(
const std::string& bluetooth_device_address, uint32_t timeout_ms = 5000)
noexcept;
150 const gamepad::input::Tracker&
Update() noexcept;
214 const gamepad::input::Tracker&
input_tracker() const noexcept {
return input_tracker_; }
226 int32_t
rssi() const noexcept;
241 NimBLEClient*
ble_client() const noexcept {
return ble_client_; }
244 static constexpr size_t kInputsQueueMax = 10;
245 bool onConnParamsUpdateRequest(NimBLEClient*,
const ble_gap_upd_params*)
override {
249 void onPhyUpdate(NimBLEClient*, uint8_t tx_phy, uint8_t rx_phy)
override;
250 bool Connect(
const NimBLEAddress& address,
bool async_connect,
const uint32_t timeout_ms);
251 void OnNotify(
const NimBLERemoteCharacteristic* remote_characteristic,
const uint8_t* data,
const size_t length,
252 const bool is_notify);
255 mutable std::mutex mutex_;
256 NimBLEClient* ble_client_{
nullptr};
257 std::string remote_device_name_;
258 std::string remote_model_number_;
259 std::array<uint8_t, 3> remote_firmware_version_{0, 0, 0};
260 std::queue<gamepad::input::State> inputs_queue_;
261 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.
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.
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.