Skip to content

Changes made to print and IPAddress #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 13 additions & 0 deletions cores/arduino/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ bool IPAddress::fromString(const char *address)
return true;
}

String IPAddress::toString()
{
String addressString = "";
for (int i =0; i < 3; i++)
{
addressString += String(_address.bytes[i], DEC);
addressString += String('.');
}
addressString += String(_address.bytes[3], DEC);
return addressString;
}


IPAddress& IPAddress::operator=(const uint8_t *address)
{
memcpy(_address.bytes, address, sizeof(_address.bytes));
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class IPAddress : public Printable {
// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address.bytes[index]; };
uint8_t& operator[](int index) { return _address.bytes[index]; };

String toString();

// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Print
size_t print(unsigned long, int = DEC);
size_t print(double, int = 2);
size_t print(const Printable&);
template <typename Arg, typename... Args> size_t print(Arg arg0, Arg arg1, Args... args){ return print(arg0) + print(arg1) + print(args...); }

size_t println(const __FlashStringHelper *);
size_t println(const String &s);
Expand All @@ -86,6 +87,7 @@ class Print
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
template <typename... Args> size_t println(Args... args) { return print(args...) + println(); }

virtual void flush() { /* Empty implementation for backward compatibility */ }
};
Expand Down