Update Packages' Patches
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -40,124 +40,126 @@
|
|||||||
// or a time out occurs due to lack of input.
|
// or a time out occurs due to lack of input.
|
||||||
enum LookaheadMode
|
enum LookaheadMode
|
||||||
{
|
{
|
||||||
SKIP_ALL, // All invalid characters are ignored.
|
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_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_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
|
#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
|
||||||
|
|
||||||
class Stream : public Print
|
class Stream : public Print
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||||
unsigned long _startMillis = 0; // used for timeout measurement
|
unsigned long _startMillis = 0; // used for timeout measurement
|
||||||
int timedRead(); // read stream with timeout
|
int timedRead(); // read stream with timeout
|
||||||
int timedPeek(); // peek 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
|
int peekNextDigit(LookaheadMode lookahead,
|
||||||
|
bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
|
|
||||||
Stream()
|
Stream()
|
||||||
{
|
{
|
||||||
_timeout = 1000;
|
_timeout = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsing methods
|
// parsing methods
|
||||||
|
|
||||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||||
unsigned long getTimeout(void)
|
unsigned long getTimeout(void)
|
||||||
{
|
{
|
||||||
return _timeout;
|
return _timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(char *target); // reads data from the stream until the target string is found
|
bool find(char *target); // reads data from the stream until the target string is found
|
||||||
bool find(uint8_t *target)
|
bool find(uint8_t *target)
|
||||||
{
|
{
|
||||||
return find ((char *)target);
|
return find ((char *)target);
|
||||||
}
|
}
|
||||||
// returns true if target string is found, false if timed out (see setTimeout)
|
// 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(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)
|
bool find(uint8_t *target, size_t length)
|
||||||
{
|
{
|
||||||
return find ((char *)target, length);
|
return find ((char *)target, length);
|
||||||
}
|
}
|
||||||
// returns true if target string is found, false if timed out
|
// returns true if target string is found, false if timed out
|
||||||
|
|
||||||
bool find(char target)
|
bool find(char target)
|
||||||
{
|
{
|
||||||
return find (&target, 1);
|
return find (&target, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||||
bool findUntil(uint8_t *target, char *terminator)
|
bool findUntil(uint8_t *target, char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil((char *)target, 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(char *target, size_t targetLen, char *terminate,
|
||||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
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);
|
{
|
||||||
}
|
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||||
|
}
|
||||||
|
|
||||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
// returns the first valid (long) integer value from the current position.
|
// returns the first valid (long) integer value from the current position.
|
||||||
// lookahead determines how parseInt looks ahead in the stream.
|
// lookahead determines how parseInt looks ahead in the stream.
|
||||||
// See LookaheadMode enumeration at the top of the file.
|
// 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.
|
// 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.
|
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||||
|
|
||||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
// float version of parseInt
|
// float version of parseInt
|
||||||
|
|
||||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||||
size_t readBytes( uint8_t *buffer, size_t length)
|
size_t readBytes( uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytes((char *)buffer, length);
|
return readBytes((char *)buffer, length);
|
||||||
}
|
}
|
||||||
// terminates if length characters have been read or timeout (see setTimeout)
|
// 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)
|
// 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, char *buffer, size_t length); // as readBytes with terminator character
|
||||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytesUntil(terminator, (char *)buffer, length);
|
return readBytesUntil(terminator, (char *)buffer, length);
|
||||||
}
|
}
|
||||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
// 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)
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
// Arduino String functions to be added here
|
// Arduino String functions to be added here
|
||||||
String readString();
|
String readString();
|
||||||
String readStringUntil(char terminator);
|
String readStringUntil(char terminator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
long parseInt(char ignore)
|
long parseInt(char ignore)
|
||||||
{
|
{
|
||||||
return parseInt(SKIP_ALL, ignore);
|
return parseInt(SKIP_ALL, ignore);
|
||||||
}
|
}
|
||||||
float parseFloat(char ignore)
|
float parseFloat(char ignore)
|
||||||
{
|
{
|
||||||
return parseFloat(SKIP_ALL, ignore);
|
return parseFloat(SKIP_ALL, ignore);
|
||||||
}
|
}
|
||||||
// These overload exists for compatibility with any class that has derived
|
// These overload exists for compatibility with any class that has derived
|
||||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||||
// the public API simple, these overload remains protected.
|
// the public API simple, these overload remains protected.
|
||||||
|
|
||||||
struct MultiTarget
|
struct MultiTarget
|
||||||
{
|
{
|
||||||
const char *str; // string you're searching for
|
const char *str; // string you're searching for
|
||||||
size_t len; // length of string you're searching for
|
size_t len; // length of string you're searching for
|
||||||
size_t index; // index used by the search routine.
|
size_t index; // index used by the search routine.
|
||||||
};
|
};
|
||||||
|
|
||||||
// This allows you to search for an arbitrary number of strings.
|
// 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.
|
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||||
int findMulti(struct MultiTarget *targets, int tCount);
|
int findMulti(struct MultiTarget *targets, int tCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef NO_IGNORE_CHAR
|
#undef NO_IGNORE_CHAR
|
||||||
|
|||||||
@@ -40,124 +40,126 @@
|
|||||||
// or a time out occurs due to lack of input.
|
// or a time out occurs due to lack of input.
|
||||||
enum LookaheadMode
|
enum LookaheadMode
|
||||||
{
|
{
|
||||||
SKIP_ALL, // All invalid characters are ignored.
|
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_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_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
|
#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
|
||||||
|
|
||||||
class Stream : public Print
|
class Stream : public Print
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||||
unsigned long _startMillis = 0; // used for timeout measurement
|
unsigned long _startMillis = 0; // used for timeout measurement
|
||||||
int timedRead(); // read stream with timeout
|
int timedRead(); // read stream with timeout
|
||||||
int timedPeek(); // peek 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
|
int peekNextDigit(LookaheadMode lookahead,
|
||||||
|
bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
|
|
||||||
Stream()
|
Stream()
|
||||||
{
|
{
|
||||||
_timeout = 1000;
|
_timeout = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsing methods
|
// parsing methods
|
||||||
|
|
||||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||||
unsigned long getTimeout(void)
|
unsigned long getTimeout(void)
|
||||||
{
|
{
|
||||||
return _timeout;
|
return _timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(char *target); // reads data from the stream until the target string is found
|
bool find(char *target); // reads data from the stream until the target string is found
|
||||||
bool find(uint8_t *target)
|
bool find(uint8_t *target)
|
||||||
{
|
{
|
||||||
return find ((char *)target);
|
return find ((char *)target);
|
||||||
}
|
}
|
||||||
// returns true if target string is found, false if timed out (see setTimeout)
|
// 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(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)
|
bool find(uint8_t *target, size_t length)
|
||||||
{
|
{
|
||||||
return find ((char *)target, length);
|
return find ((char *)target, length);
|
||||||
}
|
}
|
||||||
// returns true if target string is found, false if timed out
|
// returns true if target string is found, false if timed out
|
||||||
|
|
||||||
bool find(char target)
|
bool find(char target)
|
||||||
{
|
{
|
||||||
return find (&target, 1);
|
return find (&target, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||||
bool findUntil(uint8_t *target, char *terminator)
|
bool findUntil(uint8_t *target, char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil((char *)target, 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(char *target, size_t targetLen, char *terminate,
|
||||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
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);
|
{
|
||||||
}
|
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||||
|
}
|
||||||
|
|
||||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
// returns the first valid (long) integer value from the current position.
|
// returns the first valid (long) integer value from the current position.
|
||||||
// lookahead determines how parseInt looks ahead in the stream.
|
// lookahead determines how parseInt looks ahead in the stream.
|
||||||
// See LookaheadMode enumeration at the top of the file.
|
// 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.
|
// 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.
|
// Once parsing commences, 'ignore' will be skipped in the stream.
|
||||||
|
|
||||||
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||||
// float version of parseInt
|
// float version of parseInt
|
||||||
|
|
||||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||||
size_t readBytes( uint8_t *buffer, size_t length)
|
size_t readBytes( uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytes((char *)buffer, length);
|
return readBytes((char *)buffer, length);
|
||||||
}
|
}
|
||||||
// terminates if length characters have been read or timeout (see setTimeout)
|
// 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)
|
// 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, char *buffer, size_t length); // as readBytes with terminator character
|
||||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytesUntil(terminator, (char *)buffer, length);
|
return readBytesUntil(terminator, (char *)buffer, length);
|
||||||
}
|
}
|
||||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
// 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)
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
// Arduino String functions to be added here
|
// Arduino String functions to be added here
|
||||||
String readString();
|
String readString();
|
||||||
String readStringUntil(char terminator);
|
String readStringUntil(char terminator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
long parseInt(char ignore)
|
long parseInt(char ignore)
|
||||||
{
|
{
|
||||||
return parseInt(SKIP_ALL, ignore);
|
return parseInt(SKIP_ALL, ignore);
|
||||||
}
|
}
|
||||||
float parseFloat(char ignore)
|
float parseFloat(char ignore)
|
||||||
{
|
{
|
||||||
return parseFloat(SKIP_ALL, ignore);
|
return parseFloat(SKIP_ALL, ignore);
|
||||||
}
|
}
|
||||||
// These overload exists for compatibility with any class that has derived
|
// These overload exists for compatibility with any class that has derived
|
||||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||||
// the public API simple, these overload remains protected.
|
// the public API simple, these overload remains protected.
|
||||||
|
|
||||||
struct MultiTarget
|
struct MultiTarget
|
||||||
{
|
{
|
||||||
const char *str; // string you're searching for
|
const char *str; // string you're searching for
|
||||||
size_t len; // length of string you're searching for
|
size_t len; // length of string you're searching for
|
||||||
size_t index; // index used by the search routine.
|
size_t index; // index used by the search routine.
|
||||||
};
|
};
|
||||||
|
|
||||||
// This allows you to search for an arbitrary number of strings.
|
// 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.
|
// Returns index of the target that is found first or -1 if timeout occurs.
|
||||||
int findMulti(struct MultiTarget *targets, int tCount);
|
int findMulti(struct MultiTarget *targets, int tCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef NO_IGNORE_CHAR
|
#undef NO_IGNORE_CHAR
|
||||||
|
|||||||
@@ -160,26 +160,26 @@ extern "C" {
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
|
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _VARIANT_ARDUINO_STM32_ */
|
#endif /* _VARIANT_ARDUINO_STM32_ */
|
||||||
|
|||||||
@@ -120,26 +120,26 @@ extern "C" {
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
|
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _VARIANT_ARDUINO_STM32_ */
|
#endif /* _VARIANT_ARDUINO_STM32_ */
|
||||||
|
|||||||
+34
-34
@@ -188,7 +188,7 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PB0
|
#define LED_BUILTIN PB0
|
||||||
#endif
|
#endif
|
||||||
#define LED_GREEN LED_BUILTIN
|
#define LED_GREEN LED_BUILTIN
|
||||||
#define LED_BLUE PB7
|
#define LED_BLUE PB7
|
||||||
@@ -196,29 +196,29 @@
|
|||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PC13
|
#define USER_BTN PC13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM7
|
#define TIMER_SERVO TIM7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||||
#endif
|
#endif
|
||||||
// Serial pin used for console (ex: stlink)
|
// Serial pin used for console (ex: stlink)
|
||||||
// Rerquired by Firmata
|
// Rerquired by Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PD9
|
#define PIN_SERIAL_RX PD9
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PD8
|
#define PIN_SERIAL_TX PD8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Value of the External oscillator in Hz
|
// Value of the External oscillator in Hz
|
||||||
@@ -226,16 +226,16 @@
|
|||||||
|
|
||||||
/* Extra HAL modules */
|
/* Extra HAL modules */
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||||
#define HAL_QSPI_MODULE_ENABLED
|
#define HAL_QSPI_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||||
#define HAL_SD_MODULE_ENABLED
|
#define HAL_SD_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||||
@@ -248,27 +248,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+40
-40
@@ -75,71 +75,71 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PNUM_NOT_DEFINED
|
#define USER_BTN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPI definitions
|
// SPI definitions
|
||||||
#ifndef PIN_SPI_SS
|
#ifndef PIN_SPI_SS
|
||||||
#define PIN_SPI_SS PA4
|
#define PIN_SPI_SS PA4
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS1
|
#ifndef PIN_SPI_SS1
|
||||||
#define PIN_SPI_SS1 PA15
|
#define PIN_SPI_SS1 PA15
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS2
|
#ifndef PIN_SPI_SS2
|
||||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS3
|
#ifndef PIN_SPI_SS3
|
||||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MOSI
|
#ifndef PIN_SPI_MOSI
|
||||||
#define PIN_SPI_MOSI PA7
|
#define PIN_SPI_MOSI PA7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MISO
|
#ifndef PIN_SPI_MISO
|
||||||
#define PIN_SPI_MISO PA6
|
#define PIN_SPI_MISO PA6
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SCK
|
#ifndef PIN_SPI_SCK
|
||||||
#define PIN_SPI_SCK PA5
|
#define PIN_SPI_SCK PA5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C definitions
|
// I2C definitions
|
||||||
#ifndef PIN_WIRE_SDA
|
#ifndef PIN_WIRE_SDA
|
||||||
#define PIN_WIRE_SDA PB7
|
#define PIN_WIRE_SDA PB7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_WIRE_SCL
|
#ifndef PIN_WIRE_SCL
|
||||||
#define PIN_WIRE_SCL PB6
|
#define PIN_WIRE_SCL PB6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM21
|
#define TIMER_SERVO TIM21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 2
|
#define SERIAL_UART_INSTANCE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default pin used for generic 'Serial' instance
|
// Default pin used for generic 'Serial' instance
|
||||||
// Mandatory for Firmata
|
// Mandatory for Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PA3
|
#define PIN_SERIAL_RX PA3
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PA2
|
#define PIN_SERIAL_TX PA2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Extra HAL modules
|
// Extra HAL modules
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -147,27 +147,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-34
@@ -188,7 +188,7 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PB0
|
#define LED_BUILTIN PB0
|
||||||
#endif
|
#endif
|
||||||
#define LED_GREEN LED_BUILTIN
|
#define LED_GREEN LED_BUILTIN
|
||||||
#define LED_BLUE PB7
|
#define LED_BLUE PB7
|
||||||
@@ -196,29 +196,29 @@
|
|||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PC13
|
#define USER_BTN PC13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM7
|
#define TIMER_SERVO TIM7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||||
#endif
|
#endif
|
||||||
// Serial pin used for console (ex: stlink)
|
// Serial pin used for console (ex: stlink)
|
||||||
// Rerquired by Firmata
|
// Rerquired by Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PD9
|
#define PIN_SERIAL_RX PD9
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PD8
|
#define PIN_SERIAL_TX PD8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Value of the External oscillator in Hz
|
// Value of the External oscillator in Hz
|
||||||
@@ -226,16 +226,16 @@
|
|||||||
|
|
||||||
/* Extra HAL modules */
|
/* Extra HAL modules */
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||||
#define HAL_QSPI_MODULE_ENABLED
|
#define HAL_QSPI_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||||
#define HAL_SD_MODULE_ENABLED
|
#define HAL_SD_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||||
@@ -248,27 +248,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+40
-40
@@ -75,71 +75,71 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PNUM_NOT_DEFINED
|
#define USER_BTN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPI definitions
|
// SPI definitions
|
||||||
#ifndef PIN_SPI_SS
|
#ifndef PIN_SPI_SS
|
||||||
#define PIN_SPI_SS PA4
|
#define PIN_SPI_SS PA4
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS1
|
#ifndef PIN_SPI_SS1
|
||||||
#define PIN_SPI_SS1 PA15
|
#define PIN_SPI_SS1 PA15
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS2
|
#ifndef PIN_SPI_SS2
|
||||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS3
|
#ifndef PIN_SPI_SS3
|
||||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MOSI
|
#ifndef PIN_SPI_MOSI
|
||||||
#define PIN_SPI_MOSI PA7
|
#define PIN_SPI_MOSI PA7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MISO
|
#ifndef PIN_SPI_MISO
|
||||||
#define PIN_SPI_MISO PA6
|
#define PIN_SPI_MISO PA6
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SCK
|
#ifndef PIN_SPI_SCK
|
||||||
#define PIN_SPI_SCK PA5
|
#define PIN_SPI_SCK PA5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C definitions
|
// I2C definitions
|
||||||
#ifndef PIN_WIRE_SDA
|
#ifndef PIN_WIRE_SDA
|
||||||
#define PIN_WIRE_SDA PB7
|
#define PIN_WIRE_SDA PB7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_WIRE_SCL
|
#ifndef PIN_WIRE_SCL
|
||||||
#define PIN_WIRE_SCL PB6
|
#define PIN_WIRE_SCL PB6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM21
|
#define TIMER_SERVO TIM21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 2
|
#define SERIAL_UART_INSTANCE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default pin used for generic 'Serial' instance
|
// Default pin used for generic 'Serial' instance
|
||||||
// Mandatory for Firmata
|
// Mandatory for Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PA3
|
#define PIN_SERIAL_RX PA3
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PA2
|
#define PIN_SERIAL_TX PA2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Extra HAL modules
|
// Extra HAL modules
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -147,27 +147,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-34
@@ -188,7 +188,7 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PB0
|
#define LED_BUILTIN PB0
|
||||||
#endif
|
#endif
|
||||||
#define LED_GREEN LED_BUILTIN
|
#define LED_GREEN LED_BUILTIN
|
||||||
#define LED_BLUE PB7
|
#define LED_BLUE PB7
|
||||||
@@ -196,29 +196,29 @@
|
|||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PC13
|
#define USER_BTN PC13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM7
|
#define TIMER_SERVO TIM7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||||
#endif
|
#endif
|
||||||
// Serial pin used for console (ex: stlink)
|
// Serial pin used for console (ex: stlink)
|
||||||
// Rerquired by Firmata
|
// Rerquired by Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PD9
|
#define PIN_SERIAL_RX PD9
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PD8
|
#define PIN_SERIAL_TX PD8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Value of the External oscillator in Hz
|
// Value of the External oscillator in Hz
|
||||||
@@ -226,16 +226,16 @@
|
|||||||
|
|
||||||
/* Extra HAL modules */
|
/* Extra HAL modules */
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||||
#define HAL_QSPI_MODULE_ENABLED
|
#define HAL_QSPI_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||||
#define HAL_SD_MODULE_ENABLED
|
#define HAL_SD_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||||
@@ -248,27 +248,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+40
-40
@@ -75,71 +75,71 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PNUM_NOT_DEFINED
|
#define USER_BTN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPI definitions
|
// SPI definitions
|
||||||
#ifndef PIN_SPI_SS
|
#ifndef PIN_SPI_SS
|
||||||
#define PIN_SPI_SS PA4
|
#define PIN_SPI_SS PA4
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS1
|
#ifndef PIN_SPI_SS1
|
||||||
#define PIN_SPI_SS1 PA15
|
#define PIN_SPI_SS1 PA15
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS2
|
#ifndef PIN_SPI_SS2
|
||||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS3
|
#ifndef PIN_SPI_SS3
|
||||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MOSI
|
#ifndef PIN_SPI_MOSI
|
||||||
#define PIN_SPI_MOSI PA7
|
#define PIN_SPI_MOSI PA7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MISO
|
#ifndef PIN_SPI_MISO
|
||||||
#define PIN_SPI_MISO PA6
|
#define PIN_SPI_MISO PA6
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SCK
|
#ifndef PIN_SPI_SCK
|
||||||
#define PIN_SPI_SCK PA5
|
#define PIN_SPI_SCK PA5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C definitions
|
// I2C definitions
|
||||||
#ifndef PIN_WIRE_SDA
|
#ifndef PIN_WIRE_SDA
|
||||||
#define PIN_WIRE_SDA PB7
|
#define PIN_WIRE_SDA PB7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_WIRE_SCL
|
#ifndef PIN_WIRE_SCL
|
||||||
#define PIN_WIRE_SCL PB6
|
#define PIN_WIRE_SCL PB6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM21
|
#define TIMER_SERVO TIM21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 2
|
#define SERIAL_UART_INSTANCE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default pin used for generic 'Serial' instance
|
// Default pin used for generic 'Serial' instance
|
||||||
// Mandatory for Firmata
|
// Mandatory for Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PA3
|
#define PIN_SERIAL_RX PA3
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PA2
|
#define PIN_SERIAL_TX PA2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Extra HAL modules
|
// Extra HAL modules
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -147,27 +147,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-34
@@ -188,7 +188,7 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PB0
|
#define LED_BUILTIN PB0
|
||||||
#endif
|
#endif
|
||||||
#define LED_GREEN LED_BUILTIN
|
#define LED_GREEN LED_BUILTIN
|
||||||
#define LED_BLUE PB7
|
#define LED_BLUE PB7
|
||||||
@@ -196,29 +196,29 @@
|
|||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PC13
|
#define USER_BTN PC13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM7
|
#define TIMER_SERVO TIM7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||||
#endif
|
#endif
|
||||||
// Serial pin used for console (ex: stlink)
|
// Serial pin used for console (ex: stlink)
|
||||||
// Rerquired by Firmata
|
// Rerquired by Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PD9
|
#define PIN_SERIAL_RX PD9
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PD8
|
#define PIN_SERIAL_TX PD8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Value of the External oscillator in Hz
|
// Value of the External oscillator in Hz
|
||||||
@@ -226,16 +226,16 @@
|
|||||||
|
|
||||||
/* Extra HAL modules */
|
/* Extra HAL modules */
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||||
#define HAL_QSPI_MODULE_ENABLED
|
#define HAL_QSPI_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||||
#define HAL_SD_MODULE_ENABLED
|
#define HAL_SD_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||||
@@ -248,27 +248,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+40
-40
@@ -75,71 +75,71 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PNUM_NOT_DEFINED
|
#define USER_BTN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPI definitions
|
// SPI definitions
|
||||||
#ifndef PIN_SPI_SS
|
#ifndef PIN_SPI_SS
|
||||||
#define PIN_SPI_SS PA4
|
#define PIN_SPI_SS PA4
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS1
|
#ifndef PIN_SPI_SS1
|
||||||
#define PIN_SPI_SS1 PA15
|
#define PIN_SPI_SS1 PA15
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS2
|
#ifndef PIN_SPI_SS2
|
||||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS3
|
#ifndef PIN_SPI_SS3
|
||||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MOSI
|
#ifndef PIN_SPI_MOSI
|
||||||
#define PIN_SPI_MOSI PA7
|
#define PIN_SPI_MOSI PA7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MISO
|
#ifndef PIN_SPI_MISO
|
||||||
#define PIN_SPI_MISO PA6
|
#define PIN_SPI_MISO PA6
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SCK
|
#ifndef PIN_SPI_SCK
|
||||||
#define PIN_SPI_SCK PA5
|
#define PIN_SPI_SCK PA5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C definitions
|
// I2C definitions
|
||||||
#ifndef PIN_WIRE_SDA
|
#ifndef PIN_WIRE_SDA
|
||||||
#define PIN_WIRE_SDA PB7
|
#define PIN_WIRE_SDA PB7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_WIRE_SCL
|
#ifndef PIN_WIRE_SCL
|
||||||
#define PIN_WIRE_SCL PB6
|
#define PIN_WIRE_SCL PB6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM21
|
#define TIMER_SERVO TIM21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 2
|
#define SERIAL_UART_INSTANCE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default pin used for generic 'Serial' instance
|
// Default pin used for generic 'Serial' instance
|
||||||
// Mandatory for Firmata
|
// Mandatory for Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PA3
|
#define PIN_SERIAL_RX PA3
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PA2
|
#define PIN_SERIAL_TX PA2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Extra HAL modules
|
// Extra HAL modules
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -147,27 +147,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-34
@@ -188,7 +188,7 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PB0
|
#define LED_BUILTIN PB0
|
||||||
#endif
|
#endif
|
||||||
#define LED_GREEN LED_BUILTIN
|
#define LED_GREEN LED_BUILTIN
|
||||||
#define LED_BLUE PB7
|
#define LED_BLUE PB7
|
||||||
@@ -196,29 +196,29 @@
|
|||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PC13
|
#define USER_BTN PC13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM7
|
#define TIMER_SERVO TIM7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
|
||||||
#endif
|
#endif
|
||||||
// Serial pin used for console (ex: stlink)
|
// Serial pin used for console (ex: stlink)
|
||||||
// Rerquired by Firmata
|
// Rerquired by Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PD9
|
#define PIN_SERIAL_RX PD9
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PD8
|
#define PIN_SERIAL_TX PD8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Value of the External oscillator in Hz
|
// Value of the External oscillator in Hz
|
||||||
@@ -226,16 +226,16 @@
|
|||||||
|
|
||||||
/* Extra HAL modules */
|
/* Extra HAL modules */
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_ETH_MODULE_DISABLED)
|
#if !defined(HAL_ETH_MODULE_DISABLED)
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
#if !defined(HAL_QSPI_MODULE_DISABLED)
|
||||||
#define HAL_QSPI_MODULE_ENABLED
|
#define HAL_QSPI_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
#if !defined(HAL_SD_MODULE_DISABLED)
|
#if !defined(HAL_SD_MODULE_DISABLED)
|
||||||
#define HAL_SD_MODULE_ENABLED
|
#define HAL_SD_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
// Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration.
|
||||||
@@ -248,27 +248,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+40
-40
@@ -75,71 +75,71 @@
|
|||||||
|
|
||||||
// On-board LED pin number
|
// On-board LED pin number
|
||||||
#ifndef LED_BUILTIN
|
#ifndef LED_BUILTIN
|
||||||
#define LED_BUILTIN PNUM_NOT_DEFINED
|
#define LED_BUILTIN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On-board user button
|
// On-board user button
|
||||||
#ifndef USER_BTN
|
#ifndef USER_BTN
|
||||||
#define USER_BTN PNUM_NOT_DEFINED
|
#define USER_BTN PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SPI definitions
|
// SPI definitions
|
||||||
#ifndef PIN_SPI_SS
|
#ifndef PIN_SPI_SS
|
||||||
#define PIN_SPI_SS PA4
|
#define PIN_SPI_SS PA4
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS1
|
#ifndef PIN_SPI_SS1
|
||||||
#define PIN_SPI_SS1 PA15
|
#define PIN_SPI_SS1 PA15
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS2
|
#ifndef PIN_SPI_SS2
|
||||||
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SS3
|
#ifndef PIN_SPI_SS3
|
||||||
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MOSI
|
#ifndef PIN_SPI_MOSI
|
||||||
#define PIN_SPI_MOSI PA7
|
#define PIN_SPI_MOSI PA7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_MISO
|
#ifndef PIN_SPI_MISO
|
||||||
#define PIN_SPI_MISO PA6
|
#define PIN_SPI_MISO PA6
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SPI_SCK
|
#ifndef PIN_SPI_SCK
|
||||||
#define PIN_SPI_SCK PA5
|
#define PIN_SPI_SCK PA5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C definitions
|
// I2C definitions
|
||||||
#ifndef PIN_WIRE_SDA
|
#ifndef PIN_WIRE_SDA
|
||||||
#define PIN_WIRE_SDA PB7
|
#define PIN_WIRE_SDA PB7
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_WIRE_SCL
|
#ifndef PIN_WIRE_SCL
|
||||||
#define PIN_WIRE_SCL PB6
|
#define PIN_WIRE_SCL PB6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Timer Definitions
|
// Timer Definitions
|
||||||
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
|
||||||
#ifndef TIMER_TONE
|
#ifndef TIMER_TONE
|
||||||
#define TIMER_TONE TIM6
|
#define TIMER_TONE TIM6
|
||||||
#endif
|
#endif
|
||||||
#ifndef TIMER_SERVO
|
#ifndef TIMER_SERVO
|
||||||
#define TIMER_SERVO TIM21
|
#define TIMER_SERVO TIM21
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// UART Definitions
|
// UART Definitions
|
||||||
#ifndef SERIAL_UART_INSTANCE
|
#ifndef SERIAL_UART_INSTANCE
|
||||||
#define SERIAL_UART_INSTANCE 2
|
#define SERIAL_UART_INSTANCE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default pin used for generic 'Serial' instance
|
// Default pin used for generic 'Serial' instance
|
||||||
// Mandatory for Firmata
|
// Mandatory for Firmata
|
||||||
#ifndef PIN_SERIAL_RX
|
#ifndef PIN_SERIAL_RX
|
||||||
#define PIN_SERIAL_RX PA3
|
#define PIN_SERIAL_RX PA3
|
||||||
#endif
|
#endif
|
||||||
#ifndef PIN_SERIAL_TX
|
#ifndef PIN_SERIAL_TX
|
||||||
#define PIN_SERIAL_TX PA2
|
#define PIN_SERIAL_TX PA2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Extra HAL modules
|
// Extra HAL modules
|
||||||
#if !defined(HAL_DAC_MODULE_DISABLED)
|
#if !defined(HAL_DAC_MODULE_DISABLED)
|
||||||
#define HAL_DAC_MODULE_ENABLED
|
#define HAL_DAC_MODULE_ENABLED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -147,27 +147,27 @@
|
|||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// These serial port names are intended to allow libraries and architecture-neutral
|
// 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
|
// 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,
|
// 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.
|
// 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_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
// 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 Hardware serial port, physical RX & TX pins.
|
||||||
//
|
//
|
||||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||||
// pins are NOT connected to anything by default.
|
// pins are NOT connected to anything by default.
|
||||||
#ifndef SERIAL_PORT_MONITOR
|
#ifndef SERIAL_PORT_MONITOR
|
||||||
#define SERIAL_PORT_MONITOR Serial
|
#define SERIAL_PORT_MONITOR Serial
|
||||||
#endif
|
#endif
|
||||||
#ifndef SERIAL_PORT_HARDWARE
|
#ifndef SERIAL_PORT_HARDWARE
|
||||||
// KH mod to add Serial1, for ESP-AT
|
// KH mod to add Serial1, for ESP-AT
|
||||||
//#define SERIAL_PORT_HARDWARE Serial
|
//#define SERIAL_PORT_HARDWARE Serial
|
||||||
#define SERIAL_PORT_HARDWARE Serial1
|
#define SERIAL_PORT_HARDWARE Serial1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
class UDP : public Stream
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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 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.)
|
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
|
||||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
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
|
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
|
// 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
|
// 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;
|
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
|
// 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
|
// 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;
|
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||||
// Finish off this packet and send it
|
// Finish off this packet and send it
|
||||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||||
virtual int endPacket() = 0;
|
virtual int endPacket() = 0;
|
||||||
// Write a single byte into the packet
|
// Write a single byte into the packet
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
// Write size bytes from buffer into the packet
|
// Write size bytes from buffer into the packet
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||||
|
|
||||||
// Start processing the next available incoming packet
|
// Start processing the next available incoming packet
|
||||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||||
virtual int parsePacket() = 0;
|
virtual int parsePacket() = 0;
|
||||||
// Number of bytes remaining in the current packet
|
// Number of bytes remaining in the current packet
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
// Read a single byte from the current packet
|
// Read a single byte from the current packet
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
// Read up to len bytes from the current packet and place them into buffer
|
// 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
|
// Returns the number of bytes read, or 0 if none are available
|
||||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||||
// Read up to len characters from the current packet and place them into buffer
|
// 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
|
// Returns the number of characters read, or 0 if none are available
|
||||||
virtual int read(char* buffer, size_t len) = 0;
|
virtual int read(char* buffer, size_t len) = 0;
|
||||||
// Return the next byte from the current packet without moving on to the next byte
|
// Return the next byte from the current packet without moving on to the next byte
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
virtual void flush() = 0; // Finish reading the current packet
|
virtual void flush() = 0; // Finish reading the current packet
|
||||||
|
|
||||||
// Return the IP address of the host who sent the current incoming packet
|
// Return the IP address of the host who sent the current incoming packet
|
||||||
virtual IPAddress remoteIP() = 0;
|
virtual IPAddress remoteIP() = 0;
|
||||||
// Return the port of the host who sent the current incoming packet
|
// Return the port of the host who sent the current incoming packet
|
||||||
virtual uint16_t remotePort() = 0;
|
virtual uint16_t remotePort() = 0;
|
||||||
protected:
|
protected:
|
||||||
uint8_t* rawIPAddress(IPAddress& addr)
|
uint8_t* rawIPAddress(IPAddress& addr)
|
||||||
{
|
{
|
||||||
return addr.raw_address();
|
return addr.raw_address();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
#define __PINS_ARDUINO__
|
#define __PINS_ARDUINO__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" unsigned int PINCOUNT_fn();
|
extern "C" unsigned int PINCOUNT_fn();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pin count
|
// Pin count
|
||||||
|
|||||||
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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 <inttypes.h>
|
||||||
#include <stdio.h> // for size_t
|
#include <stdio.h> // for size_t
|
||||||
#include <stdarg.h> // for printf
|
|
||||||
|
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Printable.h"
|
#include "Printable.h"
|
||||||
@@ -32,93 +31,93 @@
|
|||||||
|
|
||||||
class Print
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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 <inttypes.h>
|
||||||
#include <stdio.h> // for size_t
|
#include <stdio.h> // for size_t
|
||||||
#include <stdarg.h> // for printf
|
|
||||||
|
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Printable.h"
|
#include "Printable.h"
|
||||||
@@ -32,93 +31,93 @@
|
|||||||
|
|
||||||
class Print
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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 <inttypes.h>
|
||||||
#include <stdio.h> // for size_t
|
#include <stdio.h> // for size_t
|
||||||
#include <stdarg.h> // for printf
|
|
||||||
|
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Printable.h"
|
#include "Printable.h"
|
||||||
@@ -32,93 +31,93 @@
|
|||||||
|
|
||||||
class Print
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// The following headers are for C++ only compilation
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "WCharacter.h"
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "Tone.h"
|
#include "Tone.h"
|
||||||
#include "WMath.h"
|
#include "WMath.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "pulse.h"
|
#include "pulse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Include board variant
|
// Include board variant
|
||||||
@@ -100,24 +100,24 @@ int __debug_buf(const char* head, char* buf, int len);
|
|||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
#endif // abs
|
#endif // abs
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
template<class T, class L>
|
template<class T, class L>
|
||||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
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>
|
template<class T, class L>
|
||||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||||
{
|
{
|
||||||
return (a < b) ? b : a;
|
return (a < b) ? b : a;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef min
|
#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) __attribute__((always_inline, unused));
|
||||||
static inline unsigned char __interruptsStatus(void)
|
static inline unsigned char __interruptsStatus(void)
|
||||||
{
|
{
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html
|
||||||
return (__get_PRIMASK() ? 0 : 1);
|
return (__get_PRIMASK() ? 0 : 1);
|
||||||
}
|
}
|
||||||
#define interruptsStatus() __interruptsStatus()
|
#define interruptsStatus() __interruptsStatus()
|
||||||
#endif
|
#endif
|
||||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
|||||||
#define bit(b) (1UL << (b))
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||||
// Interrupts
|
// Interrupts
|
||||||
#define digitalPinToInterrupt(P) ( P )
|
#define digitalPinToInterrupt(P) ( P )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// USB
|
// USB
|
||||||
#ifdef USE_TINYUSB
|
#ifdef USE_TINYUSB
|
||||||
#include "Adafruit_TinyUSB_Core.h"
|
#include "Adafruit_TinyUSB_Core.h"
|
||||||
#else
|
#else
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBDesc.h"
|
||||||
#include "USB/USBCore.h"
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBAPI.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USB_host.h"
|
#include "USB/USB_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
|||||||
@@ -35,259 +35,259 @@
|
|||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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 */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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 */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
{
|
{
|
||||||
if (write(*buffer++))
|
if (write(*buffer++))
|
||||||
n++;
|
n++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
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)
|
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[])
|
size_t Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
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)
|
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)
|
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)
|
size_t Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printNumber(n, 10) + t;
|
return printNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printNumber(n, 10);
|
return printNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printNumber(n, base);
|
return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long long n, int base)
|
size_t Print::print(long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
{
|
{
|
||||||
return write(n);
|
return write(n);
|
||||||
}
|
}
|
||||||
else if (base == 10)
|
else if (base == 10)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
int t = print('-');
|
int t = print('-');
|
||||||
n = -n;
|
n = -n;
|
||||||
return printULLNumber(n, 10) + t;
|
return printULLNumber(n, 10) + t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printULLNumber(n, 10);
|
return printULLNumber(n, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long long n, int base)
|
size_t Print::print(unsigned long long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0)
|
if (base == 0)
|
||||||
return write(n);
|
return write(n);
|
||||||
else
|
else
|
||||||
return printULLNumber(n, base);
|
return printULLNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
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 Print::println(const __FlashStringHelper *ifsh)
|
||||||
{
|
{
|
||||||
size_t n = print(ifsh);
|
size_t n = print(ifsh);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t Print::println(void)
|
||||||
{
|
{
|
||||||
return write("\r\n");
|
return write("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long long num, int base)
|
size_t Print::println(long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long long num, int base)
|
size_t Print::println(unsigned long long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printf(const char * format, ...)
|
size_t Print::printf(const char * format, ...)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
|
||||||
len = vsnprintf(buf, 256, format, ap);
|
len = vsnprintf(buf, 256, format, ap);
|
||||||
this->write(buf, len);
|
this->write(buf, len);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||||
{
|
{
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c = n % base;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFERENCE IMPLEMENTATION FOR ULL
|
// REFERENCE IMPLEMENTATION FOR ULL
|
||||||
@@ -315,152 +315,152 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
|||||||
// FAST IMPLEMENTATION FOR ULL
|
// FAST IMPLEMENTATION FOR ULL
|
||||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||||
{
|
{
|
||||||
// if limited to base 10 and 16 the bufsize can be 20
|
// if limited to base 10 and 16 the bufsize can be 20
|
||||||
char buf[64];
|
char buf[64];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint8_t innerLoops = 0;
|
uint8_t innerLoops = 0;
|
||||||
|
|
||||||
// prevent crash if called with base == 1
|
// prevent crash if called with base == 1
|
||||||
if (base < 2)
|
if (base < 2)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
// process chunks that fit in "16 bit math".
|
// process chunks that fit in "16 bit math".
|
||||||
uint16_t top = 0xFFFF / base;
|
uint16_t top = 0xFFFF / base;
|
||||||
uint16_t th16 = 1;
|
uint16_t th16 = 1;
|
||||||
|
|
||||||
while (th16 < top)
|
while (th16 < top)
|
||||||
{
|
{
|
||||||
th16 *= base;
|
th16 *= base;
|
||||||
innerLoops++;
|
innerLoops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n64 > th16)
|
while (n64 > th16)
|
||||||
{
|
{
|
||||||
// 64 bit math part
|
// 64 bit math part
|
||||||
uint64_t q = n64 / th16;
|
uint64_t q = n64 / th16;
|
||||||
uint16_t r = n64 - q * th16;
|
uint16_t r = n64 - q * th16;
|
||||||
n64 = q;
|
n64 = q;
|
||||||
|
|
||||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||||
for (uint8_t j = 0; j < innerLoops; j++)
|
for (uint8_t j = 0; j < innerLoops; j++)
|
||||||
{
|
{
|
||||||
uint16_t qq = r / base;
|
uint16_t qq = r / base;
|
||||||
buf[i++] = r - qq * base;
|
buf[i++] = r - qq * base;
|
||||||
r = qq;
|
r = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t n16 = n64;
|
uint16_t n16 = n64;
|
||||||
|
|
||||||
while (n16 > 0)
|
while (n16 > 0)
|
||||||
{
|
{
|
||||||
uint16_t qq = n16 / base;
|
uint16_t qq = n16 / base;
|
||||||
buf[i++] = n16 - qq * base;
|
buf[i++] = n16 - qq * base;
|
||||||
n16 = qq;
|
n16 = qq;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = i;
|
size_t bytes = i;
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
write((char) (buf[i - 1] < 10 ?
|
write((char) (buf[i - 1] < 10 ?
|
||||||
'0' + buf[i - 1] :
|
'0' + buf[i - 1] :
|
||||||
'A' + buf[i - 1] - 10));
|
'A' + buf[i - 1] - 10));
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, int digits)
|
size_t Print::printFloat(double number, int digits)
|
||||||
{
|
{
|
||||||
if (digits < 0)
|
if (digits < 0)
|
||||||
digits = 2;
|
digits = 2;
|
||||||
|
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isnan(number))
|
if (isnan(number))
|
||||||
return print("nan");
|
return print("nan");
|
||||||
|
|
||||||
if (isinf(number))
|
if (isinf(number))
|
||||||
return print("inf");
|
return print("inf");
|
||||||
|
|
||||||
if (number > 4294967040.0)
|
if (number > 4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
if (number < -4294967040.0)
|
if (number < -4294967040.0)
|
||||||
return print ("ovf"); // constant determined empirically
|
return print ("ovf"); // constant determined empirically
|
||||||
|
|
||||||
// Handle negative numbers
|
// Handle negative numbers
|
||||||
if (number < 0.0)
|
if (number < 0.0)
|
||||||
{
|
{
|
||||||
n += print('-');
|
n += print('-');
|
||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < digits; ++i)
|
for (uint8_t i = 0; i < digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
unsigned long int_part = (unsigned long)number;
|
unsigned long int_part = (unsigned long)number;
|
||||||
double remainder = number - (double)int_part;
|
double remainder = number - (double)int_part;
|
||||||
n += print(int_part);
|
n += print(int_part);
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
{
|
{
|
||||||
n += print(".");
|
n += print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
{
|
{
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
unsigned int toPrint = (unsigned int)remainder;
|
unsigned int toPrint = (unsigned int)remainder;
|
||||||
n += print(toPrint);
|
n += print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if ( i != 0 )
|
if ( i != 0 )
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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)
|
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||||
{
|
{
|
||||||
if (buffer == NULL || len == 0)
|
if (buffer == NULL || len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
print(delim);
|
print(delim);
|
||||||
|
|
||||||
if ( byteline && (i % byteline == 0) )
|
if ( byteline && (i % byteline == 0) )
|
||||||
println();
|
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
|
class Print
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int write_error;
|
int write_error;
|
||||||
size_t printNumber(unsigned long, uint8_t);
|
size_t printNumber(unsigned long, uint8_t);
|
||||||
size_t printULLNumber(unsigned long long, uint8_t);
|
size_t printULLNumber(unsigned long long, uint8_t);
|
||||||
size_t printFloat(double, int);
|
size_t printFloat(double, int);
|
||||||
protected:
|
protected:
|
||||||
void setWriteError(int err = 1)
|
void setWriteError(int err = 1)
|
||||||
{
|
{
|
||||||
write_error = err;
|
write_error = err;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Print() : write_error(0) {}
|
Print() : write_error(0) {}
|
||||||
|
|
||||||
int getWriteError()
|
int getWriteError()
|
||||||
{
|
{
|
||||||
return write_error;
|
return write_error;
|
||||||
}
|
}
|
||||||
void clearWriteError()
|
void clearWriteError()
|
||||||
{
|
{
|
||||||
setWriteError(0);
|
setWriteError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
size_t write(const char *str)
|
size_t write(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
size_t write(const char *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 *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to zero, meaning "a single write may block"
|
// default to zero, meaning "a single write may block"
|
||||||
// should be overridden by subclasses with buffering
|
// should be overridden by subclasses with buffering
|
||||||
virtual int availableForWrite()
|
virtual int availableForWrite()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print(const __FlashStringHelper *);
|
size_t print(const __FlashStringHelper *);
|
||||||
size_t print(const String &);
|
size_t print(const String &);
|
||||||
size_t print(const char[]);
|
size_t print(const char[]);
|
||||||
size_t print(char);
|
size_t print(char);
|
||||||
size_t print(unsigned char, int = DEC);
|
size_t print(unsigned char, int = DEC);
|
||||||
size_t print(int, int = DEC);
|
size_t print(int, int = DEC);
|
||||||
size_t print(unsigned int, int = DEC);
|
size_t print(unsigned int, int = DEC);
|
||||||
size_t print(long, int = DEC);
|
size_t print(long, int = DEC);
|
||||||
size_t print(unsigned long, int = DEC);
|
size_t print(unsigned long, int = DEC);
|
||||||
size_t print(long long, int = DEC);
|
size_t print(long long, int = DEC);
|
||||||
size_t print(unsigned long long, int = DEC);
|
size_t print(unsigned long long, int = DEC);
|
||||||
size_t print(double, int = 2);
|
size_t print(double, int = 2);
|
||||||
size_t print(const Printable&);
|
size_t print(const Printable&);
|
||||||
|
|
||||||
size_t println(const __FlashStringHelper *);
|
size_t println(const __FlashStringHelper *);
|
||||||
size_t println(const String &s);
|
size_t println(const String &s);
|
||||||
size_t println(const char[]);
|
size_t println(const char[]);
|
||||||
size_t println(char);
|
size_t println(char);
|
||||||
size_t println(unsigned char, int = DEC);
|
size_t println(unsigned char, int = DEC);
|
||||||
size_t println(int, int = DEC);
|
size_t println(int, int = DEC);
|
||||||
size_t println(unsigned int, int = DEC);
|
size_t println(unsigned int, int = DEC);
|
||||||
size_t println(long, int = DEC);
|
size_t println(long, int = DEC);
|
||||||
size_t println(unsigned long, int = DEC);
|
size_t println(unsigned long, int = DEC);
|
||||||
size_t println(long long, int = DEC);
|
size_t println(long long, int = DEC);
|
||||||
size_t println(unsigned long long, int = DEC);
|
size_t println(unsigned long long, int = DEC);
|
||||||
size_t println(double, int = 2);
|
size_t println(double, int = 2);
|
||||||
size_t println(const Printable&);
|
size_t println(const Printable&);
|
||||||
size_t println(void);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBuffer(char const buffer[], int size, 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);
|
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(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||||
size_t printBufferReverse(char const buffer[], int size, 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);
|
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
|
// private method to read stream with timeout
|
||||||
int Stream::timedRead()
|
int Stream::timedRead()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = read();
|
c = read();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} while (millis() - startMillis < _timeout);
|
||||||
|
|
||||||
Serial.print(("timedRead timeout = "));
|
Serial.print(("timedRead timeout = "));
|
||||||
Serial.println(_timeout);
|
Serial.println(_timeout);
|
||||||
|
|
||||||
return -1; // -1 indicates timeout
|
return -1; // -1 indicates timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// private method to peek stream with timeout
|
// private method to peek stream with timeout
|
||||||
int Stream::timedPeek()
|
int Stream::timedPeek()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = peek();
|
c = peek();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} 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
|
// returns peek of the next digit in the stream or -1 if timeout
|
||||||
// discards non-numeric characters
|
// discards non-numeric characters
|
||||||
int Stream::peekNextDigit()
|
int Stream::peekNextDigit()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return c; // timeout
|
return c; // timeout
|
||||||
|
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
read(); // discard non-numeric
|
read(); // discard non-numeric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods
|
// Public Methods
|
||||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
|||||||
|
|
||||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
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
|
// find returns true if the target string is found
|
||||||
bool Stream::find(const char *target)
|
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
|
// 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
|
// returns true if target string is found, false if timed out
|
||||||
bool Stream::find(const char *target, size_t length)
|
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
|
// as find but search ends if the terminator string is found
|
||||||
bool Stream::findUntil(const char *target, const char *terminator)
|
bool Stream::findUntil(const char *target, const char *terminator)
|
||||||
{
|
{
|
||||||
if (target == nullptr)
|
if (target == nullptr)
|
||||||
return true;
|
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
|
// 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
|
// 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)
|
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 index = 0; // maximum target string length is 64k bytes!
|
||||||
size_t termIndex = 0;
|
size_t termIndex = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if ( target == nullptr)
|
if ( target == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( *target == 0)
|
if ( *target == 0)
|
||||||
return true; // return true if target is a null string
|
return true; // return true if target is a null string
|
||||||
|
|
||||||
if (terminator == nullptr)
|
if (terminator == nullptr)
|
||||||
termLen = 0;
|
termLen = 0;
|
||||||
|
|
||||||
while ( (c = timedRead()) > 0)
|
while ( (c = timedRead()) > 0)
|
||||||
{
|
{
|
||||||
if ( c == target[index])
|
if ( c == target[index])
|
||||||
{
|
{
|
||||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||||
if (++index >= targetLen)
|
if (++index >= targetLen)
|
||||||
{
|
{
|
||||||
// return true if all chars in the target match
|
// return true if all chars in the target match
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = 0; // reset index if any char does not match
|
index = 0; // reset index if any char does not match
|
||||||
}
|
}
|
||||||
|
|
||||||
if (termLen > 0 && c == terminator[termIndex])
|
if (termLen > 0 && c == terminator[termIndex])
|
||||||
{
|
{
|
||||||
if (++termIndex >= termLen)
|
if (++termIndex >= termLen)
|
||||||
return false; // return false if terminate string found before target string
|
return false; // return false if terminate string found before target string
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
termIndex = 0;
|
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.
|
// function is terminated by the first character that is not a digit.
|
||||||
long Stream::parseInt()
|
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
|
// as above but a given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
long Stream::parseInt(char skipChar)
|
long Stream::parseInt(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore this charactor
|
; // ignore this charactor
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c >= '0' && c <= '9') // is c a digit?
|
else if (c >= '0' && c <= '9') // is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// as parseInt but returns a floating point value
|
// as parseInt but returns a floating point value
|
||||||
float Stream::parseFloat()
|
float Stream::parseFloat()
|
||||||
{
|
{
|
||||||
return parseFloat(NO_SKIP_CHAR);
|
return parseFloat(NO_SKIP_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as above but the given skipChar is ignored
|
// as above but the given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
float Stream::parseFloat(char skipChar)
|
float Stream::parseFloat(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
boolean isFraction = false;
|
boolean isFraction = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
float fraction = 1.0;
|
float fraction = 1.0;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore
|
; // ignore
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c == '.')
|
else if (c == '.')
|
||||||
isFraction = true;
|
isFraction = true;
|
||||||
else if (c >= '0' && c <= '9')
|
else if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
// is c a digit?
|
// is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
fraction *= 0.1f;
|
fraction *= 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
return value * fraction;
|
return value * fraction;
|
||||||
else
|
else
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read characters from stream into buffer
|
// read characters from stream into buffer
|
||||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
|||||||
//
|
//
|
||||||
size_t Stream::readBytes(char *buffer, size_t length)
|
size_t Stream::readBytes(char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
while (count < length)
|
while (count < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
count++;
|
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)
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
length--;
|
length--;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (index < length)
|
while (index < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c == terminator)
|
if (c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = 0;
|
*buffer = 0;
|
||||||
return index; // return number of characters, not including null terminator
|
return index; // return number of characters, not including null terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
|||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
while (c >= 0)
|
while (c >= 0)
|
||||||
{
|
{
|
||||||
ret += (char)c;
|
ret += (char)c;
|
||||||
c = timedRead();
|
c = timedRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char readStringBuffer[2048];
|
char readStringBuffer[2048];
|
||||||
|
|
||||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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 Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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
|
#else
|
||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Stream::readStringUntil(char terminator, size_t max)
|
String Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0 || c == terminator)
|
if (c == 0 || c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,124 +25,124 @@
|
|||||||
|
|
||||||
class Stream : public Print
|
class Stream : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
|
|
||||||
void setTimeout(unsigned long timeout);
|
void setTimeout(unsigned long timeout);
|
||||||
bool find(const char *target);
|
bool find(const char *target);
|
||||||
|
|
||||||
bool find(const uint8_t *target)
|
bool find(const uint8_t *target)
|
||||||
{
|
{
|
||||||
return find ((const char *)target);
|
return find ((const char *)target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target)
|
bool find(const String &target)
|
||||||
{
|
{
|
||||||
return find(target.c_str());
|
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)
|
bool find(const uint8_t *target, size_t length)
|
||||||
{
|
{
|
||||||
return find ((const char *)target, length);
|
return find ((const char *)target, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target, size_t length)
|
bool find(const String &target, size_t length)
|
||||||
{
|
{
|
||||||
return find(target.c_str(), 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)
|
bool findUntil(const uint8_t *target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, terminator);
|
return findUntil((const char *)target, terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const char *terminator)
|
bool findUntil(const String &target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator);
|
return findUntil(target.c_str(), terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const char *target, const String &terminator)
|
bool findUntil(const char *target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target, terminator.c_str());
|
return findUntil(target, terminator.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const String &terminator)
|
bool findUntil(const String &target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator.c_str());
|
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)
|
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, targetLen, terminate, 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 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 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 String &terminate, size_t termLen);
|
||||||
|
|
||||||
long parseInt();
|
long parseInt();
|
||||||
long parseInt(char skipChar);
|
long parseInt(char skipChar);
|
||||||
|
|
||||||
float parseFloat();
|
float parseFloat();
|
||||||
float parseFloat(char skipChar);
|
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)
|
size_t readBytes(uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytes((char *)buffer, 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)
|
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytesUntil(terminator, (char *)buffer, length);
|
return readBytesUntil(terminator, (char *)buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
String readString(size_t max = 512);
|
String readString(size_t max = 512);
|
||||||
String readStringUntil(char terminator, size_t max = 512);
|
String readStringUntil(char terminator, size_t max = 512);
|
||||||
|
|
||||||
// KH, to not use String
|
// KH, to not use String
|
||||||
char* readCharsUntil(char terminator, size_t max = 512);
|
char* readCharsUntil(char terminator, size_t max = 512);
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int getReadError()
|
int getReadError()
|
||||||
{
|
{
|
||||||
return read_error;
|
return read_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearReadError()
|
void clearReadError()
|
||||||
{
|
{
|
||||||
setReadError(0);
|
setReadError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setReadError(int err = 1)
|
void setReadError(int err = 1)
|
||||||
{
|
{
|
||||||
read_error = err;
|
read_error = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long _timeout;
|
unsigned long _timeout;
|
||||||
|
|
||||||
// KH
|
// KH
|
||||||
int timedRead();
|
int timedRead();
|
||||||
int timedPeek();
|
int timedPeek();
|
||||||
int peekNextDigit();
|
int peekNextDigit();
|
||||||
//////
|
//////
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char read_error;
|
char read_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,65 +28,65 @@
|
|||||||
// private method to read stream with timeout
|
// private method to read stream with timeout
|
||||||
int Stream::timedRead()
|
int Stream::timedRead()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = read();
|
c = read();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} while (millis() - startMillis < _timeout);
|
||||||
|
|
||||||
Serial.print(("timedRead timeout = "));
|
Serial.print(("timedRead timeout = "));
|
||||||
Serial.println(_timeout);
|
Serial.println(_timeout);
|
||||||
|
|
||||||
return -1; // -1 indicates timeout
|
return -1; // -1 indicates timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// private method to peek stream with timeout
|
// private method to peek stream with timeout
|
||||||
int Stream::timedPeek()
|
int Stream::timedPeek()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = peek();
|
c = peek();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} 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
|
// returns peek of the next digit in the stream or -1 if timeout
|
||||||
// discards non-numeric characters
|
// discards non-numeric characters
|
||||||
int Stream::peekNextDigit()
|
int Stream::peekNextDigit()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return c; // timeout
|
return c; // timeout
|
||||||
|
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
read(); // discard non-numeric
|
read(); // discard non-numeric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods
|
// Public Methods
|
||||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
|||||||
|
|
||||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
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
|
// find returns true if the target string is found
|
||||||
bool Stream::find(const char *target)
|
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
|
// 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
|
// returns true if target string is found, false if timed out
|
||||||
bool Stream::find(const char *target, size_t length)
|
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
|
// as find but search ends if the terminator string is found
|
||||||
bool Stream::findUntil(const char *target, const char *terminator)
|
bool Stream::findUntil(const char *target, const char *terminator)
|
||||||
{
|
{
|
||||||
if (target == nullptr)
|
if (target == nullptr)
|
||||||
return true;
|
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
|
// 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
|
// 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)
|
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 index = 0; // maximum target string length is 64k bytes!
|
||||||
size_t termIndex = 0;
|
size_t termIndex = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if ( target == nullptr)
|
if ( target == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( *target == 0)
|
if ( *target == 0)
|
||||||
return true; // return true if target is a null string
|
return true; // return true if target is a null string
|
||||||
|
|
||||||
if (terminator == nullptr)
|
if (terminator == nullptr)
|
||||||
termLen = 0;
|
termLen = 0;
|
||||||
|
|
||||||
while ( (c = timedRead()) > 0)
|
while ( (c = timedRead()) > 0)
|
||||||
{
|
{
|
||||||
if ( c == target[index])
|
if ( c == target[index])
|
||||||
{
|
{
|
||||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||||
if (++index >= targetLen)
|
if (++index >= targetLen)
|
||||||
{
|
{
|
||||||
// return true if all chars in the target match
|
// return true if all chars in the target match
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = 0; // reset index if any char does not match
|
index = 0; // reset index if any char does not match
|
||||||
}
|
}
|
||||||
|
|
||||||
if (termLen > 0 && c == terminator[termIndex])
|
if (termLen > 0 && c == terminator[termIndex])
|
||||||
{
|
{
|
||||||
if (++termIndex >= termLen)
|
if (++termIndex >= termLen)
|
||||||
return false; // return false if terminate string found before target string
|
return false; // return false if terminate string found before target string
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
termIndex = 0;
|
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.
|
// function is terminated by the first character that is not a digit.
|
||||||
long Stream::parseInt()
|
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
|
// as above but a given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
long Stream::parseInt(char skipChar)
|
long Stream::parseInt(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore this charactor
|
; // ignore this charactor
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c >= '0' && c <= '9') // is c a digit?
|
else if (c >= '0' && c <= '9') // is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// as parseInt but returns a floating point value
|
// as parseInt but returns a floating point value
|
||||||
float Stream::parseFloat()
|
float Stream::parseFloat()
|
||||||
{
|
{
|
||||||
return parseFloat(NO_SKIP_CHAR);
|
return parseFloat(NO_SKIP_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as above but the given skipChar is ignored
|
// as above but the given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
float Stream::parseFloat(char skipChar)
|
float Stream::parseFloat(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
boolean isFraction = false;
|
boolean isFraction = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
float fraction = 1.0;
|
float fraction = 1.0;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore
|
; // ignore
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c == '.')
|
else if (c == '.')
|
||||||
isFraction = true;
|
isFraction = true;
|
||||||
else if (c >= '0' && c <= '9')
|
else if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
// is c a digit?
|
// is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
fraction *= 0.1f;
|
fraction *= 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
return value * fraction;
|
return value * fraction;
|
||||||
else
|
else
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read characters from stream into buffer
|
// read characters from stream into buffer
|
||||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
|||||||
//
|
//
|
||||||
size_t Stream::readBytes(char *buffer, size_t length)
|
size_t Stream::readBytes(char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
while (count < length)
|
while (count < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
count++;
|
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)
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
length--;
|
length--;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (index < length)
|
while (index < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c == terminator)
|
if (c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = 0;
|
*buffer = 0;
|
||||||
return index; // return number of characters, not including null terminator
|
return index; // return number of characters, not including null terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
|||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
while (c >= 0)
|
while (c >= 0)
|
||||||
{
|
{
|
||||||
ret += (char)c;
|
ret += (char)c;
|
||||||
c = timedRead();
|
c = timedRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char readStringBuffer[2048];
|
char readStringBuffer[2048];
|
||||||
|
|
||||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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 Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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
|
#else
|
||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Stream::readStringUntil(char terminator, size_t max)
|
String Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0 || c == terminator)
|
if (c == 0 || c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,124 +25,124 @@
|
|||||||
|
|
||||||
class Stream : public Print
|
class Stream : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
|
|
||||||
void setTimeout(unsigned long timeout);
|
void setTimeout(unsigned long timeout);
|
||||||
bool find(const char *target);
|
bool find(const char *target);
|
||||||
|
|
||||||
bool find(const uint8_t *target)
|
bool find(const uint8_t *target)
|
||||||
{
|
{
|
||||||
return find ((const char *)target);
|
return find ((const char *)target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target)
|
bool find(const String &target)
|
||||||
{
|
{
|
||||||
return find(target.c_str());
|
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)
|
bool find(const uint8_t *target, size_t length)
|
||||||
{
|
{
|
||||||
return find ((const char *)target, length);
|
return find ((const char *)target, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target, size_t length)
|
bool find(const String &target, size_t length)
|
||||||
{
|
{
|
||||||
return find(target.c_str(), 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)
|
bool findUntil(const uint8_t *target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, terminator);
|
return findUntil((const char *)target, terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const char *terminator)
|
bool findUntil(const String &target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator);
|
return findUntil(target.c_str(), terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const char *target, const String &terminator)
|
bool findUntil(const char *target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target, terminator.c_str());
|
return findUntil(target, terminator.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const String &terminator)
|
bool findUntil(const String &target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator.c_str());
|
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)
|
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, targetLen, terminate, 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 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 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 String &terminate, size_t termLen);
|
||||||
|
|
||||||
long parseInt();
|
long parseInt();
|
||||||
long parseInt(char skipChar);
|
long parseInt(char skipChar);
|
||||||
|
|
||||||
float parseFloat();
|
float parseFloat();
|
||||||
float parseFloat(char skipChar);
|
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)
|
size_t readBytes(uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytes((char *)buffer, 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)
|
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytesUntil(terminator, (char *)buffer, length);
|
return readBytesUntil(terminator, (char *)buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
String readString(size_t max = 512);
|
String readString(size_t max = 512);
|
||||||
String readStringUntil(char terminator, size_t max = 512);
|
String readStringUntil(char terminator, size_t max = 512);
|
||||||
|
|
||||||
// KH, to not use String
|
// KH, to not use String
|
||||||
char* readCharsUntil(char terminator, size_t max = 512);
|
char* readCharsUntil(char terminator, size_t max = 512);
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int getReadError()
|
int getReadError()
|
||||||
{
|
{
|
||||||
return read_error;
|
return read_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearReadError()
|
void clearReadError()
|
||||||
{
|
{
|
||||||
setReadError(0);
|
setReadError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setReadError(int err = 1)
|
void setReadError(int err = 1)
|
||||||
{
|
{
|
||||||
read_error = err;
|
read_error = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long _timeout;
|
unsigned long _timeout;
|
||||||
|
|
||||||
// KH
|
// KH
|
||||||
int timedRead();
|
int timedRead();
|
||||||
int timedPeek();
|
int timedPeek();
|
||||||
int peekNextDigit();
|
int peekNextDigit();
|
||||||
//////
|
//////
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char read_error;
|
char read_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,65 +28,65 @@
|
|||||||
// private method to read stream with timeout
|
// private method to read stream with timeout
|
||||||
int Stream::timedRead()
|
int Stream::timedRead()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = read();
|
c = read();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} while (millis() - startMillis < _timeout);
|
||||||
|
|
||||||
Serial.print(("timedRead timeout = "));
|
Serial.print(("timedRead timeout = "));
|
||||||
Serial.println(_timeout);
|
Serial.println(_timeout);
|
||||||
|
|
||||||
return -1; // -1 indicates timeout
|
return -1; // -1 indicates timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// private method to peek stream with timeout
|
// private method to peek stream with timeout
|
||||||
int Stream::timedPeek()
|
int Stream::timedPeek()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = peek();
|
c = peek();
|
||||||
|
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
} while (millis() - startMillis < _timeout);
|
} 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
|
// returns peek of the next digit in the stream or -1 if timeout
|
||||||
// discards non-numeric characters
|
// discards non-numeric characters
|
||||||
int Stream::peekNextDigit()
|
int Stream::peekNextDigit()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return c; // timeout
|
return c; // timeout
|
||||||
|
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
read(); // discard non-numeric
|
read(); // discard non-numeric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods
|
// Public Methods
|
||||||
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
|
|||||||
|
|
||||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
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
|
// find returns true if the target string is found
|
||||||
bool Stream::find(const char *target)
|
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
|
// 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
|
// returns true if target string is found, false if timed out
|
||||||
bool Stream::find(const char *target, size_t length)
|
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
|
// as find but search ends if the terminator string is found
|
||||||
bool Stream::findUntil(const char *target, const char *terminator)
|
bool Stream::findUntil(const char *target, const char *terminator)
|
||||||
{
|
{
|
||||||
if (target == nullptr)
|
if (target == nullptr)
|
||||||
return true;
|
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
|
// 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
|
// 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)
|
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 index = 0; // maximum target string length is 64k bytes!
|
||||||
size_t termIndex = 0;
|
size_t termIndex = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if ( target == nullptr)
|
if ( target == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( *target == 0)
|
if ( *target == 0)
|
||||||
return true; // return true if target is a null string
|
return true; // return true if target is a null string
|
||||||
|
|
||||||
if (terminator == nullptr)
|
if (terminator == nullptr)
|
||||||
termLen = 0;
|
termLen = 0;
|
||||||
|
|
||||||
while ( (c = timedRead()) > 0)
|
while ( (c = timedRead()) > 0)
|
||||||
{
|
{
|
||||||
if ( c == target[index])
|
if ( c == target[index])
|
||||||
{
|
{
|
||||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||||
if (++index >= targetLen)
|
if (++index >= targetLen)
|
||||||
{
|
{
|
||||||
// return true if all chars in the target match
|
// return true if all chars in the target match
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = 0; // reset index if any char does not match
|
index = 0; // reset index if any char does not match
|
||||||
}
|
}
|
||||||
|
|
||||||
if (termLen > 0 && c == terminator[termIndex])
|
if (termLen > 0 && c == terminator[termIndex])
|
||||||
{
|
{
|
||||||
if (++termIndex >= termLen)
|
if (++termIndex >= termLen)
|
||||||
return false; // return false if terminate string found before target string
|
return false; // return false if terminate string found before target string
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
termIndex = 0;
|
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.
|
// function is terminated by the first character that is not a digit.
|
||||||
long Stream::parseInt()
|
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
|
// as above but a given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
long Stream::parseInt(char skipChar)
|
long Stream::parseInt(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore this charactor
|
; // ignore this charactor
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c >= '0' && c <= '9') // is c a digit?
|
else if (c >= '0' && c <= '9') // is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// as parseInt but returns a floating point value
|
// as parseInt but returns a floating point value
|
||||||
float Stream::parseFloat()
|
float Stream::parseFloat()
|
||||||
{
|
{
|
||||||
return parseFloat(NO_SKIP_CHAR);
|
return parseFloat(NO_SKIP_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as above but the given skipChar is ignored
|
// as above but the given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
float Stream::parseFloat(char skipChar)
|
float Stream::parseFloat(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
boolean isFraction = false;
|
boolean isFraction = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
int c;
|
int c;
|
||||||
float fraction = 1.0;
|
float fraction = 1.0;
|
||||||
|
|
||||||
c = peekNextDigit();
|
c = peekNextDigit();
|
||||||
|
|
||||||
// ignore non numeric leading characters
|
// ignore non numeric leading characters
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
return 0; // zero returned if timeout
|
return 0; // zero returned if timeout
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == skipChar)
|
if (c == skipChar)
|
||||||
; // ignore
|
; // ignore
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
isNegative = true;
|
isNegative = true;
|
||||||
else if (c == '.')
|
else if (c == '.')
|
||||||
isFraction = true;
|
isFraction = true;
|
||||||
else if (c >= '0' && c <= '9')
|
else if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
// is c a digit?
|
// is c a digit?
|
||||||
value = value * 10 + c - '0';
|
value = value * 10 + c - '0';
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
fraction *= 0.1f;
|
fraction *= 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(); // consume the character we got with peek
|
read(); // consume the character we got with peek
|
||||||
c = timedPeek();
|
c = timedPeek();
|
||||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||||
|
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
if (isFraction)
|
if (isFraction)
|
||||||
return value * fraction;
|
return value * fraction;
|
||||||
else
|
else
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read characters from stream into buffer
|
// read characters from stream into buffer
|
||||||
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
|
|||||||
//
|
//
|
||||||
size_t Stream::readBytes(char *buffer, size_t length)
|
size_t Stream::readBytes(char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
while (count < length)
|
while (count < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
count++;
|
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)
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
length--;
|
length--;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (index < length)
|
while (index < length)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c == terminator)
|
if (c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer++ = (char)c;
|
*buffer++ = (char)c;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = 0;
|
*buffer = 0;
|
||||||
return index; // return number of characters, not including null terminator
|
return index; // return number of characters, not including null terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
|||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
while (c >= 0)
|
while (c >= 0)
|
||||||
{
|
{
|
||||||
ret += (char)c;
|
ret += (char)c;
|
||||||
c = timedRead();
|
c = timedRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char readStringBuffer[2048];
|
char readStringBuffer[2048];
|
||||||
|
|
||||||
char* Stream::readCharsUntil(char terminator, size_t max)
|
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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 Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
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)
|
while (c >= 0 && c != terminator)
|
||||||
{
|
{
|
||||||
c = timedRead();
|
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
|
#else
|
||||||
|
|
||||||
String Stream::readString(size_t max)
|
String Stream::readString(size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Stream::readStringUntil(char terminator, size_t max)
|
String Stream::readStringUntil(char terminator, size_t max)
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
while (length < max)
|
while (length < max)
|
||||||
{
|
{
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
{
|
{
|
||||||
setReadError();
|
setReadError();
|
||||||
break; // timeout
|
break; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0 || c == terminator)
|
if (c == 0 || c == terminator)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str += (char)c;
|
str += (char)c;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,124 +25,124 @@
|
|||||||
|
|
||||||
class Stream : public Print
|
class Stream : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Stream() : _timeout(1000), read_error(0) {}
|
constexpr Stream() : _timeout(1000), read_error(0) {}
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
|
|
||||||
void setTimeout(unsigned long timeout);
|
void setTimeout(unsigned long timeout);
|
||||||
bool find(const char *target);
|
bool find(const char *target);
|
||||||
|
|
||||||
bool find(const uint8_t *target)
|
bool find(const uint8_t *target)
|
||||||
{
|
{
|
||||||
return find ((const char *)target);
|
return find ((const char *)target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target)
|
bool find(const String &target)
|
||||||
{
|
{
|
||||||
return find(target.c_str());
|
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)
|
bool find(const uint8_t *target, size_t length)
|
||||||
{
|
{
|
||||||
return find ((const char *)target, length);
|
return find ((const char *)target, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find(const String &target, size_t length)
|
bool find(const String &target, size_t length)
|
||||||
{
|
{
|
||||||
return find(target.c_str(), 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)
|
bool findUntil(const uint8_t *target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, terminator);
|
return findUntil((const char *)target, terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const char *terminator)
|
bool findUntil(const String &target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator);
|
return findUntil(target.c_str(), terminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const char *target, const String &terminator)
|
bool findUntil(const char *target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target, terminator.c_str());
|
return findUntil(target, terminator.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findUntil(const String &target, const String &terminator)
|
bool findUntil(const String &target, const String &terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target.c_str(), terminator.c_str());
|
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)
|
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
|
||||||
{
|
{
|
||||||
return findUntil((const char *)target, targetLen, terminate, 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 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 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 String &terminate, size_t termLen);
|
||||||
|
|
||||||
long parseInt();
|
long parseInt();
|
||||||
long parseInt(char skipChar);
|
long parseInt(char skipChar);
|
||||||
|
|
||||||
float parseFloat();
|
float parseFloat();
|
||||||
float parseFloat(char skipChar);
|
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)
|
size_t readBytes(uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytes((char *)buffer, 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)
|
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
|
||||||
{
|
{
|
||||||
return readBytesUntil(terminator, (char *)buffer, length);
|
return readBytesUntil(terminator, (char *)buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
String readString(size_t max = 512);
|
String readString(size_t max = 512);
|
||||||
String readStringUntil(char terminator, size_t max = 512);
|
String readStringUntil(char terminator, size_t max = 512);
|
||||||
|
|
||||||
// KH, to not use String
|
// KH, to not use String
|
||||||
char* readCharsUntil(char terminator, size_t max = 512);
|
char* readCharsUntil(char terminator, size_t max = 512);
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int getReadError()
|
int getReadError()
|
||||||
{
|
{
|
||||||
return read_error;
|
return read_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearReadError()
|
void clearReadError()
|
||||||
{
|
{
|
||||||
setReadError(0);
|
setReadError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setReadError(int err = 1)
|
void setReadError(int err = 1)
|
||||||
{
|
{
|
||||||
read_error = err;
|
read_error = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long _timeout;
|
unsigned long _timeout;
|
||||||
|
|
||||||
// KH
|
// KH
|
||||||
int timedRead();
|
int timedRead();
|
||||||
int timedPeek();
|
int timedPeek();
|
||||||
int peekNextDigit();
|
int peekNextDigit();
|
||||||
//////
|
//////
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char read_error;
|
char read_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+47
-46
@@ -41,56 +41,57 @@
|
|||||||
class UDP : public Stream
|
class UDP : public Stream
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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 begin(uint16_t) =
|
||||||
virtual uint8_t beginMulticast(IPAddress, 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
|
{
|
||||||
}
|
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
|
// 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
|
// 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;
|
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
|
// 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
|
// 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;
|
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||||
// Finish off this packet and send it
|
// Finish off this packet and send it
|
||||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||||
virtual int endPacket() = 0;
|
virtual int endPacket() = 0;
|
||||||
// Write a single byte into the packet
|
// Write a single byte into the packet
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
// Write size bytes from buffer into the packet
|
// Write size bytes from buffer into the packet
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||||
|
|
||||||
// Start processing the next available incoming packet
|
// Start processing the next available incoming packet
|
||||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||||
virtual int parsePacket() = 0;
|
virtual int parsePacket() = 0;
|
||||||
// Number of bytes remaining in the current packet
|
// Number of bytes remaining in the current packet
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
// Read a single byte from the current packet
|
// Read a single byte from the current packet
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
// Read up to len bytes from the current packet and place them into buffer
|
// 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
|
// Returns the number of bytes read, or 0 if none are available
|
||||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||||
// Read up to len characters from the current packet and place them into buffer
|
// 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
|
// Returns the number of characters read, or 0 if none are available
|
||||||
virtual int read(char* buffer, size_t len) = 0;
|
virtual int read(char* buffer, size_t len) = 0;
|
||||||
// Return the next byte from the current packet without moving on to the next byte
|
// Return the next byte from the current packet without moving on to the next byte
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
virtual void flush() = 0; // Finish reading the current packet
|
virtual void flush() = 0; // Finish reading the current packet
|
||||||
|
|
||||||
// Return the IP address of the host who sent the current incoming packet
|
// Return the IP address of the host who sent the current incoming packet
|
||||||
virtual IPAddress remoteIP() = 0;
|
virtual IPAddress remoteIP() = 0;
|
||||||
// Return the port of the host who sent the current incoming packet
|
// Return the port of the host who sent the current incoming packet
|
||||||
virtual uint16_t remotePort() = 0;
|
virtual uint16_t remotePort() = 0;
|
||||||
protected:
|
protected:
|
||||||
uint8_t* rawIPAddress(IPAddress& addr)
|
uint8_t* rawIPAddress(IPAddress& addr)
|
||||||
{
|
{
|
||||||
return addr.raw_address();
|
return addr.raw_address();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+47
-46
@@ -41,56 +41,57 @@
|
|||||||
class UDP : public Stream
|
class UDP : public Stream
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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 begin(uint16_t) =
|
||||||
virtual uint8_t beginMulticast(IPAddress, 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
|
{
|
||||||
}
|
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
|
// 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
|
// 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;
|
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
|
// 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
|
// 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;
|
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||||
// Finish off this packet and send it
|
// Finish off this packet and send it
|
||||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||||
virtual int endPacket() = 0;
|
virtual int endPacket() = 0;
|
||||||
// Write a single byte into the packet
|
// Write a single byte into the packet
|
||||||
virtual size_t write(uint8_t) = 0;
|
virtual size_t write(uint8_t) = 0;
|
||||||
// Write size bytes from buffer into the packet
|
// Write size bytes from buffer into the packet
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||||
|
|
||||||
// Start processing the next available incoming packet
|
// Start processing the next available incoming packet
|
||||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||||
virtual int parsePacket() = 0;
|
virtual int parsePacket() = 0;
|
||||||
// Number of bytes remaining in the current packet
|
// Number of bytes remaining in the current packet
|
||||||
virtual int available() = 0;
|
virtual int available() = 0;
|
||||||
// Read a single byte from the current packet
|
// Read a single byte from the current packet
|
||||||
virtual int read() = 0;
|
virtual int read() = 0;
|
||||||
// Read up to len bytes from the current packet and place them into buffer
|
// 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
|
// Returns the number of bytes read, or 0 if none are available
|
||||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||||
// Read up to len characters from the current packet and place them into buffer
|
// 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
|
// Returns the number of characters read, or 0 if none are available
|
||||||
virtual int read(char* buffer, size_t len) = 0;
|
virtual int read(char* buffer, size_t len) = 0;
|
||||||
// Return the next byte from the current packet without moving on to the next byte
|
// Return the next byte from the current packet without moving on to the next byte
|
||||||
virtual int peek() = 0;
|
virtual int peek() = 0;
|
||||||
virtual void flush() = 0; // Finish reading the current packet
|
virtual void flush() = 0; // Finish reading the current packet
|
||||||
|
|
||||||
// Return the IP address of the host who sent the current incoming packet
|
// Return the IP address of the host who sent the current incoming packet
|
||||||
virtual IPAddress remoteIP() = 0;
|
virtual IPAddress remoteIP() = 0;
|
||||||
// Return the port of the host who sent the current incoming packet
|
// Return the port of the host who sent the current incoming packet
|
||||||
virtual uint16_t remotePort() = 0;
|
virtual uint16_t remotePort() = 0;
|
||||||
protected:
|
protected:
|
||||||
uint8_t* rawIPAddress(IPAddress& addr)
|
uint8_t* rawIPAddress(IPAddress& addr)
|
||||||
{
|
{
|
||||||
return addr.raw_address();
|
return addr.raw_address();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ unsigned long millis();
|
|||||||
template <size_t N>
|
template <size_t N>
|
||||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ unsigned long millis();
|
|||||||
template <size_t N>
|
template <size_t N>
|
||||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user