Skip to content

Commit

Permalink
- make BLEHIDPeripheral extend BLEPeripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Jun 3, 2015
1 parent 45adbcb commit 2e5a8d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
48 changes: 10 additions & 38 deletions BLEHIDPeripheral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static const PROGMEM unsigned char hidInformationCharacteriticValue[] = { 0x11
BLEHIDPeripheral* BLEHIDPeripheral::_instance = NULL;

BLEHIDPeripheral::BLEHIDPeripheral(unsigned char req, unsigned char rdy, unsigned char rst) :
_blePeripheral(req, rdy, rst),
BLEPeripheral(req, rdy, rst),
_bleBondStore(),

_hidService("1812"),
Expand All @@ -32,14 +32,14 @@ BLEHIDPeripheral* BLEHIDPeripheral::instance() {
}

void BLEHIDPeripheral::begin() {
this->_blePeripheral.setBondStore(this->_bleBondStore);
this->setBondStore(this->_bleBondStore);

this->_blePeripheral.setAdvertisedServiceUuid(this->_hidService.uuid());
this->setAdvertisedServiceUuid(this->_hidService.uuid());

this->_blePeripheral.addAttribute(this->_hidService);
this->_blePeripheral.addAttribute(this->_hidInformationCharacteristic);
this->_blePeripheral.addAttribute(this->_hidControlPointCharacteristic);
this->_blePeripheral.addAttribute(this->_hidReportMapCharacteristic);
this->addAttribute(this->_hidService);
this->addAttribute(this->_hidInformationCharacteristic);
this->addAttribute(this->_hidControlPointCharacteristic);
this->addAttribute(this->_hidReportMapCharacteristic);

for (int i = 0; i < this->_numHids; i++) {
BLEHID *hid = this->_hids[i];
Expand All @@ -48,46 +48,22 @@ void BLEHIDPeripheral::begin() {
BLELocalAttribute** attributes = hid->attributes();

for (int j = 0; j < numAttributes; j++) {
this->_blePeripheral.addAttribute(*attributes[j]);
this->addAttribute(*attributes[j]);
}
}

this->_hidReportMapCharacteristic.setHids(this->_hids, this->_numHids);

// begin initialization
this->_blePeripheral.begin();
BLEPeripheral::begin();
}

void BLEHIDPeripheral::clearBondStoreData() {
this->_bleBondStore.clearData();
}

void BLEHIDPeripheral::setLocalName(const char *localName) {
this->_blePeripheral.setLocalName(localName);
}

void BLEHIDPeripheral::setDeviceName(const char* deviceName) {
this->_blePeripheral.setDeviceName(deviceName);
}

void BLEHIDPeripheral::setAppearance(unsigned short appearance) {
this->_blePeripheral.setAppearance(appearance);
}

void BLEHIDPeripheral::setReportIdOffset(unsigned char reportIdOffset) {
this->_reportIdOffset = reportIdOffset;
}

BLECentral BLEHIDPeripheral::central() {
return this->_blePeripheral.central();
}

bool BLEHIDPeripheral::connected() {
return this->_blePeripheral.connected();
}

void BLEHIDPeripheral::poll() {
this->_blePeripheral.poll();
BLEPeripheral::poll();
}

void BLEHIDPeripheral::addHID(BLEHID& hid) {
Expand All @@ -100,7 +76,3 @@ void BLEHIDPeripheral::addHID(BLEHID& hid) {
this->_hids[this->_numHids] = &hid;
this->_numHids++;
}

void BLEHIDPeripheral::addAttribute(BLELocalAttribute& attribute) {
this->_blePeripheral.addAttribute(attribute);
}
9 changes: 1 addition & 8 deletions BLEHIDPeripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "BLEHIDReportMapCharacteristic.h"
#include "BLEPeripheral.h"

class BLEHIDPeripheral
class BLEHIDPeripheral : public BLEPeripheral
{
friend class BLEHID;

Expand All @@ -16,25 +16,18 @@ class BLEHIDPeripheral
void begin();

void clearBondStoreData();
void setLocalName(const char *localName);
void setDeviceName(const char* deviceName);
void setAppearance(unsigned short appearance);
void setReportIdOffset(unsigned char reportIdOffset);

BLECentral central();
bool connected();
void poll();

void addHID(BLEHID& hid);
void addAttribute(BLELocalAttribute& attribute);

protected:
static BLEHIDPeripheral* instance();

private:
static BLEHIDPeripheral* _instance;

BLEPeripheral _blePeripheral;
BLEBondStore _bleBondStore;

BLEService _hidService;
Expand Down

0 comments on commit 2e5a8d4

Please sign in to comment.