Skip to content

Commit

Permalink
Merge pull request #769 from qubitter/master
Browse files Browse the repository at this point in the history
Add support for Immediate Alert Service
  • Loading branch information
hathach committed Apr 26, 2023
2 parents 211566b + a59ffc5 commit ec8b49a
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/tools/.idea/
/tools/midi_tests/node_modules

.idea/
.DS_Store
*.swp
/Output
Expand Down
2 changes: 2 additions & 0 deletions libraries/Bluefruit52Lib/src/bluefruit.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "services/BLEDfu.h"
#include "services/BLEUart.h"
#include "services/BLEBas.h"
#include "services/BLEIas.h"
#include "services/BLEBeacon.h"
#include "services/BLEHidGeneric.h"
#include "services/BLEHidAdafruit.h"
Expand All @@ -75,6 +76,7 @@
#include "clients/BLEClientCts.h"
#include "clients/BLEClientHidAdafruit.h"
#include "clients/BLEClientBas.h"
#include "clients/BLEClientIas.h"

#include "utility/AdaCallback.h"
#include "utility/bonding.h"
Expand Down
42 changes: 42 additions & 0 deletions libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp
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;
}
28 changes: 28 additions & 0 deletions libraries/Bluefruit52Lib/src/clients/BLEClientIas.h
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
32 changes: 32 additions & 0 deletions libraries/Bluefruit52Lib/src/services/BLEIas.cpp
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;

}
29 changes: 29 additions & 0 deletions libraries/Bluefruit52Lib/src/services/BLEIas.h
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

0 comments on commit ec8b49a

Please sign in to comment.