Skip to content

Commit 173c444

Browse files
Allow setting names for BT/BLE HID devices (#1260)
1 parent 7aa1c08 commit 173c444

File tree

16 files changed

+74
-33
lines changed

16 files changed

+74
-33
lines changed

libraries/JoystickBLE/src/JoystickBLE.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,26 @@ JoystickBLE_::JoystickBLE_(void) {
3737

3838
#define REPORT_ID 0x01
3939
static const uint8_t desc_joystick[] = {TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(REPORT_ID))};
40-
void JoystickBLE_::begin(void) {
41-
PicoBluetoothBLEHID.startHID("PicoW BLE Joystick", "PicoW BLE Joystick", 0x03c4, desc_joystick, sizeof(desc_joystick));
40+
41+
void JoystickBLE_::begin(const char *localName, const char *hidName) {
42+
if (!localName) {
43+
localName = "PicoW BLE Joystick";
44+
}
45+
if (!hidName) {
46+
hidName = localName;
47+
}
48+
PicoBluetoothBLEHID.startHID(localName, hidName, 0x03c4, desc_joystick, sizeof(desc_joystick));
4249
}
4350

44-
void JoystickBLE_::end(void) {
51+
void JoystickBLE_::end() {
4552
PicoBluetoothBLEHID.end();
4653
}
4754

4855
void JoystickBLE_::setBattery(int lvl) {
4956
PicoBluetoothBLEHID.setBattery(lvl);
5057
}
5158

52-
void JoystickBLE_::send_now(void) {
59+
void JoystickBLE_::send_now() {
5360
PicoBluetoothBLEHID.send(&data, sizeof(data));
5461
}
5562

libraries/JoystickBLE/src/JoystickBLE.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
//======================================================================
2828
class JoystickBLE_ : public HID_Joystick {
2929
public:
30-
JoystickBLE_(void);
31-
void begin(void);
32-
void end(void);
33-
virtual void send_now(void) override;
30+
JoystickBLE_();
31+
void begin(const char *localName = nullptr, const char *hidName = nullptr);
32+
void end();
33+
virtual void send_now() override;
3434
void setBattery(int lvl);
3535
};
3636
extern JoystickBLE_ JoystickBLE;

libraries/JoystickBT/examples/BTJoystick-AllFunctions/BTJoystick-AllFunctions.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
void setup() {
1111
Serial.begin(115200);
1212
Serial.println("Use BOOTSEL to start the Joystick demo.");
13-
JoystickBT.begin();
13+
JoystickBT.begin("PicoJoy Demo");
1414
}
1515

1616
void loop() {

libraries/JoystickBT/src/JoystickBT.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,29 @@
3131
//================================================================================
3232
// Joystick/Gamepad
3333

34-
JoystickBT_::JoystickBT_(void) {
34+
JoystickBT_::JoystickBT_() {
3535
// HID_Joystick sets up all the member vars
3636
}
3737

3838
#define REPORT_ID 0x01
3939
static const uint8_t desc_joystick[] = {TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(REPORT_ID))};
40-
void JoystickBT_::begin(void) {
41-
PicoBluetoothHID.startHID("PicoW Joystick 00:00:00:00:00:00", "PicoW HID Joystick", 0x2508, 33, desc_joystick, sizeof(desc_joystick));
40+
41+
void JoystickBT_::begin(const char *localName, const char *hidName) {
42+
if (!localName) {
43+
localName = "PicoW BT Joystick";
44+
}
45+
if (!hidName) {
46+
hidName = localName;
47+
}
48+
PicoBluetoothHID.startHID(localName, hidName, 0x2508, 33, desc_joystick, sizeof(desc_joystick));
4249
}
4350

44-
void JoystickBT_::end(void) {
51+
void JoystickBT_::end() {
4552
PicoBluetoothHID.end();
4653
}
4754

4855
//immediately send an HID report
49-
void JoystickBT_::send_now(void) {
56+
void JoystickBT_::send_now() {
5057
PicoBluetoothHID.send(REPORT_ID, &data, sizeof(data));
5158
}
5259

libraries/JoystickBT/src/JoystickBT.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
//======================================================================
2828
class JoystickBT_ : public HID_Joystick {
2929
public:
30-
JoystickBT_(void);
31-
void begin(void);
32-
void end(void);
33-
virtual void send_now(void) override;
30+
JoystickBT_();
31+
void begin(const char *localName = nullptr, const char *hidName = nullptr);
32+
void end();
33+
virtual void send_now() override;
3434
};
3535
extern JoystickBT_ JoystickBT;

libraries/KeyboardBLE/src/KeyboardBLE.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ KeyboardBLE_::KeyboardBLE_(void) {
3535
#define REPORT_ID 0x01
3636

3737
static const uint8_t desc_keyboard[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID))};
38-
void KeyboardBLE_::begin(const uint8_t *layout) {
38+
39+
void KeyboardBLE_::begin(const char *localName, const char *hidName, const uint8_t *layout) {
40+
if (!localName) {
41+
localName = "PicoW BLE Keyboard";
42+
}
43+
if (!hidName) {
44+
hidName = localName;
45+
}
3946
_asciimap = layout;
40-
PicoBluetoothBLEHID.startHID("PicoW BLE Keyboard", "PicoW BLE Keyboard", 0x03c1, desc_keyboard, sizeof(desc_keyboard));
47+
PicoBluetoothBLEHID.startHID(localName, hidName, 0x03c1, desc_keyboard, sizeof(desc_keyboard));
4148
}
4249

4350
void KeyboardBLE_::end(void) {

libraries/KeyboardBLE/src/KeyboardBLE.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class KeyboardBLE_ : public HID_Keyboard {
3030
virtual void sendReport(KeyReport* keys) override;
3131
public:
3232
KeyboardBLE_(void);
33-
void begin(const uint8_t *layout = KeyboardLayout_en_US);
33+
void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US);
3434
void end(void);
3535
void setBattery(int lvl);
3636
};

libraries/KeyboardBT/examples/BTKeyboardPassword/BTKeyboardPassword.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
void setup() {
77
Serial.begin(115200);
8-
KeyboardBT.begin();
8+
KeyboardBT.begin("PicoW Password");
99
delay(5000);
1010
Serial.printf("Arduino USB Password Typer\n");
1111
Serial.printf("Press BOOTSEL to enter your super-secure(not!) password\n\n");

libraries/KeyboardBT/src/KeyboardBT.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ KeyboardBT_::KeyboardBT_(void) {
3535
#define REPORT_ID 0x01
3636

3737
static const uint8_t desc_keyboard[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID))};
38-
void KeyboardBT_::begin(const uint8_t *layout) {
38+
39+
void KeyboardBT_::begin(const char *localName, const char *hidName, const uint8_t *layout) {
40+
if (!localName) {
41+
localName = "PicoW BT Keyboard";
42+
}
43+
if (!hidName) {
44+
hidName = localName;
45+
}
3946
_asciimap = layout;
40-
PicoBluetoothHID.startHID("PicoW Keyboard 00:00:00:00:00:00", "PicoW HID Keyboard", 0x2540, 33, desc_keyboard, sizeof(desc_keyboard));
47+
PicoBluetoothHID.startHID(localName, hidName, 0x2540, 33, desc_keyboard, sizeof(desc_keyboard));
4148
}
4249

4350
void KeyboardBT_::end(void) {

libraries/KeyboardBT/src/KeyboardBT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class KeyboardBT_ : public HID_Keyboard {
3030
virtual void sendReport(KeyReport* keys) override;
3131
public:
3232
KeyboardBT_(void);
33-
void begin(const uint8_t *layout = KeyboardLayout_en_US);
33+
void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US);
3434
void end(void);
3535
};
3636
extern KeyboardBT_ KeyboardBT;

0 commit comments

Comments
 (0)