forked from khoih-prog/AsyncHTTPRequest_Generic
Update Packages' Patches
This commit is contained in:
1730
Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.8.0/boards.txt
Normal file
1730
Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.8.0/boards.txt
Normal file
File diff suppressed because it is too large
Load Diff
1751
Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt
Normal file
1751
Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -40,124 +40,126 @@
|
||||
// or a time out occurs due to lack of input.
|
||||
enum LookaheadMode
|
||||
{
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
};
|
||||
|
||||
#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
protected:
|
||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||
unsigned long _startMillis = 0; // used for timeout measurement
|
||||
int timedRead(); // read stream with timeout
|
||||
int timedPeek(); // peek stream with timeout
|
||||
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||
protected:
|
||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||
unsigned long _startMillis = 0; // used for timeout measurement
|
||||
int timedRead(); // read stream with timeout
|
||||
int timedPeek(); // peek stream with timeout
|
||||
int peekNextDigit(LookaheadMode lookahead,
|
||||
bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
|
||||
// parsing methods
|
||||
// parsing methods
|
||||
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate,
|
||||
size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
// lookahead determines how parseInt looks ahead in the stream.
|
||||
// See LookaheadMode enumeration at the top of the file.
|
||||
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
// lookahead determines how parseInt looks ahead in the stream.
|
||||
// See LookaheadMode enumeration at the top of the file.
|
||||
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||
|
||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// float version of parseInt
|
||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// float version of parseInt
|
||||
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
// Arduino String functions to be added here
|
||||
String readString();
|
||||
String readStringUntil(char terminator);
|
||||
// Arduino String functions to be added here
|
||||
String readString();
|
||||
String readStringUntil(char terminator);
|
||||
|
||||
protected:
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
protected:
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
};
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
};
|
||||
|
||||
// This allows you to search for an arbitrary number of strings.
|
||||
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||
int findMulti(struct MultiTarget *targets, int tCount);
|
||||
// This allows you to search for an arbitrary number of strings.
|
||||
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||
int findMulti(struct MultiTarget *targets, int tCount);
|
||||
};
|
||||
|
||||
#undef NO_IGNORE_CHAR
|
||||
|
||||
@@ -40,124 +40,126 @@
|
||||
// or a time out occurs due to lack of input.
|
||||
enum LookaheadMode
|
||||
{
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
};
|
||||
|
||||
#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
protected:
|
||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||
unsigned long _startMillis = 0; // used for timeout measurement
|
||||
int timedRead(); // read stream with timeout
|
||||
int timedPeek(); // peek stream with timeout
|
||||
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||
protected:
|
||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||
unsigned long _startMillis = 0; // used for timeout measurement
|
||||
int timedRead(); // read stream with timeout
|
||||
int timedPeek(); // peek stream with timeout
|
||||
int peekNextDigit(LookaheadMode lookahead,
|
||||
bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
|
||||
// parsing methods
|
||||
// parsing methods
|
||||
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate,
|
||||
size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
// lookahead determines how parseInt looks ahead in the stream.
|
||||
// See LookaheadMode enumeration at the top of the file.
|
||||
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
// lookahead determines how parseInt looks ahead in the stream.
|
||||
// See LookaheadMode enumeration at the top of the file.
|
||||
// Lookahead is terminated by the first character that is not a valid part of an integer.
|
||||
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||
|
||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// float version of parseInt
|
||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// float version of parseInt
|
||||
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
// Arduino String functions to be added here
|
||||
String readString();
|
||||
String readStringUntil(char terminator);
|
||||
// Arduino String functions to be added here
|
||||
String readString();
|
||||
String readStringUntil(char terminator);
|
||||
|
||||
protected:
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
protected:
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
};
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
};
|
||||
|
||||
// This allows you to search for an arbitrary number of strings.
|
||||
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||
int findMulti(struct MultiTarget *targets, int tCount);
|
||||
// This allows you to search for an arbitrary number of strings.
|
||||
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||
int findMulti(struct MultiTarget *targets, int tCount);
|
||||
};
|
||||
|
||||
#undef NO_IGNORE_CHAR
|
||||
|
||||
@@ -160,26 +160,26 @@ extern "C" {
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
|
||||
#endif /* _VARIANT_ARDUINO_STM32_ */
|
||||
|
||||
@@ -120,26 +120,26 @@ extern "C" {
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
|
||||
#endif /* _VARIANT_ARDUINO_STM32_ */
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PB0
|
||||
#define LED_BUILTIN PB0
|
||||
#endif
|
||||
#define LED_GREEN LED_BUILTIN
|
||||
#define LED_BLUE PB7
|
||||
@@ -196,29 +196,29 @@
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PC13
|
||||
#define USER_BTN PC13
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM7
|
||||
#define TIMER_SERVO TIM7
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#endif
|
||||
// Serial pin used for console (ex: stlink)
|
||||
// Rerquired by Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#endif
|
||||
|
||||
// Value of the External oscillator in Hz
|
||||
@@ -226,16 +226,16 @@
|
||||
|
||||
/* Extra HAL modules */
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||
@@ -248,27 +248,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -75,71 +75,71 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// SPI definitions
|
||||
#ifndef PIN_SPI_SS
|
||||
#define PIN_SPI_SS PA4
|
||||
#define PIN_SPI_SS PA4
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS1
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS2
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS3
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_MOSI
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#endif
|
||||
#ifndef PIN_SPI_MISO
|
||||
#define PIN_SPI_MISO PA6
|
||||
#define PIN_SPI_MISO PA6
|
||||
#endif
|
||||
#ifndef PIN_SPI_SCK
|
||||
#define PIN_SPI_SCK PA5
|
||||
#define PIN_SPI_SCK PA5
|
||||
#endif
|
||||
|
||||
// I2C definitions
|
||||
#ifndef PIN_WIRE_SDA
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#endif
|
||||
#ifndef PIN_WIRE_SCL
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM21
|
||||
#define TIMER_SERVO TIM21
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#endif
|
||||
|
||||
// Default pin used for generic 'Serial' instance
|
||||
// Mandatory for Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#endif
|
||||
|
||||
// Extra HAL modules
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -147,27 +147,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PB0
|
||||
#define LED_BUILTIN PB0
|
||||
#endif
|
||||
#define LED_GREEN LED_BUILTIN
|
||||
#define LED_BLUE PB7
|
||||
@@ -196,29 +196,29 @@
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PC13
|
||||
#define USER_BTN PC13
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM7
|
||||
#define TIMER_SERVO TIM7
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#endif
|
||||
// Serial pin used for console (ex: stlink)
|
||||
// Rerquired by Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#endif
|
||||
|
||||
// Value of the External oscillator in Hz
|
||||
@@ -226,16 +226,16 @@
|
||||
|
||||
/* Extra HAL modules */
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||
@@ -248,27 +248,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -75,71 +75,71 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// SPI definitions
|
||||
#ifndef PIN_SPI_SS
|
||||
#define PIN_SPI_SS PA4
|
||||
#define PIN_SPI_SS PA4
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS1
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS2
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS3
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_MOSI
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#endif
|
||||
#ifndef PIN_SPI_MISO
|
||||
#define PIN_SPI_MISO PA6
|
||||
#define PIN_SPI_MISO PA6
|
||||
#endif
|
||||
#ifndef PIN_SPI_SCK
|
||||
#define PIN_SPI_SCK PA5
|
||||
#define PIN_SPI_SCK PA5
|
||||
#endif
|
||||
|
||||
// I2C definitions
|
||||
#ifndef PIN_WIRE_SDA
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#endif
|
||||
#ifndef PIN_WIRE_SCL
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM21
|
||||
#define TIMER_SERVO TIM21
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#endif
|
||||
|
||||
// Default pin used for generic 'Serial' instance
|
||||
// Mandatory for Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#endif
|
||||
|
||||
// Extra HAL modules
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -147,27 +147,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PB0
|
||||
#define LED_BUILTIN PB0
|
||||
#endif
|
||||
#define LED_GREEN LED_BUILTIN
|
||||
#define LED_BLUE PB7
|
||||
@@ -196,29 +196,29 @@
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PC13
|
||||
#define USER_BTN PC13
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM7
|
||||
#define TIMER_SERVO TIM7
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#endif
|
||||
// Serial pin used for console (ex: stlink)
|
||||
// Rerquired by Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#endif
|
||||
|
||||
// Value of the External oscillator in Hz
|
||||
@@ -226,16 +226,16 @@
|
||||
|
||||
/* Extra HAL modules */
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||
@@ -248,27 +248,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -75,71 +75,71 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// SPI definitions
|
||||
#ifndef PIN_SPI_SS
|
||||
#define PIN_SPI_SS PA4
|
||||
#define PIN_SPI_SS PA4
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS1
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS2
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS3
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_MOSI
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#endif
|
||||
#ifndef PIN_SPI_MISO
|
||||
#define PIN_SPI_MISO PA6
|
||||
#define PIN_SPI_MISO PA6
|
||||
#endif
|
||||
#ifndef PIN_SPI_SCK
|
||||
#define PIN_SPI_SCK PA5
|
||||
#define PIN_SPI_SCK PA5
|
||||
#endif
|
||||
|
||||
// I2C definitions
|
||||
#ifndef PIN_WIRE_SDA
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#endif
|
||||
#ifndef PIN_WIRE_SCL
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM21
|
||||
#define TIMER_SERVO TIM21
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#endif
|
||||
|
||||
// Default pin used for generic 'Serial' instance
|
||||
// Mandatory for Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#endif
|
||||
|
||||
// Extra HAL modules
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -147,27 +147,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PB0
|
||||
#define LED_BUILTIN PB0
|
||||
#endif
|
||||
#define LED_GREEN LED_BUILTIN
|
||||
#define LED_BLUE PB7
|
||||
@@ -196,29 +196,29 @@
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PC13
|
||||
#define USER_BTN PC13
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM7
|
||||
#define TIMER_SERVO TIM7
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#endif
|
||||
// Serial pin used for console (ex: stlink)
|
||||
// Rerquired by Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#endif
|
||||
|
||||
// Value of the External oscillator in Hz
|
||||
@@ -226,16 +226,16 @@
|
||||
|
||||
/* Extra HAL modules */
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||
@@ -248,27 +248,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -75,71 +75,71 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// SPI definitions
|
||||
#ifndef PIN_SPI_SS
|
||||
#define PIN_SPI_SS PA4
|
||||
#define PIN_SPI_SS PA4
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS1
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS2
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS3
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_MOSI
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#endif
|
||||
#ifndef PIN_SPI_MISO
|
||||
#define PIN_SPI_MISO PA6
|
||||
#define PIN_SPI_MISO PA6
|
||||
#endif
|
||||
#ifndef PIN_SPI_SCK
|
||||
#define PIN_SPI_SCK PA5
|
||||
#define PIN_SPI_SCK PA5
|
||||
#endif
|
||||
|
||||
// I2C definitions
|
||||
#ifndef PIN_WIRE_SDA
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#endif
|
||||
#ifndef PIN_WIRE_SCL
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM21
|
||||
#define TIMER_SERVO TIM21
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#endif
|
||||
|
||||
// Default pin used for generic 'Serial' instance
|
||||
// Mandatory for Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#endif
|
||||
|
||||
// Extra HAL modules
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -147,27 +147,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PB0
|
||||
#define LED_BUILTIN PB0
|
||||
#endif
|
||||
#define LED_GREEN LED_BUILTIN
|
||||
#define LED_BLUE PB7
|
||||
@@ -196,29 +196,29 @@
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PC13
|
||||
#define USER_BTN PC13
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM7
|
||||
#define TIMER_SERVO TIM7
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||
#endif
|
||||
// Serial pin used for console (ex: stlink)
|
||||
// Rerquired by Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#define PIN_SERIAL_RX PD9
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#define PIN_SERIAL_TX PD8
|
||||
#endif
|
||||
|
||||
// Value of the External oscillator in Hz
|
||||
@@ -226,16 +226,16 @@
|
||||
|
||||
/* Extra HAL modules */
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#define HAL_ETH_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
#endif
|
||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||
@@ -248,27 +248,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -75,71 +75,71 @@
|
||||
|
||||
// On-board LED pin number
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// On-board user button
|
||||
#ifndef USER_BTN
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#define USER_BTN PNUM_NOT_DEFINED
|
||||
#endif
|
||||
|
||||
// SPI definitions
|
||||
#ifndef PIN_SPI_SS
|
||||
#define PIN_SPI_SS PA4
|
||||
#define PIN_SPI_SS PA4
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS1
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#define PIN_SPI_SS1 PA15
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS2
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_SS3
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||
#endif
|
||||
#ifndef PIN_SPI_MOSI
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#define PIN_SPI_MOSI PA7
|
||||
#endif
|
||||
#ifndef PIN_SPI_MISO
|
||||
#define PIN_SPI_MISO PA6
|
||||
#define PIN_SPI_MISO PA6
|
||||
#endif
|
||||
#ifndef PIN_SPI_SCK
|
||||
#define PIN_SPI_SCK PA5
|
||||
#define PIN_SPI_SCK PA5
|
||||
#endif
|
||||
|
||||
// I2C definitions
|
||||
#ifndef PIN_WIRE_SDA
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#define PIN_WIRE_SDA PB7
|
||||
#endif
|
||||
#ifndef PIN_WIRE_SCL
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#define PIN_WIRE_SCL PB6
|
||||
#endif
|
||||
|
||||
// Timer Definitions
|
||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||
#ifndef TIMER_TONE
|
||||
#define TIMER_TONE TIM6
|
||||
#define TIMER_TONE TIM6
|
||||
#endif
|
||||
#ifndef TIMER_SERVO
|
||||
#define TIMER_SERVO TIM21
|
||||
#define TIMER_SERVO TIM21
|
||||
#endif
|
||||
|
||||
// UART Definitions
|
||||
#ifndef SERIAL_UART_INSTANCE
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#define SERIAL_UART_INSTANCE 2
|
||||
#endif
|
||||
|
||||
// Default pin used for generic 'Serial' instance
|
||||
// Mandatory for Firmata
|
||||
#ifndef PIN_SERIAL_RX
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#define PIN_SERIAL_RX PA3
|
||||
#endif
|
||||
#ifndef PIN_SERIAL_TX
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#define PIN_SERIAL_TX PA2
|
||||
#endif
|
||||
|
||||
// Extra HAL modules
|
||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -147,27 +147,27 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
#ifndef SERIAL_PORT_MONITOR
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#endif
|
||||
#ifndef SERIAL_PORT_HARDWARE
|
||||
// KH mod to add Serial1, for ESP-AT
|
||||
//#define SERIAL_PORT_HARDWARE Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -41,59 +41,60 @@
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) = 0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) =
|
||||
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
|
||||
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// Sending UDP packets
|
||||
// Sending UDP packets
|
||||
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define __PINS_ARDUINO__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" unsigned int PINCOUNT_fn();
|
||||
extern "C" unsigned int PINCOUNT_fn();
|
||||
#endif
|
||||
|
||||
// Pin count
|
||||
|
||||
1730
Packages_Patches/Seeeduino/hardware/samd/1.7.0/boards.txt
Normal file
1730
Packages_Patches/Seeeduino/hardware/samd/1.7.0/boards.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
#include <stdarg.h> // for printf
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
@@ -32,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
#include <stdarg.h> // for printf
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
@@ -32,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
#include <stdarg.h> // for printf
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
@@ -32,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,93 +32,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,93 +32,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,16 +76,16 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// The following headers are for C++ only compilation
|
||||
#ifdef __cplusplus
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#include "WCharacter.h"
|
||||
#include "WString.h"
|
||||
#include "Tone.h"
|
||||
#include "WMath.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pulse.h"
|
||||
#endif
|
||||
#include "delay.h"
|
||||
#ifdef __cplusplus
|
||||
#include "Uart.h"
|
||||
#include "Uart.h"
|
||||
#endif
|
||||
|
||||
// Include board variant
|
||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
@@ -147,8 +147,8 @@ auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused));
|
||||
static inline unsigned char __interruptsStatus(void)
|
||||
{
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||
return (__get_PRIMASK() ? 0 : 1);
|
||||
}
|
||||
#define interruptsStatus() __interruptsStatus()
|
||||
#endif
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,93 +32,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -35,259 +35,259 @@
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,93 +31,93 @@
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -28,65 +28,65 @@
|
||||
// private method to read stream with timeout
|
||||
int Stream::timedRead()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// private method to peek stream with timeout
|
||||
int Stream::timedPeek()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// returns peek of the next digit in the stream or -1 if timeout
|
||||
// discards non-numeric characters
|
||||
int Stream::peekNextDigit()
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
|
||||
if (c == '-')
|
||||
return c;
|
||||
if (c == '-')
|
||||
return c;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
||||
|
||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
||||
{
|
||||
_timeout = timeout;
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
// find returns true if the target string is found
|
||||
bool Stream::find(const char *target)
|
||||
{
|
||||
return findUntil(target, NULL);
|
||||
return findUntil(target, NULL);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of given length is found
|
||||
// returns true if target string is found, false if timed out
|
||||
bool Stream::find(const char *target, size_t length)
|
||||
{
|
||||
return findUntil(target, length, NULL, 0);
|
||||
return findUntil(target, length, NULL, 0);
|
||||
}
|
||||
|
||||
// as find but search ends if the terminator string is found
|
||||
bool Stream::findUntil(const char *target, const char *terminator)
|
||||
{
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of the given length is found
|
||||
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
|
||||
// returns true if target string is found, false if terminated or timed out
|
||||
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||
{
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
|
||||
// function is terminated by the first character that is not a digit.
|
||||
long Stream::parseInt()
|
||||
{
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
}
|
||||
|
||||
// as above but a given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
long Stream::parseInt(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// as parseInt but returns a floating point value
|
||||
float Stream::parseFloat()
|
||||
{
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
}
|
||||
|
||||
// as above but the given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
float Stream::parseFloat(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
// read characters from stream into buffer
|
||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
||||
//
|
||||
size_t Stream::readBytes(char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
size_t count = 0;
|
||||
size_t count = 0;
|
||||
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
|
||||
|
||||
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
if (length < 1)
|
||||
return 0;
|
||||
if (length < 1)
|
||||
return 0;
|
||||
|
||||
length--;
|
||||
size_t index = 0;
|
||||
length--;
|
||||
size_t index = 0;
|
||||
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c == terminator)
|
||||
break;
|
||||
if (c == terminator)
|
||||
break;
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
}
|
||||
|
||||
#if 1
|
||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char readStringBuffer[2048];
|
||||
|
||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
return readStringBuffer;
|
||||
return readStringBuffer;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
ret = String(readStringBuffer);
|
||||
ret = String(readStringBuffer);
|
||||
|
||||
return String(readStringBuffer);
|
||||
return String(readStringBuffer);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,124 +25,124 @@
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const char *target, size_t length);
|
||||
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
|
||||
unsigned long _timeout;
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
private:
|
||||
char read_error;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,65 +28,65 @@
|
||||
// private method to read stream with timeout
|
||||
int Stream::timedRead()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// private method to peek stream with timeout
|
||||
int Stream::timedPeek()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// returns peek of the next digit in the stream or -1 if timeout
|
||||
// discards non-numeric characters
|
||||
int Stream::peekNextDigit()
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
|
||||
if (c == '-')
|
||||
return c;
|
||||
if (c == '-')
|
||||
return c;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
||||
|
||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
||||
{
|
||||
_timeout = timeout;
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
// find returns true if the target string is found
|
||||
bool Stream::find(const char *target)
|
||||
{
|
||||
return findUntil(target, NULL);
|
||||
return findUntil(target, NULL);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of given length is found
|
||||
// returns true if target string is found, false if timed out
|
||||
bool Stream::find(const char *target, size_t length)
|
||||
{
|
||||
return findUntil(target, length, NULL, 0);
|
||||
return findUntil(target, length, NULL, 0);
|
||||
}
|
||||
|
||||
// as find but search ends if the terminator string is found
|
||||
bool Stream::findUntil(const char *target, const char *terminator)
|
||||
{
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of the given length is found
|
||||
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
|
||||
// returns true if target string is found, false if terminated or timed out
|
||||
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||
{
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
|
||||
// function is terminated by the first character that is not a digit.
|
||||
long Stream::parseInt()
|
||||
{
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
}
|
||||
|
||||
// as above but a given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
long Stream::parseInt(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// as parseInt but returns a floating point value
|
||||
float Stream::parseFloat()
|
||||
{
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
}
|
||||
|
||||
// as above but the given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
float Stream::parseFloat(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
// read characters from stream into buffer
|
||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
||||
//
|
||||
size_t Stream::readBytes(char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
size_t count = 0;
|
||||
size_t count = 0;
|
||||
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
|
||||
|
||||
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
if (length < 1)
|
||||
return 0;
|
||||
if (length < 1)
|
||||
return 0;
|
||||
|
||||
length--;
|
||||
size_t index = 0;
|
||||
length--;
|
||||
size_t index = 0;
|
||||
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c == terminator)
|
||||
break;
|
||||
if (c == terminator)
|
||||
break;
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
}
|
||||
|
||||
#if 1
|
||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char readStringBuffer[2048];
|
||||
|
||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
return readStringBuffer;
|
||||
return readStringBuffer;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
ret = String(readStringBuffer);
|
||||
ret = String(readStringBuffer);
|
||||
|
||||
return String(readStringBuffer);
|
||||
return String(readStringBuffer);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,124 +25,124 @@
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const char *target, size_t length);
|
||||
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
|
||||
unsigned long _timeout;
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
private:
|
||||
char read_error;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,65 +28,65 @@
|
||||
// private method to read stream with timeout
|
||||
int Stream::timedRead()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
do
|
||||
{
|
||||
c = read();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
Serial.print(("timedRead timeout = "));
|
||||
Serial.println(_timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// private method to peek stream with timeout
|
||||
int Stream::timedPeek()
|
||||
{
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
int c;
|
||||
unsigned long startMillis = millis();
|
||||
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
do
|
||||
{
|
||||
c = peek();
|
||||
|
||||
if (c >= 0)
|
||||
return c;
|
||||
if (c >= 0)
|
||||
return c;
|
||||
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
yield();
|
||||
} while (millis() - startMillis < _timeout);
|
||||
|
||||
return -1; // -1 indicates timeout
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// returns peek of the next digit in the stream or -1 if timeout
|
||||
// discards non-numeric characters
|
||||
int Stream::peekNextDigit()
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
while (1)
|
||||
{
|
||||
c = timedPeek();
|
||||
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
if (c < 0)
|
||||
return c; // timeout
|
||||
|
||||
if (c == '-')
|
||||
return c;
|
||||
if (c == '-')
|
||||
return c;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
if (c >= '0' && c <= '9')
|
||||
return c;
|
||||
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
||||
|
||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
||||
{
|
||||
_timeout = timeout;
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
// find returns true if the target string is found
|
||||
bool Stream::find(const char *target)
|
||||
{
|
||||
return findUntil(target, NULL);
|
||||
return findUntil(target, NULL);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of given length is found
|
||||
// returns true if target string is found, false if timed out
|
||||
bool Stream::find(const char *target, size_t length)
|
||||
{
|
||||
return findUntil(target, length, NULL, 0);
|
||||
return findUntil(target, length, NULL, 0);
|
||||
}
|
||||
|
||||
// as find but search ends if the terminator string is found
|
||||
bool Stream::findUntil(const char *target, const char *terminator)
|
||||
{
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
if (target == nullptr)
|
||||
return true;
|
||||
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
|
||||
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
return findUntil(target, strlen(target), terminator, tlen);
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of the given length is found
|
||||
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
|
||||
// returns true if target string is found, false if terminated or timed out
|
||||
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||
{
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
if ( target == nullptr)
|
||||
return true;
|
||||
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
if ( *target == 0)
|
||||
return true; // return true if target is a null string
|
||||
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
if (terminator == nullptr)
|
||||
termLen = 0;
|
||||
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
while ( (c = timedRead()) > 0)
|
||||
{
|
||||
if ( c == target[index])
|
||||
{
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if (++index >= targetLen)
|
||||
{
|
||||
// return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0; // reset index if any char does not match
|
||||
}
|
||||
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
if (termLen > 0 && c == terminator[termIndex])
|
||||
{
|
||||
if (++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
termIndex = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
|
||||
// function is terminated by the first character that is not a digit.
|
||||
long Stream::parseInt()
|
||||
{
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
}
|
||||
|
||||
// as above but a given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
long Stream::parseInt(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c >= '0' && c <= '9') // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// as parseInt but returns a floating point value
|
||||
float Stream::parseFloat()
|
||||
{
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
}
|
||||
|
||||
// as above but the given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
float Stream::parseFloat(char skipChar)
|
||||
{
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
float fraction = 1.0;
|
||||
|
||||
c = peekNextDigit();
|
||||
c = peekNextDigit();
|
||||
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
// ignore non numeric leading characters
|
||||
if (c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
do
|
||||
{
|
||||
if (c == skipChar)
|
||||
; // ignore
|
||||
else if (c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
isFraction = true;
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
// is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
if (isFraction)
|
||||
fraction *= 0.1f;
|
||||
}
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
if (isFraction)
|
||||
return value * fraction;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
// read characters from stream into buffer
|
||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
||||
//
|
||||
size_t Stream::readBytes(char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
size_t count = 0;
|
||||
size_t count = 0;
|
||||
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (count < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
|
||||
|
||||
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
{
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
if (buffer == nullptr)
|
||||
return 0;
|
||||
|
||||
if (length < 1)
|
||||
return 0;
|
||||
if (length < 1)
|
||||
return 0;
|
||||
|
||||
length--;
|
||||
size_t index = 0;
|
||||
length--;
|
||||
size_t index = 0;
|
||||
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (index < length)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c == terminator)
|
||||
break;
|
||||
if (c == terminator)
|
||||
break;
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
*buffer++ = (char)c;
|
||||
index++;
|
||||
}
|
||||
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
*buffer = 0;
|
||||
return index; // return number of characters, not including null terminator
|
||||
}
|
||||
|
||||
#if 1
|
||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
c = timedRead();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char readStringBuffer[2048];
|
||||
|
||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
return readStringBuffer;
|
||||
return readStringBuffer;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
String ret;
|
||||
uint16_t offset = 0;
|
||||
|
||||
int c = timedRead();
|
||||
int c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
readStringBuffer[offset++] = c;
|
||||
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
c = timedRead();
|
||||
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
readStringBuffer[offset++] = c;
|
||||
}
|
||||
|
||||
readStringBuffer[offset] = 0;
|
||||
readStringBuffer[offset] = 0;
|
||||
|
||||
ret = String(readStringBuffer);
|
||||
ret = String(readStringBuffer);
|
||||
|
||||
return String(readStringBuffer);
|
||||
return String(readStringBuffer);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
String Stream::readString(size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
String Stream::readStringUntil(char terminator, size_t max)
|
||||
{
|
||||
String str;
|
||||
size_t length = 0;
|
||||
String str;
|
||||
size_t length = 0;
|
||||
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
while (length < max)
|
||||
{
|
||||
int c = timedRead();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
setReadError();
|
||||
break; // timeout
|
||||
}
|
||||
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
if (c == 0 || c == terminator)
|
||||
break;
|
||||
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
str += (char)c;
|
||||
length++;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,124 +25,124 @@
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
public:
|
||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
void setTimeout(unsigned long timeout);
|
||||
bool find(const char *target);
|
||||
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
bool find(const uint8_t *target)
|
||||
{
|
||||
return find ((const char *)target);
|
||||
}
|
||||
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
bool find(const String &target)
|
||||
{
|
||||
return find(target.c_str());
|
||||
}
|
||||
|
||||
bool find(const char *target, size_t length);
|
||||
bool find(const char *target, size_t length);
|
||||
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
bool find(const uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((const char *)target, length);
|
||||
}
|
||||
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
bool find(const String &target, size_t length)
|
||||
{
|
||||
return find(target.c_str(), length);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
bool findUntil(const char *target, const char *terminator);
|
||||
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, const char *terminator)
|
||||
{
|
||||
return findUntil((const char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
bool findUntil(const String &target, const char *terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
bool findUntil(const char *target, const String &terminator)
|
||||
{
|
||||
return findUntil(target, terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
bool findUntil(const String &target, const String &terminator)
|
||||
{
|
||||
return findUntil(target.c_str(), terminator.c_str());
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((const char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
|
||||
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
|
||||
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
long parseInt();
|
||||
long parseInt(char skipChar);
|
||||
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
float parseFloat();
|
||||
float parseFloat(char skipChar);
|
||||
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
size_t readBytes(uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length);
|
||||
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
String readString(size_t max = 512);
|
||||
String readStringUntil(char terminator, size_t max = 512);
|
||||
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
// KH, to not use String
|
||||
char* readCharsUntil(char terminator, size_t max = 512);
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
int getReadError()
|
||||
{
|
||||
return read_error;
|
||||
}
|
||||
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
void clearReadError()
|
||||
{
|
||||
setReadError(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
protected:
|
||||
void setReadError(int err = 1)
|
||||
{
|
||||
read_error = err;
|
||||
}
|
||||
|
||||
unsigned long _timeout;
|
||||
unsigned long _timeout;
|
||||
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
// KH
|
||||
int timedRead();
|
||||
int timedPeek();
|
||||
int peekNextDigit();
|
||||
//////
|
||||
|
||||
private:
|
||||
char read_error;
|
||||
private:
|
||||
char read_error;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,56 +41,57 @@
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) = 0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) =
|
||||
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// Sending UDP packets
|
||||
// Sending UDP packets
|
||||
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,56 +41,57 @@
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) = 0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) =
|
||||
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// Sending UDP packets
|
||||
// Sending UDP packets
|
||||
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -105,7 +105,7 @@ unsigned long millis();
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
||||
{
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ unsigned long millis();
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
||||
{
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user