Browse Source

Update Print on Teensy 2.0 & Teensy++ 2.0

main
PaulStoffregen 7 years ago
parent
commit
bc36bfebdd
1 changed files with 4 additions and 62 deletions
  1. +4
    -62
      teensy/Print.h

+ 4
- 62
teensy/Print.h View File

@@ -40,14 +40,15 @@

class __FlashStringHelper;

#if ARDUINO >= 100
class Print
{
public:
Print() : write_error(0) {}
virtual size_t write(uint8_t b);
constexpr Print() : write_error(0) {}
virtual size_t write(uint8_t b) = 0;
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
virtual size_t write(const uint8_t *buffer, size_t size);
virtual int availableForWrite(void) { return 0; }
virtual void flush() { }
size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
size_t print(const String &s);
size_t print(char c) { return write((uint8_t)c); }
@@ -113,64 +114,5 @@ class Print
size_t printFloat(double n, uint8_t digits);
};

#else
class Print
{
public:
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
void print(const String &s);
void print(char c) { write((uint8_t)c); }
void print(const char s[]) { write(s); }
void print(const __FlashStringHelper *f);

void print(uint8_t b) { write(b); }
void print(int n) { print((long)n); }
void print(unsigned int n) { printNumber(n, 0, 10); }
void print(long n);
void print(unsigned long n) { printNumber(n, 0, 10); }

void print(unsigned char n, int base) { printNumber(n, 0, base); }
void print(int n, int base) { (base == 10) ? print(n) : printNumber(n, 0, base); }
void print(unsigned int n, int base) { printNumber(n, 0, base); }
void print(long n, int base) { (base == 10) ? print(n) : printNumber(n, 0, base); }
void print(unsigned long n, int base) { printNumber(n, 0, base); }

void print(double n, int digits = 2) { printFloat(n, digits); }
void println(void);
void println(const String &s) { print(s); println(); }
void println(char c) { print(c); println(); }
void println(const char s[]) { print(s); println(); }
void println(const __FlashStringHelper *f) { print(f); println(); }
void println(uint8_t b) { print(b); println(); }
void println(int n) { print(n); println(); }
void println(unsigned int n) { print(n); println(); }
void println(long n) { print(n); println(); }
void println(unsigned long n) { print(n); println(); }

void println(unsigned char n, int base) { print(n, base); println(); }
void println(int n, int base) { print(n, base); println(); }
void println(unsigned int n, int base) { print(n, base); println(); }
void println(long n, int base) { print(n, base); println(); }
void println(unsigned long n, int base) { print(n, base); println(); }

void println(double n, int digits = 2) { print(n, digits); println(); }
private:
void printNumberDec(unsigned long n, uint8_t sign);
void printNumberHex(unsigned long n);
void printNumberBin(unsigned long n);
void printNumberAny(unsigned long n, uint8_t base);
inline size_t printNumber(unsigned long n, uint8_t sign, uint8_t base) __attribute__((always_inline)) {
if (base == 0) { write((uint8_t)n); return; }
if (base == 10 || base < 2) { printNumberDec(n, sign); return; }
if (base == 16) { printNumberHex(n); return; }
if (base == 2) { printNumberBin(n); return; }
printNumberAny(n, base);
}
void printFloat(double n, uint8_t digits);
};
#endif


#endif

Loading…
Cancel
Save