8000 Addition of MFRC522 support · highwalker/esp32-snippets@882f152 · GitHub
[go: up one dir, main page]

Skip to content

Commit 882f152

Browse files
committed
Addition of MFRC522 support
1 parent f10d048 commit 882f152

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2432
-295
lines changed

cpp_utils/BLE.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ BLEClient *BLE::m_pClient = nullptr;
3333

3434
#include <esp_gattc_api.h>
3535

36-
BLE::BLE() {
37-
}
38-
39-
40-
BLE::~BLE() {
41-
}
42-
4336

4437
BLEClient* BLE::createClient() {
4538
m_pClient = new BLEClient();

cpp_utils/BLE.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
class BLE {
2626
public:
27-
BLE();
28-
virtual ~BLE();
2927
static void dumpDevices();
3028
static BLEClient *createClient();
3129

cpp_utils/BLE2902.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) {
1919
setValue(data, 2);
2020
}
2121

22-
BLE2902::~BLE2902() {
23-
}
24-
2522
/**
2623
* @brief Set the notifications flag.
2724
* @param [in] flag The notifications flag.

cpp_utils/BLE2902.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
class BLE2902: public BLEDescriptor {
2525
public:
2626
BLE2902();
27-
virtual ~BLE2902();
2827
void setNotifications(bool flag);
2928
void setIndications(bool flag);
3029
}; // BLE2902

cpp_utils/BLEAddress.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ BLEAddress::BLEAddress(std::string stringAddress) {
4949
} // BLEAddress
5050

5151

52-
BLEAddress::~BLEAddress() {
53-
} // ~BLEAddress
54-
5552
/**
5653
* @brief Determine if this address equals another.
5754
* @param [in] otherAddress The other address to compare against.

cpp_utils/BLEAddress.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class BLEAddress {
1616
public:
1717
BLEAddress(esp_bd_addr_t address);
1818
BLEAddress(std::string stringAddress);
19-
virtual ~BLEAddress();
2019
bool equals(BLEAddress otherAddress);
2120
esp_bd_addr_t* getNative();
2221
std::string toString();

cpp_utils/BLEAdvertisedDevice.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
3939
} // BLEAdvertisedDevice
4040

4141

42-
BLEAdvertisedDevice::~BLEAdvertisedDevice() {
43-
}
44-
45-
4642
/**
4743
* @brief Get the address.
4844
* @return The address of the advertised device.

cpp_utils/BLEAdvertisedDevice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class BLEScan;
2222
class BLEAdvertisedDevice {
2323
public:
2424
BLEAdvertisedDevice();
25-
virtual ~BLEAdvertisedDevice();
2625

2726
BLEAddress getAddress();
2827
uint16_t getApperance();

cpp_utils/BLEAdvertisedDeviceCallbacks.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,4 @@
88
#if defined(CONFIG_BT_ENABLED)
99

1010
#include "BLEAdvertisedDeviceCallbacks F42D .h"
11-
12-
BLEAdvertisedDeviceCallbacks::BLEAdvertisedDeviceCallbacks() {
13-
}
14-
15-
BLEAdvertisedDeviceCallbacks::~BLEAdvertisedDeviceCallbacks() {
16-
}
1711
#endif /* CONFIG_BT_ENABLED */

cpp_utils/BLEAdvertisedDeviceCallbacks.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class BLEAdvertisedDevice;
1414

1515
class BLEAdvertisedDeviceCallbacks {
1616
public:
17-
BLEAdvertisedDeviceCallbacks();
18-
virtual ~BLEAdvertisedDeviceCallbacks();
17+
virtual ~BLEAdvertisedDeviceCallbacks() {}
1918
virtual void onResult(BLEAdvertisedDevice *pAdvertisedDevice) = 0;
2019
};
2120
#endif /* CONFIG_BT_ENABLED */

cpp_utils/BLEAdvertising.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ BLEAdvertising::BLEAdvertising() {
4444
} // BLEAdvertising
4545

4646

47-
BLEAdvertising::~BLEAdvertising() {
48-
} // ~BLEAdvertising
49-
50-
51-
5247
/**
5348
* @brief Set the device appearance in the advertising data.
5449
* The appearance attribute is of type 0x19. The codes for distinct appearances can be found here:

cpp_utils/BLEAdvertising.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
class BLEAdvertising {
1515
public:
1616
BLEAdvertising();
17-
virtual ~BLEAdvertising();
1817
void start();
1918
void stop();
2019
void setAppearance(uint16_t appearance);

cpp_utils/BLECharacteristicCallbacks.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
#include <esp_log.h>
1111
static char LOG_TAG[] = "BLECharacteristicCallbacks";
1212

13-
BLECharacteristicCallbacks::BLECharacteristicCallbacks() {
14-
}
1513

16-
BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {
17-
}
14+
BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {}
1815

1916
/**
2017
* @brief Callback function to support a read request.

cpp_utils/BLECharacteristicCallbacks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class BLECharacteristic;
1414

1515
class BLECharacteristicCallbacks {
1616
public:
17-
BLECharacteristicCallbacks();
1817
virtual ~BLECharacteristicCallbacks();
1918
virtual void onRead(BLECharacteristic *pCharacteristic);
2019
virtual void onWrite(BLECharacteristic *pCharacteristic);

cpp_utils/BLECharacteristicMap.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
#include <iomanip>
1111
#include "BLECharacteristicMap.h"
1212

13-
BLECharacteristicMap::BLECharacteristicMap() {
14-
}
15-
16-
BLECharacteristicMap::~BLECharacteristicMap() {
17-
}
18-
1913

2014
/**
2115
* @brief Return the characteristic by UUID.

cpp_utils/BLECharacteristicMap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
class BLECharacteristicMap {
1616
public:
17-
BLECharacteristicMap();
18-
virtual ~BLECharacteristicMap();
1917
void setByUUID(BLEUUID uuid, BLECharacteristic *characteristic);
2018
void setByHandle(uint16_t handle, BLECharacteristic *characteristic);
2119
BLECharacteristic *getByUUID(BLEUUID uuid);

cpp_utils/BLEClient.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ BLEClient::BLEClient() {
4848
m_haveServices = false;
4949
} // BLEClient
5050

51-
BLEClient::~BLEClient() {
52-
ESP_LOGD(LOG_TAG, "BLEClient object destroyed");
53-
} // ~BLEClient
54-
5551
/**
5652
* @brief Connect to the partner.
5753
* @param [in] address The address of the partner.
@@ -143,6 +139,7 @@ void BLEClient::gattClientEventHandler(
143139
break;
144140
} // ESP_GATTC_REG_EVT
145141

142+
146143
//
147144
// ESP_GATTC_SEARCH_CMPL_EVT
148145
//
@@ -170,6 +167,7 @@ void BLEClient::gattClientEventHandler(
170167
break;
171168
} // ESP_GATTC_SEARCH_RES_EVT
172169

170+
173171
default: {
174172
break;
175173
}
@@ -221,6 +219,7 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) {
221219
return nullptr;
222220
} // getService
223221

222+
224223
/**
225224
* @brief Ask the remote BLE server for its services.
226225
* A BLE Server exposes a set of services for its partners. Here we ask the server for its set of

cpp_utils/BLEClient.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class BLEClientCallbacks;
2929
class BLEClient {
3030
public:
3131
BLEClient();
32-
virtual ~BLEClient();
33-
34-
3532
void connect(BLEAddress address);
3633
void disconnect();
3734

cpp_utils/BLEClientCallbacks.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
#include <esp_log.h>
1111
static const char LOG_TAG[] = "BLEClientCallbacks";
1212

13-
BLEClientCallbacks::BLEClientCallbacks() {
14-
// TODO Auto-generated constructor stub
15-
16-
}
17-
18-
BLEClientCallbacks::~BLEClientCallbacks() {
19-
// TODO Auto-generated destructor stub
20-
}
21-
2213
void BLEClientCallbacks::onConnect(BLEClient* pClient) {
2314
ESP_LOGD(LOG_TAG, ">> onConnect(): Default");
2415
ESP_LOGD(LOG_TAG, "<< onConnect()");

cpp_utils/BLEClientCallbacks.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
class BLEClient;
1515
class BLEClientCallbacks {
1616
public:
17-
BLEClientCallbacks();
18-
virtual ~BLEClientCallbacks();
17+
virtual ~BLEClientCallbacks() {};
1918
virtual void onConnect(BLEClient *pClient);
2019
};
2120
#endif /* CONFIG_BT_ENABLED */

cpp_utils/BLEDesciptorMap.cpp renamed to cpp_utils/BLEDescriptorMap.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
#include "BLEDescriptor.h"
1313
#include <esp_gatts_api.h> // ESP32 BLE
1414

15-
BLEDescriptorMap::BLEDescriptorMap() {
16-
}
17-
18-
BLEDescriptorMap::~BLEDescriptorMap() {
19-
}
20-
21-
2215
/**
2316
* @brief Return the descriptor by UUID.
2417
* @param [in] UUID The UUID to look up the descriptor.

cpp_utils/BLERemoteCharacteristic.cpp

Lines changed: 29 additions & 6 deletions
< F438 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ static bool compareGattId(esp_gatt_id_t id1, esp_gatt_id_t id2) {
5353
} // compareCharId
5454

5555

56-
BLERemoteCharacteristic::~BLERemoteCharacteristic() {
57-
}
58-
59-
6056
/**
61-
* @brief Handle GATT Client events
57+
* @brief Handle GATT Client events.
58+
* When an event arrives for a GATT client we give this characteristic the opportunity to
59+
* take a look at it to see if there is interest in it.
60+
* @param [in] event The type of event.
61+
* @param [in] gattc_if The interface on which the event was received.
62+
* @param [in] evtParam Payload data for the event.
63+
* @returns N/A
6264
*/
6365
void BLERemoteCharacteristic::gattClientEventHandler(
6466
esp_gattc_cb_event_t event,
@@ -67,6 +69,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(
6769
switch(event) {
6870
//
6971
// ESP_GATTC_READ_CHAR_EVT
72+
// This event indicates that the server has responded to the read request.
7073
//
7174
// read:
7275
// esp_gatt_status_t status
@@ -81,13 +84,18 @@ void BLERemoteCharacteristic::gattClientEventHandler(
8184
if (compareSrvcId(evtParam->read.srvc_id, *m_pRemoteService->getSrvcId()) == false) {
8285
break;
8386
}
87+
8488
if (evtParam->read.conn_id != m_pRemoteService->getClient()->getConnId()) {
8589
break;
8690
}
91+
8792
if (compareGattId(evtParam->read.char_id, m_charId) == false) {
8893
break;
8994
}
90-
m_value = std::string((char*)evtParam->read.value, evtParam->read.value_len);
95+
96+
if (evtParam->read.status == ESP_GATT_OK) {
97+
m_value = std::string((char*)evtParam->read.value, evtParam->read.value_len);
98+
}
9199
m_semaphoreReadCharEvt.give();
92100
break;
93101
} // ESP_GATTC_READ_CHAR_EVT
@@ -186,19 +194,24 @@ uint8_t BLERemoteCharacteristic::readUInt8(void) {
186194
*/
187195
std::string BLERemoteCharacteristic::readValue() {
188196
ESP_LOGD(LOG_TAG, ">> readValue()");
197+
189198
m_semaphoreReadCharEvt.take("readValue");
199+
190200
esp_err_t errRc = ::esp_ble_gattc_read_char(
191201
m_pRemoteService->getClient()->getGattcIf(),
192202
m_pRemoteService->getClient()->getConnId(),
193203
m_pRemoteService->getSrvcId(),
194204
&m_charId,
195205
ESP_GATT_AUTH_REQ_NONE);
206+
196207
if (errRc != ESP_OK) {
197208
ESP_LOGE(LOG_TAG, "esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
198209
return "";
199210
}
211+
200212
m_semaphoreReadCharEvt.take("readValue");
201213
m_semaphoreReadCharEvt.give();
214+
202215
ESP_LOGD(LOG_TAG, "<< readValue()");
203216
return m_value;
204217
} // readValue
@@ -210,18 +223,23 @@ std::string BLERemoteCharacteristic::readValue() {
210223
*/
211224
void BLERemoteCharacteristic::registerForNotify() {
212225
ESP_LOGD(LOG_TAG, ">> registerForNotify()");
226+
213227
m_semaphoreRegForNotifyEvt.take("registerForNotify");
228+
214229
esp_err_t errRc = ::esp_ble_gattc_register_for_notify(
215230
m_pRemoteService->getClient()->getGattcIf(),
216231
*m_pRemoteService->getClient()->getAddress().getNative(),
217232
m_pRemoteService->getSrvcId(),
218233
&m_charId);
234+
219235
if (errRc != ESP_OK) {
220236
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
221237
return;
222238
}
239+
223240
m_semaphoreRegForNotifyEvt.take("registerForNotify");
224241
m_semaphoreRegForNotifyEvt.give();
242+
225243
ESP_LOGD(LOG_TAG, "<< registerForNotify()");
226244
} // registerForNotify
227245

@@ -246,7 +264,9 @@ std::string BLERemoteCharacteristic::toString() {
246264
*/
247265
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
248266
ESP_LOGD(LOG_TAG, ">> writeValue(), length: %d", newValue.length());
267+
249268
m_semaphoreWriteCharEvt.take("writeValue");
269+
250270
esp_err_t errRc = ::esp_ble_gattc_write_char(
251271
m_pRemoteService->getClient()->getGattcIf(),
252272
m_pRemoteService->getClient()->getConnId(),
@@ -257,12 +277,15 @@ void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
257277
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
258278
ESP_GATT_AUTH_REQ_NONE
259279
);
280+
260281
if (errRc != ESP_OK) {
261282
ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
262283
return;
263284
}
285+
264286
m_semaphoreWriteCharEvt.take("writeValue");
265287
m_semaphoreWriteCharEvt.give();
288+
266289
ESP_LOGD(LOG_TAG, "<< writeValue()");
267290
} // writeValue
268291

cpp_utils/BLERemoteCharacteristic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class BLERemoteService;
2121

2222
class BLERemoteCharacteristic {
2323
public:
24-
BLERemoteCharacteristic(esp_gatt_id_t charId, esp_gatt_char_prop_t charProp, BLERemoteService *pRemoteService);
25-
virtual ~BLERemoteCharacteristic();
24+
BLERemoteCharacteristic(esp_gatt_id_t charId, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
2625

2726
// Public member functions
2827
std::string readValue(void);

cpp_utils/BLERemoteDescriptor.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@
88
#if defined(CONFIG_BT_ENABLED)
99
#include "BLERemoteDescriptor.h"
1010

11-
BLERemoteDescriptor::BLERemoteDescriptor() {
12-
// TODO Auto-generated constructor stub
13-
14-
}
15-
16-
BLERemoteDescriptor::~BLERemoteDescriptor() {
17-
// TODO Auto-generated destructor stub
18-
}
19-
2011
#endif /* CONFIG_BT_ENABLED */

0 commit comments

Comments
 (0)
0