Skip to content

Commit

Permalink
For consistency, BTHID Joypad->Joystick (#2218)
Browse files Browse the repository at this point in the history
Matches existing library names and nomenclature
  • Loading branch information
earlephilhower committed Jun 10, 2024
1 parent db13d3c commit f272995
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions docs/hidmaster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~
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
to 32 button states at a time.

.. 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.
// Use "buttons & (1 << buttonNumber)" to look at the individual button states
// ...
Expand All @@ -147,7 +147,7 @@ BluetoothHIDMaster::onXXX Callback Installers
void BluetoothHIDMaster::onKeyUp(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::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
------------------------
Expand Down Expand Up @@ -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.
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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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) cbdata;
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
Expand Down Expand Up @@ -202,7 +202,7 @@ void setup() {
hid.onConsumerKeyDown(ckb, (void *)true);
hid.onConsumerKeyUp(ckb, (void *)false);

hid.onJoypad(joy);
hid.onJoystick(joy);

hid.begin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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) cbdata;
const char *hats[16] = { "U", "UR", "R", "DR", "D", "DL", "L", "UL", "", "", "", "", "", "", "", "." };
Expand Down Expand Up @@ -202,7 +202,7 @@ void setup() {
hid.onConsumerKeyDown(ckb, (void *)true);
hid.onConsumerKeyUp(ckb, (void *)false);

hid.onJoypad(joy);
hid.onJoystick(joy);

hid.begin(true);

Expand Down
12 changes: 6 additions & 6 deletions libraries/BluetoothHIDMaster/src/BluetoothHIDMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ void BluetoothHIDMaster::onConsumerKeyUp(void (*cb)(void *, int), void *cbData)
_consumerKeyUpData = cbData;
}

void BluetoothHIDMaster::onJoypad(void (*cb)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData) {
_joypadCB = cb;
_joypadData = cbData;
void BluetoothHIDMaster::onJoystick(void (*cb)(void *, int, int, int, int, uint8_t, uint32_t), void *cbData) {
_joystickCB = cb;
_joystickData = cbData;
}

std::list<BTDeviceInfo> BluetoothHIDMaster::scan(uint32_t mask, int scanTimeSec, bool async) {
Expand Down Expand Up @@ -257,7 +257,7 @@ bool BluetoothHIDMaster::connectMouse() {
return connectCOD(0x2580);
}

bool BluetoothHIDMaster::connectJoypad() {
bool BluetoothHIDMaster::connectJoystick() {
return connectCOD(0x2508);
}

Expand Down Expand Up @@ -427,8 +427,8 @@ void BluetoothHIDMaster::hid_host_handle_interrupt_report(btstack_hid_parser_t *
if (updMouse && _mouseMoveCB) {
_mouseMoveCB(_mouseMoveData, dx, dy, dwheel);
}
if (updJoy && _joypadCB) {
_joypadCB(_joypadData, dx, dy, dz, rz, hat, newMB);
if (updJoy && _joystickCB) {
_joystickCB(_joystickData, dx, dy, dz, rz, hat, newMB);
}
}

Expand Down
12 changes: 6 additions & 6 deletions libraries/BluetoothHIDMaster/src/BluetoothHIDMaster.h
Original file line number Diff line number Diff line change
@@ -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
Copyright (c) 2024 Earle F. Philhower, III <earlephilhower@yahoo.com>
Expand Down Expand Up @@ -78,7 +78,7 @@ class BluetoothHIDMaster {

static const uint32_t keyboard_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;
std::list<BTDeviceInfo> scan(uint32_t mask, int scanTimeSec = 5, bool async = false);
bool scanAsyncDone();
Expand All @@ -87,7 +87,7 @@ class BluetoothHIDMaster {
bool connect(const uint8_t *addr);
bool connectKeyboard();
bool connectMouse();
bool connectJoypad();
bool connectJoystick();
bool connectAny();

bool connectBLE(const uint8_t *addr, int addrType);
Expand All @@ -102,7 +102,7 @@ class BluetoothHIDMaster {
void onKeyUp(void (*)(void *, int), void *cbData = nullptr);
void onConsumerKeyDown(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:
bool _ble = false;
Expand Down Expand Up @@ -135,8 +135,8 @@ class BluetoothHIDMaster {
void (*_consumerKeyUpCB)(void *, int) = nullptr;
void *_consumerKeyUpData;

void (*_joypadCB)(void *, int, int, int, int, uint8_t, uint32_t) = nullptr;
void *_joypadData;
void (*_joystickCB)(void *, int, int, int, int, uint8_t, uint32_t) = nullptr;
void *_joystickData;


btstack_packet_callback_registration_t _sm_event_callback_registration;
Expand Down

0 comments on commit f272995

Please sign in to comment.