updated to be more similar to battery service

This commit is contained in:
Charlie B committed 2023-04-20 03:07:28 -04:00
1 parent 9388e7358c
commit a59ffc545c
4 files changed
+22 -22

No files matched your search

@@ -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;
}
@@ -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);
@@ -19,6 +19,9 @@ public:
uint16_t getAlertLevel (void);
private:
BLEClientCharacteristic _alert;
};
@@ -7,12 +7,13 @@
#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) {
@@ -20,14 +21,11 @@ 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;
@@ -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);