Skip to content

Commit

Permalink
updated to be more similar to battery service
Browse files Browse the repository at this point in the history
  • Loading branch information
qubitter committed Apr 20, 2023
1 parent 9388e73 commit a59ffc5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
15 changes: 9 additions & 6 deletions libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
#include "BLEClientIas.h"
#include "bluefruit.h"

BLEClientIas::BLEClientIas() : BLEClientService(UUID16_SVC_IMMEDIATE_ALERT) {
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;
}

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

BLEClientCharacteristic chr(uuid);
chr.begin(this);
_alert.begin(this);

if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr)) {
level = chr.read8();
if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) {
level = _alert.read8();
}

Bluefruit.Discovery.setHandleRange(bck_range);
Expand Down
3 changes: 3 additions & 0 deletions libraries/Bluefruit52Lib/src/clients/BLEClientIas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class BLEClientIas : public BLEClientService {

uint16_t getAlertLevel (void);

private:
BLEClientCharacteristic _alert;

};


Expand Down
18 changes: 8 additions & 10 deletions libraries/Bluefruit52Lib/src/services/BLEIas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@
#include "utility/utilities.h"
#include "BLEService.h"

BLEIas::BLEIas(void) : BLEService(UUID16_SVC_IMMEDIATE_ALERT) {
BLEIas::BLEIas(void) :
BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) {

}

void BLEIas::setAlertLevel(uint8_t alert_level) {
_alert_level = alert_level;
void BLEIas::write(uint8_t alert_level) {
_alert.write8(alert_level);
}

err_t BLEIas::begin(void) {

// Invoke the superclass begin()
VERIFY_STATUS(BLEService::begin());

BLECharacteristic chars;
_alert.setProperties(CHR_PROPS_READ);
_alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_alert.setFixedLen(1);

chars.setUuid(UUID16_CHR_ALERT_LEVEL);
chars.setTempMemory();
chars.setProperties(CHR_PROPS_READ);
chars.setFixedLen(sizeof(_alert_level));
VERIFY_STATUS(chars.begin());
chars.write8(_alert_level);
VERIFY_STATUS( _alert.begin() );

return ERROR_NONE;

Expand Down
8 changes: 2 additions & 6 deletions libraries/Bluefruit52Lib/src/services/BLEIas.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
class BLEIas : public BLEService {

protected:
union {
struct {
uint8_t _alert_level; // UUID 0x2A06
};
};
BLECharacteristic _alert;

public:
BLEIas(void);

void setAlertLevel(uint8_t alert_level);
void write(uint8_t level);

virtual err_t begin(void);

Expand Down

0 comments on commit a59ffc5

Please sign in to comment.