Skip to content

Commit a59ffc5

Browse files
committed
updated to be more similar to battery service
1 parent 9388e73 commit a59ffc5

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
#include "BLEClientIas.h"
66
#include "bluefruit.h"
77

8-
BLEClientIas::BLEClientIas() : BLEClientService(UUID16_SVC_IMMEDIATE_ALERT) {
8+
BLEClientIas::BLEClientIas() :
9+
BLEClientService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
910

1011
}
1112

1213
bool BLEClientIas::begin(void) {
1314
// invoke superclass begin()
1415
BLEClientService::begin();
16+
17+
_alert.begin(this);
18+
1519
return true;
1620
}
1721

1822
bool BLEClientIas::discover(uint16_t conn_handle) {
1923
VERIFY(BLEClientService::discover(conn_handle));
20-
24+
_conn_hdl = conn_handle;
2125
return true;
2226
}
2327

@@ -26,11 +30,10 @@ uint16_t BLEClientIas::getAlertLevel() {
2630
uint8_t level = 0;
2731
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange();
2832

29-
BLEClientCharacteristic chr(uuid);
30-
chr.begin(this);
33+
_alert.begin(this);
3134

32-
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr)) {
33-
level = chr.read8();
35+
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) {
36+
level = _alert.read8();
3437
}
3538

3639
Bluefruit.Discovery.setHandleRange(bck_range);

libraries/Bluefruit52Lib/src/clients/BLEClientIas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class BLEClientIas : public BLEClientService {
1919

2020
uint16_t getAlertLevel (void);
2121

22+
private:
23+
BLEClientCharacteristic _alert;
24+
2225
};
2326

2427

libraries/Bluefruit52Lib/src/services/BLEIas.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@
77
#include "utility/utilities.h"
88
#include "BLEService.h"
99

10-
BLEIas::BLEIas(void) : BLEService(UUID16_SVC_IMMEDIATE_ALERT) {
10+
BLEIas::BLEIas(void) :
11+
BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
1112

1213
}
1314

14-
void BLEIas::setAlertLevel(uint8_t alert_level) {
15-
_alert_level = alert_level;
15+
void BLEIas::write(uint8_t alert_level) {
16+
_alert.write8(alert_level);
1617
}
1718

1819
err_t BLEIas::begin(void) {
1920

2021
// Invoke the superclass begin()
2122
VERIFY_STATUS(BLEService::begin());
2223

23-
BLECharacteristic chars;
24+
_alert.setProperties(CHR_PROPS_READ);
25+
_alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
26+
_alert.setFixedLen(1);
2427

25-
chars.setUuid(UUID16_CHR_ALERT_LEVEL);
26-
chars.setTempMemory();
27-
chars.setProperties(CHR_PROPS_READ);
28-
chars.setFixedLen(sizeof(_alert_level));
29-
VERIFY_STATUS(chars.begin());
30-
chars.write8(_alert_level);
28+
VERIFY_STATUS( _alert.begin() );
3129

3230
return ERROR_NONE;
3331

libraries/Bluefruit52Lib/src/services/BLEIas.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414
class BLEIas : public BLEService {
1515

1616
protected:
17-
union {
18-
struct {
19-
uint8_t _alert_level; // UUID 0x2A06
20-
};
21-
};
17+
BLECharacteristic _alert;
2218

2319
public:
2420
BLEIas(void);
2521

26-
void setAlertLevel(uint8_t alert_level);
22+
void write(uint8_t level);
2723

2824
virtual err_t begin(void);
2925

0 commit comments

Comments
 (0)