8000 Common code style · exocode/esp32-snippets@b17e346 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit b17e346

Browse files
committed
Common code style
1 parent 8f106d7 commit b17e346

File tree

138 files changed

+3402
-3910
lines changed

Some content is hidden

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

138 files changed

+3402
-3910
lines changed

cpp_utils/Apa102.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void Apa102::show() {
3737

3838
double brigthnessScale = getBrightness() / 100.0;
3939
// Loop over all the pixels in the pixels array to set the colors.
40-
for (int i=0; i<m_pixelCount; i++) {
40+
for (uint16_t i = 0; i < m_pixelCount; i++) {
4141
mySPI.transferByte(0xff); // Maximum brightness
4242
mySPI.transferByte(m_pixels[i].blue * brigthnessScale);
4343
mySPI.transferByte(m_pixels[i].green * brigthnessScale);

cpp_utils/BLE2902.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "BLE2902.h"
1616

1717
BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) {
18-
uint8_t data[2] = {0,0};
18+
uint8_t data[2] = { 0, 0 };
1919
setValue(data, 2);
2020
} // BLE2902
2121

@@ -44,11 +44,8 @@ bool BLE2902::getIndications() {
4444
*/
4545
void BLE2902::setIndications(bool flag) {
4646
uint8_t *pValue = getValue();
47-
if (flag) {
48-
pValue[0] |= 1<<1;
49-
} else {
50-
pValue[0] &= ~(1<<1);
51-
}
47+
if (flag) pValue[0] |= 1 << 1;
48+
else pValue[0] &= ~(1 << 1);
5249
} // setIndications
5350

5451

@@ -58,12 +55,8 @@ void BLE2902::setIndications(bool flag) {
5855
*/
5956
void BLE2902::setNotifications(bool flag) {
6057
uint8_t *pValue = getValue();
61-
if (flag) {
62-
pValue[0] |= 1<<0;
63-
} else {
64-
pValue[0] &= ~(1<<0);
65-
}
58+
if (flag) pValue[0] |= 1 << 0;
59+
else pValue[0] &= ~(1 << 0);
6660
} // setNotifications
6761

68-
6962
#endif
cpp_utils/BLE2904.cpp
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BLE2904::BLE2904() : BLEDescriptor(BLEUUID((uint16_t) 0x2904)) {
2121
m_data.m_namespace = 1; // 1 = Bluetooth SIG Assigned Numbers
2222
m_data.m_unit = 0;
2323
m_data.m_description = 0;
24-
setValue((uint8_t*)&m_data, sizeof(m_data));
24+
setValue((uint8_t*) &m_data, sizeof(m_data));
2525
} // BLE2902
2626

2727

@@ -30,7 +30,7 @@ BLE2904::BLE2904() : BLEDescriptor(BLEUUID((uint16_t) 0x2904)) {
3030
*/
3131
void BLE2904::setDescription(uint16_t description) {
3232
m_data.m_description = description;
33-
setValue((uint8_t*)&m_data, sizeof(m_data));
33+
setValue((uint8_t*) &m_data, sizeof(m_data));
3434
}
3535

3636

@@ -39,7 +39,7 @@ void BLE2904::setDescription(uint16_t description) {
3939
*/
4040
void BLE2904::setExponent(int8_t exponent) {
4141
m_data.m_exponent = exponent;
42-
setValue((uint8_t*)&m_data, sizeof(m_data));
42+
setValue((uint8_t*) &m_data, sizeof(m_data));
4343
} // setExponent
4444

4545

@@ -48,7 +48,7 @@ void BLE2904::setExponent(int8_t exponent) {
4848
*/
4949
void BLE2904::setFormat(uint8_t format) {
5050
m_data.m_format = format;
51-
setValue((uint8_t*)&m_data, sizeof(m_data));
51+
setValue((uint8_t*) &m_data, sizeof(m_data));
5252
} // setFormat
5353

5454

@@ -57,18 +57,18 @@ void BLE2904::setFormat(uint8_t format) {
5757
*/
5858
void BLE2904::setNamespace(uint8_t namespace_value) {
5959
m_data.m_namespace = namespace_value;
60-
setValue((uint8_t*)&m_data, sizeof(m_data));
60+
setValue((uint8_t*) &m_data, sizeof(m_data));
6161
} // setNamespace
6262

6363

6464
/**
6565
* @brief Set the units for this value. It should be one of the encoded values defined here:
6666
* https://www.bluetooth.com/specifications/assigned-numbers/units
67-
* @param [in] uint The type of units of this characteristic as defined by assigned numbers.
67+
* @param [in] unit The type of units of this characteristic as defined by assigned numbers.
6868
*/
6969
void BLE2904::setUnit(uint16_t unit) {
7070
m_data.m_unit = unit;
71-
setValue((uint8_t*)&m_data, sizeof(m_data));
71+
setValue((uint8_t*) &m_data, sizeof(m_data));
7272
} // setUnit
7373

7474
#endif

cpp_utils/BLEAddress.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,16 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
3939
* @param [in] stringAddress The hex representation of the address.
4040
*/
4141
BLEAddress::BLEAddress(std::string stringAddress) {
42-
if (stringAddress.length() != 17) {
43-
return;
44-
}
42+
if (stringAddress.length() != 17) return;
43+
4544
int data[6];
4645
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
47-
m_address[0] = (uint8_t)data[0];
48-
m_address[1] = (uint8_t)data[1];
49-
m_address[2] = (uint8_t)data[2];
50-
m_address[3] = (uint8_t)data[3];
51-
m_address[4] = (uint8_t)data[4];
52-
m_address[5] = (uint8_t)data[5];
46+
m_address[0] = (uint8_t) data[0];
47+
m_address[1] = (uint8_t) data[1];
48+
m_address[2] = (uint8_t) data[2];
49+
m_address[3] = (uint8_t) data[3];
50+
m_address[4] = (uint8_t) data[4];
51+
m_address[5] = (uint8_t) data[5];
5352
} // BLEAddress
5453

5554

@@ -85,12 +84,12 @@ esp_bd_addr_t *BLEAddress::getNative() {
8584
*/
8685
std::string BLEAddress::toString() {
8786
std::stringstream stream;
88-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[0] << ':';
89-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[1] << ':';
90-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[2] << ':';
91-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[3] << ':';
92-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[4] << ':';
93-
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[5];
87+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[0] << ':';
88+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[1] << ':';
89+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[2] << ':';
90+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[3] << ':';
91+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[4] << ':';
92+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[5];
9493
return stream.str();
9594
} // toString
9695
#endif

cpp_utils/BLEAdvertisedDevice.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ BLEUUID BLEAdvertisedDevice::getServiceUUID() { //TODO Remove it eventually, is
138138
*/
139139
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
140140
for (int i = 0; i < m_serviceUUIDs.size(); i++) {
141-
if(m_serviceUUIDs[i].equals(uuid))
142-
return true;
141+
if (m_serviceUUIDs[i].equals(uuid)) return true;
143142
}
144143
return false;
145144
}
@@ -236,9 +235,9 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
236235
bool finished = false;
237236
setPayload(payload);
238237

239-
while(!finished) {
240238
length = *payload; // Retrieve the length of the record.
241239
payload++; // Skip to type
240+
while (!finished) {
242241
sizeConsumed += 1 + length; // increase the size consumed.
243242

244243
if (length != 0) { // A length of 0 indicates that we have reached the end.
@@ -251,7 +250,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
251250
ad_type, BLEUtils::advTypeToString(ad_type), length, pHex);
252251
free(pHex);
253252

254-
switch(ad_type) {
253+
switch (ad_type) {
255254
case ESP_BLE_AD_TYPE_NAME_CMPL: { // Adv Data Type: 0x09
256255
setName(std::string(reinterpret_cast<char*>(payload), length));
257256
break;
@@ -274,16 +273,16 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
274273

275274
case ESP_BLE_AD_TYPE_16SRV_CMPL:
276275
case ESP_BLE_AD_TYPE_16SRV_PART: { // Adv Data Type: 0x02
277-
for (int var = 0; var < length/2; ++var) {
278-
setServiceUUID(BLEUUID(*reinterpret_cast<uint16_t*>(payload+var*2)));
276+
for (int var = 0; var < length / 2; ++var) {
277+
setServiceUUID(BLEUUID(*reinterpret_cast<uint16_t*>(payload + var * 2)));
279278
}
280279
break;
281280
} // ESP_BLE_AD_TYPE_16SRV_PART
282281

283282
case ESP_BLE_AD_TYPE_32SRV_CMPL:
284283
case ESP_BLE_AD_TYPE_32SRV_PART: { // Adv Data Type: 0x04
285-
for (int var = 0; var < length/4; ++var) {
286-
setServiceUUID(BLEUUID(*reinterpret_cast<uint32_t*>(payload+var*4)));
284+
for (int var = 0; var < length / 4; ++var) {
285+
setServiceUUID(BLEUUID(*reinterpret_cast<uint32_t*>(payload + var * 4)));
287286
}
288287
break;
289288
} // ESP_BLE_AD_TYPE_32SRV_PART
@@ -309,10 +308,10 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
309308
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
310309
break;
311310
}
312-
uint16_t uuid = *(uint16_t *)payload;
311+
uint16_t uuid = *(uint16_t*) payload;
313312
setServiceDataUUID(BLEUUID(uuid));
314313
if (length > 2) {
315-
setServiceData(std::string(reinterpret_cast<char*>(payload+2), length-2));
314+
setServiceData(std::string(reinterpret_cast<char*>(payload + 2), length - 2));
316315
}
317316
break;
318317
} //ESP_BLE_AD_TYPE_SERVICE_DATA
@@ -322,10 +321,10 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
322321
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
323322
break;
324323
}
325-
uint32_t uuid = *(uint32_t *)payload;
324+
uint32_t uuid = *(uint32_t*) payload;
326325
setServiceDataUUID(BLEUUID(uuid));
327326
if (length > 4) {
328-
setServiceData(std::string(reinterpret_cast<char*>(payload+4), length-4));
327+
setServiceData(std::string(reinterpret_cast<char*>(payload + 4), length - 4));
329328
}
330329
break;
331330
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
@@ -336,9 +335,9 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
336335
break;
337336
}
338337

339-
setServiceDataUUID(BLEUUID(payload, (size_t)16, false));
338+
setServiceDataUUID(BLEUUID(payload, (size_t) 16, false));
340339
if (length > 16) {
341-
setServiceData(std::string(reinterpret_cast<char*>(payload+16), length-16));
340+
setServiceData(std::string(reinterpret_cast<char*>(payload + 16), length - 16));
342341
}
343342
break;
344343
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
@@ -352,7 +351,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
352351
} // Length <> 0
353352

354353

355-
if (sizeConsumed >=31 || length == 0) {
354+
if (sizeConsumed >= 31 || length == 0) {
356355
finished = true;
357356
}
358357
} // !finished
@@ -395,7 +394,7 @@ void BLEAdvertisedDevice::setAppearance(uint16_t appearance) {
395394
void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
396395
m_manufacturerData = manufacturerData;
397396
m_haveManufacturerData = true;
398-
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)m_manufacturerData.data(), (uint8_t)m_manufacturerData.length());
397+
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.data(), (uint8_t) m_manufacturerData.length());
399398
ESP_LOGD(LOG_TAG, "- manufacturer data: %s", pHex);
400399
free(pHex);
401400
} // setManufacturerData
@@ -517,4 +516,3 @@ void BLEAdvertisedDevice::setPayload(uint8_t* payload) {
517516

518517

519518
#endif /* CONFIG_BT_ENABLED */
520-

cpp_utils/BLEAdvertisedDevice.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class BLEAdvertisedDevice {
7272
void setTXPower(int8_t txPower);
7373
void setPayload(uint8_t* payload);
7474

75-
7675
bool m_haveAppearance;
7776
bool m_haveManufacturerData;
7877
bool m_haveName;
@@ -82,7 +81,6 @@ class BLEAdvertisedDevice {
8281
bool m_haveTXPower;
8382

8483

85-
BLEAddress m_address = BLEAddress((uint8_t*)"\0\0\0\0\0\0");
8684
uint8_t m_adFlag;
8785
uint16_t m_appearance;
8886
int m_deviceType;
@@ -95,6 +93,7 @@ class BLEAdvertisedDevice {
9593
std::string m_serviceData;
9694
BLEUUID m_serviceDataUUID;
9795
uint8_t* m_payload;
96+
BLEAddress m_address = BLEAddress((uint8_t*) "\0\0\0\0\0\0");
9897
};
9998

10099
/**

0 commit comments

Comments
 (0)
0