Skip to content

Commit

Permalink
Initial RSSI support
Browse files Browse the repository at this point in the history
Untested

Part of:
#42
  • Loading branch information
ricardoquesada committed Feb 4, 2024
1 parent 670c6d5 commit 66753e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/components/bluepad32/bt/uni_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ void uni_bt_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t* packe
if (IS_ENABLED(UNI_ENABLE_BLE))
uni_bt_le_on_gap_event_advertising_report(packet, size);
break;
case GAP_EVENT_RSSI_MEASUREMENT: {
uint8_t rssi = gap_event_rssi_measurement_get_rssi(packet);
hci_con_handle_t conn = gap_event_rssi_measurement_get_con_handle(packet);
uni_hid_device_t* d = uni_hid_device_get_instance_for_connection_handle(conn);
if (!d) {
loge("Could not found device for connection handle: %x\n", conn);
break;
}
d->conn.rssi = rssi;
break;
}
// GATT EVENTS (BLE only)
case GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT:
logd("--> GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT\n");
Expand Down
1 change: 1 addition & 0 deletions src/components/bluepad32/bt/uni_bt_bredr.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ void uni_bt_bredr_on_gap_inquiry_result(uint16_t channel, const uint8_t* packet,
uni_hid_device_set_cod(d, cod);
d->conn.page_scan_repetition_mode = page_scan_repetition_mode;
d->conn.clock_offset = clock_offset | UNI_BT_CLOCK_OFFSET_VALID;
d->conn.rssi = rssi;

if (name_len > 0 && !uni_hid_device_has_name(d)) {
uni_hid_device_set_name(d, name_buffer);
Expand Down
3 changes: 2 additions & 1 deletion src/components/bluepad32/bt/uni_bt_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ static const uint8_t adv_data[] = {
17, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS,
0x63, 0x7F, 0xBF, 0xC1, 0xC5, 0xAF, 0x88, 0xB6, 0xB9, 0x46, 0x00, 0xAC, 0xA4, 0xC4, 0x27, 0x46,
};
_Static_assert(sizeof(adv_data) <= 31, "adv_data too big");
// clang-format on
static int adv_data_len = sizeof(adv_data);
static const int adv_data_len = sizeof(adv_data);

static void att_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t* packet, uint16_t size);
static int att_write_callback(hci_con_handle_t con_handle,
Expand Down
4 changes: 4 additions & 0 deletions src/components/bluepad32/include/bt/uni_bt_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ typedef struct {
uint16_t control_cid;
uint16_t interrupt_cid;

// BR/EDR only
uint8_t page_scan_repetition_mode;
uint16_t clock_offset;

// BLE & BR/EDR
uint8_t rssi;

bool incoming;
bool connected;

Expand Down

0 comments on commit 66753e1

Please sign in to comment.