10#include "NimBLEDevice.h"
12#include "cyf/hysteresis_quantizer.h"
13#include "gamepad_input_tracker.h"
27class Client :
public NimBLEClientCallbacks {
77 bool Connect(
const std::string& address, uint32_t timeout_ms = 5000)
noexcept;
130 bool Connect(gamepad::input::Button buttons)
noexcept;
150 const gamepad::input::Tracker&
Update() noexcept;
214 const gamepad::input::Tracker&
input_tracker() const noexcept {
return input_tracker_; }
236 int32_t
rssi() const noexcept;
328 NimBLEClient*
ble_client() const noexcept {
return ble_client_; }
331 static constexpr size_t kInputsQueueMax = 10;
332 bool onConnParamsUpdateRequest(NimBLEClient*,
const ble_gap_upd_params*)
override {
336 void onPhyUpdate(NimBLEClient*, uint8_t tx_phy, uint8_t rx_phy)
override;
337 bool Connect(
const NimBLEAddress& address,
bool async_connect,
const uint32_t timeout_ms);
338 void OnNotify(
const NimBLERemoteCharacteristic* remote_characteristic,
const uint8_t* data,
const size_t length,
339 const bool is_notify);
341 void UpdateTxPower();
343 mutable std::mutex mutex_;
344 NimBLEClient* ble_client_{
nullptr};
345 std::string remote_device_name_;
346 std::string remote_model_number_;
347 std::array<uint8_t, 3> remote_firmware_version_{0, 0, 0};
348 std::queue<gamepad::input::State> inputs_queue_;
349 gamepad::input::Tracker input_tracker_;
350 cyf::HysteresisQuantizer<int32_t> rssi_quantizer_;
351 uint64_t last_update_tx_power_ms_{0};
352 bool dynamic_tx_power_enabled_ =
true;
353 int32_t local_tx_power_{0};
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 set_local_tx_power(int32_t tx_power) noexcept
Set the local BLE TX power (manual mode).
const std::array< uint8_t, 3 > & remote_firmware_version() const noexcept
Get firmware version of the CodexPad.
bool is_connected() const noexcept
Is connected.
void set_dynamic_tx_power_enabled(bool enabled) noexcept
Enable or disable dynamic TX power adjustment based on RSSI.
NimBLEClient * ble_client() const noexcept
Get the BLE client object.
void Init() noexcept
Initialize.
void Disconnect() noexcept
Disconnect.
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 connected CodexPad.
~Client() noexcept
Destructor.
int32_t local_tx_power() const noexcept
Get the manually configured local BLE TX power value.
bool Connect(const std::string &address, uint32_t timeout_ms=5000) noexcept
Connect.