added debugging
Fork of BLE_nRF8001 by
Embed:
(wiki syntax)
Show/hide line numbers
BLECentral.cpp
00001 #include "Arduino.h" 00002 00003 #include "BLEPeripheral.h" 00004 00005 #include "BLECentral.h" 00006 00007 BLECentral::BLECentral(BLEPeripheral* peripheral) : 00008 _peripheral(peripheral) 00009 { 00010 this->clearAddress(); 00011 } 00012 00013 BLECentral::operator bool() const { 00014 unsigned char zero[6] = {0, 0, 0, 0, 0, 0}; 00015 00016 return (memcmp(this->_address, zero, sizeof(this->_address)) != 0); 00017 } 00018 00019 bool BLECentral::operator==(const BLECentral& rhs) const { 00020 return (memcmp(this->_address, rhs._address, sizeof(this->_address)) == 0); 00021 } 00022 00023 bool BLECentral::operator!=(const BLECentral& rhs) const { 00024 return !(*this == rhs); 00025 } 00026 00027 bool BLECentral::connected() { 00028 this->poll(); 00029 00030 return (*this && *this == this->_peripheral->central()); 00031 } 00032 00033 const char* BLECentral::address() const { 00034 static char address[18]; 00035 00036 sprintf(address, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", 00037 this->_address[5], 00038 this->_address[4], 00039 this->_address[3], 00040 this->_address[2], 00041 this->_address[1], 00042 this->_address[0]); 00043 00044 return address; 00045 } 00046 00047 void BLECentral::poll() { 00048 this->_peripheral->poll(); 00049 } 00050 00051 void BLECentral::disconnect() { 00052 if (this->connected()) { 00053 this->_peripheral->disconnect(); 00054 } 00055 } 00056 00057 void BLECentral::setAddress(const unsigned char* address) { 00058 memcpy(this->_address, address, sizeof(this->_address)); 00059 } 00060 00061 void BLECentral::clearAddress() { 00062 memset(this->_address, 0x00, sizeof(this->_address)); 00063 }
Generated on Tue Jul 12 2022 15:15:46 by 1.7.2