|
CodexPad Arduino Lib 2.1.6
|
#include <codex_pad.h>
Public Types | |
| enum class | TxPower : int8_t { kMinus16dBm = -16 , kMinus12dBm = -12 , kMinus8dBm = -8 , kMinus5dBm = -5 , kMinus3dBm = -3 , kMinus1dBm = -1 , k0dBm = 0 , k1dBm = 1 , k2dBm = 2 , k3dBm = 3 , k4dBm = 4 , k5dBm = 5 , k6dBm = 6 } |
| enum class | Button : uint32_t { kUp = uint32_t{1} << 0 , kDown = uint32_t{1} << 1 , kLeft = uint32_t{1} << 2 , kRight = uint32_t{1} << 3 , kSquareX = uint32_t{1} << 4 , kTriangleY = uint32_t{1} << 5 , kCrossA = uint32_t{1} << 6 , kCircleB = uint32_t{1} << 7 , kL1 = uint32_t{1} << 8 , kL2 = uint32_t{1} << 9 , kL3 = uint32_t{1} << 10 , kR1 = uint32_t{1} << 11 , kR2 = uint32_t{1} << 12 , kR3 = uint32_t{1} << 13 , kSelect = uint32_t{1} << 14 , kStart = uint32_t{1} << 15 , kHome = uint32_t{1} << 16 } |
| enum class | Axis : size_t { kLeftStickX , kLeftStickY , kRightStickX , kRightStickY } |
Public Member Functions | |
| CodexPad () | |
| Constructor. | |
| ~CodexPad () | |
| Destructor. | |
| void | Init () |
| Initialize. | |
| bool | Connect (const std::string &bluetooth_device_address, const uint32_t timeout_ms=5000) |
| Connect. | |
| bool | ScanAndConnect (const uint32_t button_mask) |
| Scans for nearby CodexPad devices and automatically connects to a device whose button state matches the specified mask. | |
| void | Disconnect () |
| Disconnect. | |
| void | Update () |
| Update, need to be called in Loop. | |
| bool | is_connected () const |
| Is connected. | |
| bool | set_remote_tx_power (const TxPower power) |
| Set transmission power, only effective when connected, immediately effective for current connection, effective for next connection. | |
| const std::string & | remote_device_name () const |
| Get model number of the CodexPad. | |
| const std::string & | remote_model_number () const |
| Get model number of the CodexPad. | |
| const std::array< uint8_t, 3 > | remote_firmware_version () const |
| Get firmware version of the CodexPad. | |
| bool | pressed (const Button button) const |
| check if a button is pressed | |
| bool | released (const Button button) const |
| check if a button is released | |
| bool | holding (const Button button) const |
| check if a button is held | |
| bool | button_state (const Button button) const |
| check if a button is pressed or held | |
| uint32_t | button_states () const |
| Get all button states, return a 32-bit unsigned integer where each bit represents the state of a specific button. | |
| uint8_t | axis_value (const Axis axis) const |
| Get axis value. | |
| std::array< uint8_t, kAxisValueNum > | axis_values () const |
| Get current values of all analog axes. | |
| bool | HasAxisValueChanged (const Axis axis, const uint8_t threshold) const |
| check if an axis value has changed | |
| NimBLEClient * | ble_client () const |
| Get the BLE client object. | |
Static Public Member Functions | |
| static constexpr uint32_t | ButtonMask () |
| template<typename FirstButton, typename... RestButtons> | |
| static constexpr uint32_t | ButtonMask (FirstButton first, RestButtons... rest) |
| Combines multiple button identifiers into a single 32-bit button mask. | |
Static Public Attributes | |
| static constexpr size_t | kAxisValueNum = 4 |
| Number of axis values. | |
| static constexpr uint8_t | kAxisCenter = 0x80 |
| Axis center value. | |
CodexPad main class.
Definition at line 46 of file codex_pad.h.
|
strong |
| Enumerator | |
|---|---|
| kLeftStickX | Left stick X axis. |
| kLeftStickY | Left stick Y axis. |
| kRightStickX | Right stick X axis. |
| kRightStickY | Right stick Y axis. |
Definition at line 402 of file codex_pad.h.
|
strong |
Definition at line 220 of file codex_pad.h.
|
strong |
Definition at line 78 of file codex_pad.h.
| CodexPad::CodexPad | ( | ) |
Constructor.
Definition at line 28 of file codex_pad.cpp.
| CodexPad::~CodexPad | ( | ) |
Destructor.
Definition at line 30 of file codex_pad.cpp.
| uint8_t CodexPad::axis_value | ( | const Axis | axis | ) | const |
Get axis value.
| [in] | axis | Axis |
Definition at line 163 of file codex_pad.cpp.
| std::array< uint8_t, CodexPad::kAxisValueNum > CodexPad::axis_values | ( | ) | const |
Get current values of all analog axes.
Typical center position value is 128 (0x80).
Example:
Definition at line 165 of file codex_pad.cpp.
|
inline |
Get the BLE client object.
This function returns a pointer to the internal BLE client object. The caller should not try and release/delete it.
Definition at line 903 of file codex_pad.h.
| bool CodexPad::button_state | ( | const Button | button | ) | const |
check if a button is pressed or held
| true | if the button is pressed or held |
| false | if the button is not pressed or held |
Definition at line 159 of file codex_pad.cpp.
| uint32_t CodexPad::button_states | ( | ) | const |
Get all button states, return a 32-bit unsigned integer where each bit represents the state of a specific button.
Definition at line 161 of file codex_pad.cpp.
|
inlinestaticconstexpr |
Definition at line 445 of file codex_pad.h.
|
inlinestaticconstexpr |
Combines multiple button identifiers into a single 32-bit button mask.
This is a convenience function for creating a bitmask that represents a combination of specific buttons (e.g., Start + A). The resulting mask can be used as a parameter for methods like ScanAndConnect, or for checking against the combined state returned by button_states.
| [in] | button | One or more button identifiers from the Button enumeration. |
constexpr function, allowing the mask to be computed at compile time. Example - Creating a mask for the Start and Cross/A buttons: Definition at line 493 of file codex_pad.h.
| bool CodexPad::Connect | ( | const std::string & | bluetooth_device_address, |
| const uint32_t | timeout_ms = 5000 ) |
Connect.
| [in] | bluetooth_device_address | The Bluetooth device address(BD_ADDR) of the CodexPad, formatted as "XX:XX:XX:XX:XX:XX", X is a number or uppercase letter, colon separated |
| [in] | timeout_ms | Timeout in milliseconds |
| true | if connected successfully |
| false | if connection failed |
Definition at line 38 of file codex_pad.cpp.
|
inline |
Disconnect.
Definition at line 658 of file codex_pad.h.
| bool CodexPad::HasAxisValueChanged | ( | const Axis | axis, |
| const uint8_t | threshold ) const |
check if an axis value has changed
| [in] | axis | Axis |
| [in] | threshold | Threshold |
| true | if the axis value has changed |
| false | if the axis value has not changed |
Definition at line 173 of file codex_pad.cpp.
| bool CodexPad::holding | ( | const Button | button | ) | const |
check if a button is held
| true | if the button is held |
| false | if the button is not held |
Definition at line 155 of file codex_pad.cpp.
| void CodexPad::Init | ( | ) |
Initialize.
Definition at line 32 of file codex_pad.cpp.
| bool CodexPad::is_connected | ( | ) | const |
Is connected.
| true | if connected |
| false | if not |
Definition at line 123 of file codex_pad.cpp.
| bool CodexPad::pressed | ( | const Button | button | ) | const |
check if a button is pressed
| true | if the button is pressed |
| false | if the button is not pressed |
Definition at line 147 of file codex_pad.cpp.
| bool CodexPad::released | ( | const Button | button | ) | const |
check if a button is released
| true | if the button is released |
| false | if the button is not released |
Definition at line 151 of file codex_pad.cpp.
|
inline |
Get model number of the CodexPad.
Definition at line 710 of file codex_pad.h.
|
inline |
Get firmware version of the CodexPad.
Definition at line 734 of file codex_pad.h.
|
inline |
Get model number of the CodexPad.
Definition at line 722 of file codex_pad.h.
| bool CodexPad::ScanAndConnect | ( | const uint32_t | button_mask | ) |
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches the specified mask.
This method actively scans for Bluetooth devices. When it discovers one or more CodexPad devices whose current button states exactly match the provided button_mask, it will attempt to establish a connection. If multiple nearby devices match the button mask, the device with the strongest signal (highest RSSI) will be selected for connection.
| [in] | button_mask | A 32-bit button mask used to match the target device's button states. Use the ButtonMask() function to combine multiple Button values. |
| true | Connection successful (a device matching the button mask was found and connected). |
| false | Connection failed (no matching device found or connection attempt failed). |
Button::kHome in the button mask. Holding the Home button triggers a device reboot, which will interrupt the connection process. Example: Definition at line 49 of file codex_pad.cpp.
| bool CodexPad::set_remote_tx_power | ( | const TxPower | power | ) |
Set transmission power, only effective when connected, immediately effective for current connection, effective for next connection.
| [in] | power | Transmission power |
| true | Success |
| false | Fail |
Definition at line 125 of file codex_pad.cpp.
| void CodexPad::Update | ( | ) |
Update, need to be called in Loop.
Definition at line 102 of file codex_pad.cpp.
|
staticconstexpr |
Axis center value.
Definition at line 66 of file codex_pad.h.
|
staticconstexpr |
Number of axis values.
Definition at line 56 of file codex_pad.h.