Skip to content

Commit

Permalink
Allow setting SerialBT advertised name (#2181)
Browse files Browse the repository at this point in the history
Trivial fix #2179
  • Loading branch information
earlephilhower authored May 30, 2024
1 parent 361b4e0 commit 1f9350d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <SerialBT.h>

void setup() {
SerialBT.setName("PicoW UPPERCASE 00:00:00:00:00:00");
SerialBT.begin();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/SerialBT/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SerialBT KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setName KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
5 changes: 4 additions & 1 deletion libraries/SerialBT/src/SerialBT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ void SerialBT_::begin(unsigned long baud, uint16_t config) {

gap_discoverable_control(1);
gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
gap_set_local_name("PicoW Serial 00:00:00:00:00:00");
if (!_name) {
setName("PicoW Serial 00:00:00:00:00:00");
}
gap_set_local_name(_name);

// Turn on!
hci_power_control(HCI_POWER_ON);
Expand Down
10 changes: 10 additions & 0 deletions libraries/SerialBT/src/SerialBT.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class SerialBT_ : public HardwareSerial {
SerialBT_();

bool setFIFOSize(size_t size);
bool setName(const char *name) {
if (_running) {
return false;
}
free(_name);
_name = strdup(name);
return true;
}

void begin(unsigned long baud = 115200) override {
begin(baud, SERIAL_8N1);
Expand Down Expand Up @@ -82,4 +90,6 @@ class SerialBT_ : public HardwareSerial {

volatile int _writeLen = 0;
const void *_writeBuff;

char *_name = nullptr;
};

0 comments on commit 1f9350d

Please sign in to comment.