-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from qubitter/master
Add support for Immediate Alert Service
- Loading branch information
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
/tools/.idea/ | ||
/tools/midi_tests/node_modules | ||
|
||
.idea/ | ||
.DS_Store | ||
*.swp | ||
/Output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Created by Charlie Bershatsky on 4/19/23. | ||
// | ||
|
||
#include "BLEClientIas.h" | ||
#include "bluefruit.h" | ||
|
||
BLEClientIas::BLEClientIas() : | ||
BLEClientService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) { | ||
|
||
} | ||
|
||
bool BLEClientIas::begin(void) { | ||
// invoke superclass begin() | ||
BLEClientService::begin(); | ||
|
||
_alert.begin(this); | ||
|
||
return true; | ||
} | ||
|
||
bool BLEClientIas::discover(uint16_t conn_handle) { | ||
VERIFY(BLEClientService::discover(conn_handle)); | ||
_conn_hdl = conn_handle; | ||
return true; | ||
} | ||
|
||
uint16_t BLEClientIas::getAlertLevel() { | ||
|
||
uint8_t level = 0; | ||
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange(); | ||
|
||
_alert.begin(this); | ||
|
||
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) { | ||
level = _alert.read8(); | ||
} | ||
|
||
Bluefruit.Discovery.setHandleRange(bck_range); | ||
|
||
return level; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Created by Charlie Bershatsky on 4/19/23. | ||
// | ||
|
||
#ifndef ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H | ||
#define ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H | ||
|
||
#include "bluefruit_common.h" | ||
#include "BLEClientCharacteristic.h" | ||
#include "BLEClientService.h" | ||
|
||
class BLEClientIas : public BLEClientService { | ||
|
||
public: | ||
BLEClientIas(void); | ||
|
||
virtual bool begin(void); | ||
virtual bool discover(uint16_t conn_handle); | ||
|
||
uint16_t getAlertLevel (void); | ||
|
||
private: | ||
BLEClientCharacteristic _alert; | ||
|
||
}; | ||
|
||
|
||
#endif //ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Created by Charlie Bershatsky on 4/19/23. | ||
// | ||
|
||
#include "BLEIas.h" | ||
#include "bluefruit.h" | ||
#include "utility/utilities.h" | ||
#include "BLEService.h" | ||
|
||
BLEIas::BLEIas(void) : | ||
BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) { | ||
|
||
} | ||
|
||
void BLEIas::write(uint8_t alert_level) { | ||
_alert.write8(alert_level); | ||
} | ||
|
||
err_t BLEIas::begin(void) { | ||
|
||
// Invoke the superclass begin() | ||
VERIFY_STATUS(BLEService::begin()); | ||
|
||
_alert.setProperties(CHR_PROPS_READ); | ||
_alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); | ||
_alert.setFixedLen(1); | ||
|
||
VERIFY_STATUS( _alert.begin() ); | ||
|
||
return ERROR_NONE; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by Charlie Bershatsky on 4/19/23. | ||
// | ||
|
||
#ifndef ADAFRUIT_NRF52_ARDUINO_BLEIAS_H | ||
#define ADAFRUIT_NRF52_ARDUINO_BLEIAS_H | ||
|
||
#include "bluefruit_common.h" | ||
|
||
#include "BLEService.h" | ||
#include "BLECharacteristic.h" | ||
|
||
|
||
class BLEIas : public BLEService { | ||
|
||
protected: | ||
BLECharacteristic _alert; | ||
|
||
public: | ||
BLEIas(void); | ||
|
||
void write(uint8_t level); | ||
|
||
virtual err_t begin(void); | ||
|
||
}; | ||
|
||
|
||
#endif //ADAFRUIT_NRF52_ARDUINO_BLEIAS_H |