Skip to content

Commit 0133b05

Browse files
committed
add discover() to client characteristic
- add getHandleRange to client service
1 parent 78b3906 commit 0133b05

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ void BLEClientCharacteristic::disconnect(void)
9191
_chr.handle_value = BLE_GATT_HANDLE_INVALID;
9292
}
9393

94+
95+
bool BLEClientCharacteristic::discover(void)
96+
{
97+
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange();
98+
99+
// Set discovery handle to parent's service
100+
Bluefruit.Discovery.setHandleRange( _service->getHandleRange() );
101+
102+
bool result = Bluefruit.Discovery.discoverCharacteristic( _service->connHandle(), *this) > 0;
103+
104+
// Set back to previous
105+
Bluefruit.Discovery.setHandleRange(bck_range);
106+
107+
return result;
108+
}
109+
110+
bool BLEClientCharacteristic::discovered(void)
111+
{
112+
return _chr.handle_value != BLE_GATT_HANDLE_INVALID;
113+
}
114+
94115
void BLEClientCharacteristic::useAdaCallback(bool enabled)
95116
{
96117
_use_AdaCallback = enabled;
@@ -106,10 +127,7 @@ uint16_t BLEClientCharacteristic::valueHandle(void)
106127
return _chr.handle_value;
107128
}
108129

109-
bool BLEClientCharacteristic::discovered(void)
110-
{
111-
return _chr.handle_value != BLE_GATT_HANDLE_INVALID;
112-
}
130+
113131

114132
uint8_t BLEClientCharacteristic::properties(void)
115133
{

libraries/Bluefruit52Lib/src/BLEClientCharacteristic.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ class BLEClientCharacteristic
6464

6565
void begin(BLEClientService* parent_svc = NULL);
6666

67+
bool discover(void);
68+
bool discovered(void);
69+
6770
uint16_t connHandle(void);
6871
uint16_t valueHandle(void);
69-
bool discovered(void);
7072
uint8_t properties(void);
7173

7274

libraries/Bluefruit52Lib/src/BLEClientService.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ void BLEClientService::setHandleRange(ble_gattc_handle_range_t handle_range)
9696
_hdl_range = handle_range;
9797
}
9898

99-
void BLEClientService::setHandleRange(uint16_t start_hdl, uint16_t end_hdl)
99+
ble_gattc_handle_range_t BLEClientService::getHandleRange(void)
100100
{
101-
_hdl_range.start_handle = start_hdl;
102-
_hdl_range.end_handle = end_hdl;
101+
return _hdl_range;
103102
}
104103

105104
void BLEClientService::disconnect(void)

libraries/Bluefruit52Lib/src/BLEClientService.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ class BLEClientService
6262
bool discovered(void);
6363

6464
uint16_t connHandle(void);
65-
void setHandleRange(uint16_t start_hdl, uint16_t end_hdl);
66-
void setHandleRange(ble_gattc_handle_range_t handle_range);
65+
66+
void setHandleRange(ble_gattc_handle_range_t handle_range);
67+
ble_gattc_handle_range_t getHandleRange(void);
6768

6869
friend class BLEGatt;
6970
};

0 commit comments

Comments
 (0)