BLE-Gamepad-Client 0.3.2
Loading...
Searching...
No Matches
BLEController.h
1#pragma once
2
3#include <NimBLEAddress.h>
4#include "BLEBatteryEvent.h"
5#include "BLEControllerInternal.h"
6#include "BLEControlsEvent.h"
7#include "BLEVibrationsCommand.h"
8
9class BLEController {
10 public:
11 BLEController();
12 explicit BLEController(NimBLEAddress address);
13 explicit BLEController(const std::string& address);
14 ~BLEController() = default;
15 bool begin();
16 bool isConnected() const;
17 NimBLEAddress getAddress() const;
18 void onConnect(const OnConnect& callback);
19 void onDisconnect(const OnDisconnect& callback);
20 void readControls(BLEControlsEvent& event) const;
21 void onControlsUpdate(const OnControlsUpdate& callback);
22 void readBattery(BLEBatteryEvent& event) const;
23 void onBatteryUpdate(const OnBatteryUpdate& callback);
24 void writeVibrations(const BLEVibrationsCommand& cmd) const;
25
26 private:
28 NimBLEAddress _allowedAddress;
29 OnConnect _onConnect;
30 OnDisconnect _onDisconnect;
31 OnControlsUpdate _onControlsUpdate;
32 bool _onControlsUpdateIsSet;
33 OnBatteryUpdate _onBatteryUpdate;
34 bool _onBatteryUpdateIsSet;
35};
Definition BLEControllerInternal.h:15
void writeVibrations(const BLEVibrationsCommand &cmd) const
Send the vibrations command to the connected controller.
Definition BLEController.cpp:148
void onConnect(const OnConnect &callback)
Sets the callback to be invoked when the controller connects.
Definition BLEController.cpp:82
void onBatteryUpdate(const OnBatteryUpdate &callback)
Sets the callback to be invoked when the controller sends update to the battery state.
Definition BLEController.cpp:136
void readBattery(BLEBatteryEvent &event) const
Read the battery state from the connected controller.
Definition BLEController.cpp:126
bool begin()
Initializes a controller instance and NimBLE stack if it's not already initialized.
Definition BLEController.cpp:22
NimBLEAddress getAddress() const
Returns one of the following:
Definition BLEController.cpp:70
void onControlsUpdate(const OnControlsUpdate &callback)
Sets the callback to be invoked when the controller sends update to the controls state.
Definition BLEController.cpp:114
void onDisconnect(const OnDisconnect &callback)
Sets the callback to be invoked when the controller disconnects.
Definition BLEController.cpp:93
bool isConnected() const
Is controller connected to the board.
Definition BLEController.cpp:54
void readControls(BLEControlsEvent &event) const
Read the controls state from the connected controller.
Definition BLEController.cpp:104
Definition BLEBatteryEvent.h:5
Definition BLEControlsEvent.h:5
Definition BLEVibrationsCommand.h:3