Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cores/esp32/MacAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ MacAddress::MacAddress(const String &macstr) {
fromString(macstr.c_str());
}

#ifdef __GXX_EXPERIMENTAL_CXX0X__
MacAddress::MacAddress(std::initializer_list<uint8_t> list) {
size_t size = list.size();
memset(_mac.bytes, 0, sizeof(_mac.bytes));
if (size == 6) {
_type = MAC6;
} else if (size == 8) {
_type = MAC8;
} else {
// Default to MAC6 and keep the rest of the bytes as 0
_type = MAC6;
return;
}

memcpy(_mac.bytes, list.begin(), size);
}
#endif

MacAddress::MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) {
_type = MAC6;
memset(_mac.bytes, 0, sizeof(_mac.bytes));
Expand Down
9 changes: 9 additions & 0 deletions cores/esp32/MacAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <stdint.h>
#include <WString.h>
#include <Printable.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <initializer_list>
#endif

enum MACType {
MAC6,
Expand Down Expand Up @@ -56,6 +59,12 @@ class MacAddress : public Printable {
MacAddress(const char *macstr);
MacAddress(const String &macstr);

#ifdef __GXX_EXPERIMENTAL_CXX0X__
// Initializer list constructor for {0xAA, 0xBB, ...} syntax
// This has higher priority than String conversion, preventing ambiguity
MacAddress(std::initializer_list<uint8_t> list);
#endif

virtual ~MacAddress() {}

bool fromString(const char *buf);
Expand Down
7 changes: 7 additions & 0 deletions cores/esp32/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ String::String(StringSumHelper &&rval) {
init();
move(rval);
}

String::String(std::initializer_list<char> list) {
init();
if (list.size() > 0) {
copy(list.begin(), list.size());
}
}
#endif

String::String(char c) {
Expand Down
4 changes: 4 additions & 0 deletions cores/esp32/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <initializer_list>
#endif

// A pure abstract class forward used as a means to proide a unique pointer type
// but really is never defined.
Expand Down Expand Up @@ -58,6 +61,7 @@ class String {
String(const char *cstr, unsigned int length);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(const uint8_t *cstr, unsigned int length) : String(reinterpret_cast<const char *>(cstr), length) {}
String(std::initializer_list<char> list);
#endif
String(const String &str);
String(const __FlashStringHelper *str) : String(reinterpret_cast<const char *>(str)) {}
Expand Down
Loading