diff --git a/Firmware/LiquidCrystal_Prusa.cpp b/Firmware/LiquidCrystal_Prusa.cpp index 1f0b69cd..fe2c837a 100644 --- a/Firmware/LiquidCrystal_Prusa.cpp +++ b/Firmware/LiquidCrystal_Prusa.cpp @@ -543,4 +543,171 @@ void LiquidCrystal_Prusa::write8bits(uint8_t value) { } pulseEnable(); -} \ No newline at end of file +} + +void LiquidCrystal_Prusa::print(const char* s) +{ + while (*s) write(*(s++)); +} + +void LiquidCrystal_Prusa::print(char c, int base) +{ + print((long) c, base); +} + +void LiquidCrystal_Prusa::print(unsigned char b, int base) +{ + print((unsigned long) b, base); +} + +void LiquidCrystal_Prusa::print(int n, int base) +{ + print((long) n, base); +} + +void LiquidCrystal_Prusa::print(unsigned int n, int base) +{ + print((unsigned long) n, base); +} + +void LiquidCrystal_Prusa::print(long n, int base) +{ + if (base == 0) { + write(n); + } else if (base == 10) { + if (n < 0) { + print('-'); + n = -n; + } + printNumber(n, 10); + } else { + printNumber(n, base); + } +} + +void LiquidCrystal_Prusa::print(unsigned long n, int base) +{ + if (base == 0) write(n); + else printNumber(n, base); +} + +void LiquidCrystal_Prusa::print(double n, int digits) +{ + printFloat(n, digits); +} + +void LiquidCrystal_Prusa::println(void) +{ + print('\r'); + print('\n'); +} + +/*void LiquidCrystal_Prusa::println(const String &s) +{ + print(s); + println(); +}*/ + +void LiquidCrystal_Prusa::println(const char c[]) +{ + print(c); + println(); +} + +void LiquidCrystal_Prusa::println(char c, int base) +{ + print(c, base); + println(); +} + +void LiquidCrystal_Prusa::println(unsigned char b, int base) +{ + print(b, base); + println(); +} + +void LiquidCrystal_Prusa::println(int n, int base) +{ + print(n, base); + println(); +} + +void LiquidCrystal_Prusa::println(unsigned int n, int base) +{ + print(n, base); + println(); +} + +void LiquidCrystal_Prusa::println(long n, int base) +{ + print(n, base); + println(); +} + +void LiquidCrystal_Prusa::println(unsigned long n, int base) +{ + print(n, base); + println(); +} + +void LiquidCrystal_Prusa::println(double n, int digits) +{ + print(n, digits); + println(); +} + +void LiquidCrystal_Prusa::printNumber(unsigned long n, uint8_t base) +{ + unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. + unsigned long i = 0; + + if (n == 0) { + print('0'); + return; + } + + while (n > 0) { + buf[i++] = n % base; + n /= base; + } + + for (; i > 0; i--) + print((char) (buf[i - 1] < 10 ? + '0' + buf[i - 1] : + 'A' + buf[i - 1] - 10)); +} + +void LiquidCrystal_Prusa::printFloat(double number, uint8_t digits) +{ + // Handle negative numbers + if (number < 0.0) + { + print('-'); + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + for (uint8_t i=0; i 0) + print("."); + + // Extract digits from the remainder one at a time + while (digits-- > 0) + { + remainder *= 10.0; + int toPrint = int(remainder); + print(toPrint); + remainder -= toPrint; + } +} diff --git a/Firmware/LiquidCrystal_Prusa.h b/Firmware/LiquidCrystal_Prusa.h index 7b72d098..77acaa91 100644 --- a/Firmware/LiquidCrystal_Prusa.h +++ b/Firmware/LiquidCrystal_Prusa.h @@ -2,7 +2,8 @@ #define LiquidCrystal_Prusa_h #include -#include "Print.h" +#include +//#include "Print.h" // commands #define LCD_CLEARDISPLAY 0x01 @@ -42,7 +43,7 @@ #define LCD_5x10DOTS 0x04 #define LCD_5x8DOTS 0x00 -class LiquidCrystal_Prusa : public Print { +class LiquidCrystal_Prusa/* : public Print */{ public: LiquidCrystal_Prusa(uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, @@ -81,10 +82,34 @@ public: void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); - virtual size_t write(uint8_t); +// virtual size_t write(uint8_t); + size_t write(uint8_t); void command(uint8_t); - - using Print::write; + + void print(const char*); + void print(char, int = 0); + void print(unsigned char, int = 0); + void print(int, int = 10); + void print(unsigned int, int = 10); + void print(long, int = 10); + void print(unsigned long, int = 10); + void print(double, int = 2); + +// void println(const String &s); + void println(const char[]); + void println(char, int = 0); + void println(unsigned char, int = 0); + void println(int, int = 10); + void println(unsigned int, int = 10); + void println(long, int = 10); + void println(unsigned long, int = 10); + void println(double, int = 2); + void println(void); + + void printNumber(unsigned long n, uint8_t base); + void printFloat(double number, uint8_t digits); + +// using Print::write; private: void send(uint8_t, uint8_t); void write4bits(uint8_t); diff --git a/Firmware/MarlinSerial.cpp b/Firmware/MarlinSerial.cpp index 02903a77..d3ffdfbe 100644 --- a/Firmware/MarlinSerial.cpp +++ b/Firmware/MarlinSerial.cpp @@ -259,11 +259,11 @@ void MarlinSerial::println(void) print('\n'); } -void MarlinSerial::println(const String &s) +/*void MarlinSerial::println(const String &s) { print(s); println(); -} +}*/ void MarlinSerial::println(const char c[]) { diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index 615b7eb9..81743475 100644 --- a/Firmware/MarlinSerial.h +++ b/Firmware/MarlinSerial.h @@ -197,12 +197,12 @@ class MarlinSerial //: public Stream write(*buffer++); } - static FORCE_INLINE void print(const String &s) +/* static FORCE_INLINE void print(const String &s) { for (int i = 0; i < (int)s.length(); i++) { write(s[i]); } - } + }*/ static FORCE_INLINE void print(const char *str) { diff --git a/Firmware/SdFile.h b/Firmware/SdFile.h index cbf1bbdb..60e2f5de 100644 --- a/Firmware/SdFile.h +++ b/Firmware/SdFile.h @@ -25,7 +25,7 @@ #ifdef SDSUPPORT #include "SdBaseFile.h" -#include +//#include #ifndef SdFile_h #define SdFile_h //------------------------------------------------------------------------------ @@ -33,7 +33,7 @@ * \class SdFile * \brief SdBaseFile with Print. */ -class SdFile : public SdBaseFile, public Print { +class SdFile : public SdBaseFile/*, public Print*/ { public: SdFile() {} SdFile(const char* name, uint8_t oflag);