For consistency, BTHID Joypad->Joystick (#2218)
Matches existing library names and nomenclature
This commit is contained in:
parent
db13d3c1f8
commit
f272995536
5 changed files with 20 additions and 20 deletions
|
|
@ -119,13 +119,13 @@ HID key and the up/down state to the stream and read back the ASCII for use in a
|
||||||
|
|
||||||
Joystick Callbacks
|
Joystick Callbacks
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
A single ``BluetoothHIDMaster::onJoypad`` callback gets activated every time a report from a joystick is processed.
|
A single ``BluetoothHIDMaster::onJoystick`` callback gets activated every time a report from a joystick is processed.
|
||||||
It receives (potentially, if supported by the device) 4 analog axes, one 8-way digital hat switch position, and up
|
It receives (potentially, if supported by the device) 4 analog axes, one 8-way digital hat switch position, and up
|
||||||
to 32 button states at a time.
|
to 32 button states at a time.
|
||||||
|
|
||||||
.. code :: cpp
|
.. code :: cpp
|
||||||
|
|
||||||
void joypadCB(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
void joystickCB(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
||||||
// HAT 0 = UP and continues clockwise. If no hat direction it is set to 0x0f.
|
// HAT 0 = UP and continues clockwise. If no hat direction it is set to 0x0f.
|
||||||
// Use "buttons & (1 << buttonNumber)" to look at the individual button states
|
// Use "buttons & (1 << buttonNumber)" to look at the individual button states
|
||||||
// ...
|
// ...
|
||||||
|
|
@ -147,7 +147,7 @@ BluetoothHIDMaster::onXXX Callback Installers
|
||||||
void BluetoothHIDMaster::onKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
void BluetoothHIDMaster::onKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void BluetoothHIDMaster::onConsumerKeyDown(void (*)(void *, int), void *cbData = nullptr);
|
void BluetoothHIDMaster::onConsumerKeyDown(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void BluetoothHIDMaster::onConsumerKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
void BluetoothHIDMaster::onConsumerKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void BluetoothHIDMaster::onJoypad(void (*)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData = nullptr);
|
void BluetoothHIDMaster::onJoystick(void (*)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData = nullptr);
|
||||||
|
|
||||||
BluetoothHIDMaster Class
|
BluetoothHIDMaster Class
|
||||||
------------------------
|
------------------------
|
||||||
|
|
@ -187,7 +187,7 @@ bool BluetoothHIDMaster::connect(const uint8_t *addr)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
Start the connection process to the Bluetooth Classic device with the given MAC. Note that this returns immediately, but it may take several seconds until ``connected()`` reports that the connection has been established.
|
Start the connection process to the Bluetooth Classic device with the given MAC. Note that this returns immediately, but it may take several seconds until ``connected()`` reports that the connection has been established.
|
||||||
|
|
||||||
bool BluetoothHIDMaster::connectKeyboard(), connectMouse(), connectJoypad(), connectAny()
|
bool BluetoothHIDMaster::connectKeyboard(), connectMouse(), connectJoystick(), connectAny()
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
Connect to the first found specified Bluetooth Classic device type (or any HID device) in pairing mode. No need to call ``scan()`` or have an address.
|
Connect to the first found specified Bluetooth Classic device type (or any HID device) in pairing mode. No need to call ``scan()`` or have an address.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ void ckb(void *cbdata, int key) {
|
||||||
|
|
||||||
|
|
||||||
// Joystick can get reports of 4 analog axes, 1 d-pad bitfield, and up to 32 buttons
|
// Joystick can get reports of 4 analog axes, 1 d-pad bitfield, and up to 32 buttons
|
||||||
// Axes and hats that aren't reported by the pad are read as 0
|
// Axes and hats that aren't reported by the joystick are read as 0
|
||||||
void joy(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
void joy(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
||||||
(void) cbdata;
|
(void) cbdata;
|
||||||
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
|
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
|
||||||
|
|
@ -202,7 +202,7 @@ void setup() {
|
||||||
hid.onConsumerKeyDown(ckb, (void *)true);
|
hid.onConsumerKeyDown(ckb, (void *)true);
|
||||||
hid.onConsumerKeyUp(ckb, (void *)false);
|
hid.onConsumerKeyUp(ckb, (void *)false);
|
||||||
|
|
||||||
hid.onJoypad(joy);
|
hid.onJoystick(joy);
|
||||||
|
|
||||||
hid.begin();
|
hid.begin();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ void ckb(void *cbdata, int key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Joystick can get reports of 4 analog axes, 1 d-pad bitfield, and up to 32 buttons
|
// Joystick can get reports of 4 analog axes, 1 d-pad bitfield, and up to 32 buttons
|
||||||
// Axes and hats that aren't reported by the pad are read as 0
|
// Axes and hats that aren't reported by the joystick are read as 0
|
||||||
void joy(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
void joy(void *cbdata, int x, int y, int z, int rz, uint8_t hat, uint32_t buttons) {
|
||||||
(void) cbdata;
|
(void) cbdata;
|
||||||
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
|
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
|
||||||
|
|
@ -202,7 +202,7 @@ void setup() {
|
||||||
hid.onConsumerKeyDown(ckb, (void *)true);
|
hid.onConsumerKeyDown(ckb, (void *)true);
|
||||||
hid.onConsumerKeyUp(ckb, (void *)false);
|
hid.onConsumerKeyUp(ckb, (void *)false);
|
||||||
|
|
||||||
hid.onJoypad(joy);
|
hid.onJoystick(joy);
|
||||||
|
|
||||||
hid.begin(true);
|
hid.begin(true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,9 +161,9 @@ void BluetoothHIDMaster::onConsumerKeyUp(void (*cb)(void *, int), void *cbData)
|
||||||
_consumerKeyUpData = cbData;
|
_consumerKeyUpData = cbData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothHIDMaster::onJoypad(void (*cb)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData) {
|
void BluetoothHIDMaster::onJoystick(void (*cb)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData) {
|
||||||
_joypadCB = cb;
|
_joystickCB = cb;
|
||||||
_joypadData = cbData;
|
_joystickData = cbData;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<BTDeviceInfo> BluetoothHIDMaster::scan(uint32_t mask, int scanTimeSec, bool async) {
|
std::list<BTDeviceInfo> BluetoothHIDMaster::scan(uint32_t mask, int scanTimeSec, bool async) {
|
||||||
|
|
@ -257,7 +257,7 @@ bool BluetoothHIDMaster::connectMouse() {
|
||||||
return connectCOD(0x2580);
|
return connectCOD(0x2580);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BluetoothHIDMaster::connectJoypad() {
|
bool BluetoothHIDMaster::connectJoystick() {
|
||||||
return connectCOD(0x2508);
|
return connectCOD(0x2508);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,8 +427,8 @@ void BluetoothHIDMaster::hid_host_handle_interrupt_report(btstack_hid_parser_t *
|
||||||
if (updMouse && _mouseMoveCB) {
|
if (updMouse && _mouseMoveCB) {
|
||||||
_mouseMoveCB(_mouseMoveData, dx, dy, dwheel);
|
_mouseMoveCB(_mouseMoveData, dx, dy, dwheel);
|
||||||
}
|
}
|
||||||
if (updJoy && _joypadCB) {
|
if (updJoy && _joystickCB) {
|
||||||
_joypadCB(_joypadData, dx, dy, dz, rz, hat, newMB);
|
_joystickCB(_joystickData, dx, dy, dz, rz, hat, newMB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Bluetooth HID Master class, can connect to keyboards, mice, and joypads
|
Bluetooth HID Master class, can connect to keyboards, mice, and joysticks
|
||||||
Works with Bluetooth Classic and BLE devices
|
Works with Bluetooth Classic and BLE devices
|
||||||
|
|
||||||
Copyright (c) 2024 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
Copyright (c) 2024 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||||
|
|
@ -78,7 +78,7 @@ public:
|
||||||
|
|
||||||
static const uint32_t keyboard_cod = 0x2540;
|
static const uint32_t keyboard_cod = 0x2540;
|
||||||
static const uint32_t mouse_cod = 0x2540;
|
static const uint32_t mouse_cod = 0x2540;
|
||||||
static const uint32_t joypad_cod = 0x2508;
|
static const uint32_t joystick_cod = 0x2508;
|
||||||
static const uint32_t any_cod = 0;
|
static const uint32_t any_cod = 0;
|
||||||
std::list<BTDeviceInfo> scan(uint32_t mask, int scanTimeSec = 5, bool async = false);
|
std::list<BTDeviceInfo> scan(uint32_t mask, int scanTimeSec = 5, bool async = false);
|
||||||
bool scanAsyncDone();
|
bool scanAsyncDone();
|
||||||
|
|
@ -87,7 +87,7 @@ public:
|
||||||
bool connect(const uint8_t *addr);
|
bool connect(const uint8_t *addr);
|
||||||
bool connectKeyboard();
|
bool connectKeyboard();
|
||||||
bool connectMouse();
|
bool connectMouse();
|
||||||
bool connectJoypad();
|
bool connectJoystick();
|
||||||
bool connectAny();
|
bool connectAny();
|
||||||
|
|
||||||
bool connectBLE(const uint8_t *addr, int addrType);
|
bool connectBLE(const uint8_t *addr, int addrType);
|
||||||
|
|
@ -102,7 +102,7 @@ public:
|
||||||
void onKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
void onKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void onConsumerKeyDown(void (*)(void *, int), void *cbData = nullptr);
|
void onConsumerKeyDown(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void onConsumerKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
void onConsumerKeyUp(void (*)(void *, int), void *cbData = nullptr);
|
||||||
void onJoypad(void (*)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData = nullptr);
|
void onJoystick(void (*)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _ble = false;
|
bool _ble = false;
|
||||||
|
|
@ -135,8 +135,8 @@ private:
|
||||||
void (*_consumerKeyUpCB)(void *, int) = nullptr;
|
void (*_consumerKeyUpCB)(void *, int) = nullptr;
|
||||||
void *_consumerKeyUpData;
|
void *_consumerKeyUpData;
|
||||||
|
|
||||||
void (*_joypadCB)(void *, int, int, int, int, uint8_t, uint32_t) = nullptr;
|
void (*_joystickCB)(void *, int, int, int, int, uint8_t, uint32_t) = nullptr;
|
||||||
void *_joypadData;
|
void *_joystickData;
|
||||||
|
|
||||||
|
|
||||||
btstack_packet_callback_registration_t _sm_event_callback_registration;
|
btstack_packet_callback_registration_t _sm_event_callback_registration;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue