Skip to content

Commit ec8b49a

Browse files
authored
Merge pull request #769 from qubitter/master
Add support for Immediate Alert Service
2 parents 211566b + a59ffc5 commit ec8b49a

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/tools/.idea/
1414
/tools/midi_tests/node_modules
1515

16+
.idea/
1617
.DS_Store
1718
*.swp
1819
/Output

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "services/BLEDfu.h"
6363
#include "services/BLEUart.h"
6464
#include "services/BLEBas.h"
65+
#include "services/BLEIas.h"
6566
#include "services/BLEBeacon.h"
6667
#include "services/BLEHidGeneric.h"
6768
#include "services/BLEHidAdafruit.h"
@@ -75,6 +76,7 @@
7576
#include "clients/BLEClientCts.h"
7677
#include "clients/BLEClientHidAdafruit.h"
7778
#include "clients/BLEClientBas.h"
79+
#include "clients/BLEClientIas.h"
7880

7981
#include "utility/AdaCallback.h"
8082
#include "utility/bonding.h"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Created by Charlie Bershatsky on 4/19/23.
3+
//
4+
5+
#include "BLEClientIas.h"
6+
#include "bluefruit.h"
7+
8+
BLEClientIas::BLEClientIas() :
9+
BLEClientService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
10+
11+
}
12+
13+
bool BLEClientIas::begin(void) {
14+
// invoke superclass begin()
15+
BLEClientService::begin();
16+
17+
_alert.begin(this);
18+
19+
return true;
20+
}
21+
22+
bool BLEClientIas::discover(uint16_t conn_handle) {
23+
VERIFY(BLEClientService::discover(conn_handle));
24+
_conn_hdl = conn_handle;
25+
return true;
26+
}
27+
28+
uint16_t BLEClientIas::getAlertLevel() {
29+
30+
uint8_t level = 0;
31+
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange();
32+
33+
_alert.begin(this);
34+
35+
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) {
36+
level = _alert.read8();
37+
}
38+
39+
Bluefruit.Discovery.setHandleRange(bck_range);
40+
41+
return level;
42+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Created by Charlie Bershatsky on 4/19/23.
3+
//
4+
5+
#ifndef ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
6+
#define ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
7+
8+
#include "bluefruit_common.h"
9+
#include "BLEClientCharacteristic.h"
10+
#include "BLEClientService.h"
11+
12+
class BLEClientIas : public BLEClientService {
13+
14+
public:
15+
BLEClientIas(void);
16+
17+
virtual bool begin(void);
18+
virtual bool discover(uint16_t conn_handle);
19+
20+
uint16_t getAlertLevel (void);
21+
22+
private:
23+
BLEClientCharacteristic _alert;
24+
25+
};
26+
27+
28+
#endif //ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Created by Charlie Bershatsky on 4/19/23.
3+
//
4+
5+
#include "BLEIas.h"
6+
#include "bluefruit.h"
7+
#include "utility/utilities.h"
8+
#include "BLEService.h"
9+
10+
BLEIas::BLEIas(void) :
11+
BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {
12+
13+
}
14+
15+
void BLEIas::write(uint8_t alert_level) {
16+
_alert.write8(alert_level);
17+
}
18+
19+
err_t BLEIas::begin(void) {
20+
21+
// Invoke the superclass begin()
22+
VERIFY_STATUS(BLEService::begin());
23+
24+
_alert.setProperties(CHR_PROPS_READ);
25+
_alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
26+
_alert.setFixedLen(1);
27+
28+
VERIFY_STATUS( _alert.begin() );
29+
30+
return ERROR_NONE;
31+
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Created by Charlie Bershatsky on 4/19/23.
3+
//
4+
5+
#ifndef ADAFRUIT_NRF52_ARDUINO_BLEIAS_H
6+
#define ADAFRUIT_NRF52_ARDUINO_BLEIAS_H
7+
8+
#include "bluefruit_common.h"
9+
10+
#include "BLEService.h"
11+
#include "BLECharacteristic.h"
12+
13+
14+
class BLEIas : public BLEService {
15+
16+
protected:
17+
BLECharacteristic _alert;
18+
19+
public:
20+
BLEIas(void);
21+
22+
void write(uint8_t level);
23+
24+
virtual err_t begin(void);
25+
26+
};
27+
28+
29+
#endif //ADAFRUIT_NRF52_ARDUINO_BLEIAS_H

0 commit comments

Comments
 (0)