diff --git a/Examples/PropWare_DuplexUART/DuplexUART_Demo.cpp b/Examples/PropWare_DuplexUART/DuplexUART_Demo.cpp index 49bc90c6..80d1b0b2 100644 --- a/Examples/PropWare_DuplexUART/DuplexUART_Demo.cpp +++ b/Examples/PropWare_DuplexUART/DuplexUART_Demo.cpp @@ -68,7 +68,7 @@ int main () { // Start our new cog and initialize the speaking UART const uint8_t cog = init_main_cog(&threadData, &speaker); - pwSyncOut.printf("New cog %u. Ready to send!!!" CRLF, cog); +// pwSyncOut.printf("New cog %u. Ready to send!!!" CRLF, cog); // TODO while (1) { waitcnt(500 * MILLISECOND + CNT); @@ -93,14 +93,14 @@ void listen_silently (void *arg) { // Initialize the listener UART and clear the buffer init_listener_cog(buffer, &listener); - pwSyncOut.puts("Ready to receive!" CRLF); +// pwSyncOut.puts("Ready to receive!" CRLF); // TODO while (1) { chars = 0; if ((err = listener.fgets(buffer, &chars))) error(err); - pwSyncOut.printf("Data (%d chars): \"%s\"" CRLF, chars, buffer); +// pwSyncOut.printf("Data (%d chars): \"%s\"" CRLF, chars, buffer); // TODO } } @@ -117,7 +117,7 @@ void init_listener_cog (char buffer[], PropWare::HalfDuplexUART *listener) { void error (const PropWare::ErrorCode err) { PropWare::SimplePort debugLEDs(PropWare::Port::P16, 8, PropWare::Pin::OUT); - pwSyncOut.printf("Unknown error: %u" CRLF, err); +// pwSyncOut.printf("Unknown error: %u" CRLF, err); // TODO while (1) { debugLEDs.write((uint32_t) err); diff --git a/Examples/PropWare_SynchronousPrinter/SynchronousPrinter_Demo.cpp b/Examples/PropWare_SynchronousPrinter/SynchronousPrinter_Demo.cpp index 60eb7859..0165dca8 100644 --- a/Examples/PropWare_SynchronousPrinter/SynchronousPrinter_Demo.cpp +++ b/Examples/PropWare_SynchronousPrinter/SynchronousPrinter_Demo.cpp @@ -21,6 +21,7 @@ volatile uint32_t wait_time = SECOND; volatile bool syncStart = false; volatile uint32_t startCnt; +// TODO: This should probably be fixed whenever SynchronousPrinter is complete int main (int argc, char *argv[]) { int8_t n; int8_t cog; @@ -35,7 +36,7 @@ int main (int argc, char *argv[]) { for (n = 1; n < COGS; n++) { cog = (int8_t) _start_cog_thread(cog_stack[n] + sizeof(cog_stack[n]), run_cog, nullptr, &thread_data); - pwSyncOut.printf("Toggle COG %d Started" CRLF, cog); +// pwSyncOut.printf("Toggle COG %d Started" CRLF, cog); } startCnt = CNT; @@ -46,7 +47,7 @@ int main (int argc, char *argv[]) { PropWare::Pin::flash_pin( (PropWare::Port::Mask) (1 << (cogid() + 16)), 3); - pwSyncOut.printf("Hello from cog %d" CRLF, cogid()); +// pwSyncOut.printf("Hello from cog %d" CRLF, cogid()); nextCnt = waitcnt2(nextCnt, wait_time); } return 0; @@ -64,7 +65,7 @@ void run_cog (void *arg) { PropWare::Pin::flash_pin( (PropWare::Port::Mask) (1 << (cogid() + 16)), 3); - pwSyncOut.printf("Hello from cog %d" CRLF, cogid()); +// pwSyncOut.printf("Hello from cog %d" CRLF, cogid()); nextCnt = waitcnt2(nextCnt, wait_time); } } diff --git a/PropWare/printer.h b/PropWare/printer.h index 61454575..ea660cf6 100644 --- a/PropWare/printer.h +++ b/PropWare/printer.h @@ -102,21 +102,20 @@ class Printer { * object such as a PropWare::UART */ Printer (const PrintCapable *printCapable) - : m_printCapable(printCapable), - m_lock(-1) { + : m_printCapable(printCapable) { } /** * @see PropWare::PrintCapable::put_char */ - void put_char (const char c, const bool bypassLock = false) const { + void put_char (const char c) const { this->m_printCapable->put_char(c); } /** * @see PropWare::PrintCapable::puts */ - void puts (const char string[], const bool bypassLock = false) const { + void puts (const char string[]) const { this->m_printCapable->puts(string); } @@ -131,12 +130,11 @@ class Printer { * value. */ void put_int (int32_t x, uint16_t width = 0, - const char fillChar = DEFAULT_FILL_CHAR, - const bool bypassLock = false) const { + const char fillChar = DEFAULT_FILL_CHAR) const { if (0 > x) this->m_printCapable->put_char('-'); - this->put_uint((uint32_t) abs(x), width, fillChar, true); + this->put_uint((uint32_t) abs(x), width, fillChar); } /** @@ -146,12 +144,9 @@ class Printer { * @param[in] width Minimum number of characters to print * @param[in] fillChar Character to print to the left of the number * if the number's width is less than `width` - * @param[in] bypassLock For internal use only. Leave as default - * value. */ void put_uint (uint32_t x, uint16_t width = 0, - const char fillChar = DEFAULT_FILL_CHAR, - const bool bypassLock = false) const { + const char fillChar = DEFAULT_FILL_CHAR) const { const uint8_t radix = 10; char buf[sizeof(x) * 8]; uint8_t i = 0; @@ -187,8 +182,7 @@ class Printer { * value. */ void put_hex (uint32_t x, uint16_t width = 0, - const char fillChar = DEFAULT_FILL_CHAR, - const bool bypassLock = false) const { + const char fillChar = DEFAULT_FILL_CHAR) const { char buf[sizeof(x)*2]; uint8_t temp, j, i = 0; @@ -226,12 +220,9 @@ class Printer { * the decimal point * @param[in] fillChar Character to print to the left of the number * if the number's width is less than `width` - * @param[in] bypassLock For internal use only. Leave as default - * value. */ void put_float (double f, uint16_t width = 0, uint16_t precision = 6, - const char fillChar = DEFAULT_FILL_CHAR, - const bool bypassLock = false) const { + const char fillChar = DEFAULT_FILL_CHAR) const { //////////////////////////////////////////////////////////////////// // Code taken straight from Parallax's floatToString! Thank you!!! //////////////////////////////////////////////////////////////////// @@ -372,7 +363,7 @@ class Printer { * @see PropWare::Printer::printf(const char *fmt, const T first, * Targs... remaining) */ - void printf(const char *fmt, const bool bypassLock = false) const { + void printf(const char *fmt) const { this->puts(fmt); } @@ -413,9 +404,6 @@ class Printer { char c; Format format; - if (0 <= this->m_lock) - while (lockset(this->m_lock)); - while (*s) { c = *s; @@ -450,18 +438,18 @@ class Printer { switch (c) { case 'i': case 'd': - this->print((int32_t) first, format, true); + this->print((int32_t) first, format); break; case 'X': format.radix = 16; // No "break;" after 'X' - let it flow into 'u' case 'u': - this->print((uint32_t) first, format, true); + this->print((uint32_t) first, format); break; case 'f': case 's': case 'c': - this->print(first, format, true); + this->print(first, format); break; default: this->m_printCapable->put_char( @@ -480,11 +468,6 @@ class Printer { ++s; } - - if (0 <= this->m_lock) { -// this->printCapable->puts("cleared" CRLF); - lockclr(this->m_lock); - } } /** @@ -493,8 +476,7 @@ class Printer { * @param[in] c Character to be printed * @param format Unused */ - void print (const char c, const Format format = DEFAULT_FORMAT, - const bool bypassLock = false) const { + void print (const char c, const Format format = DEFAULT_FORMAT) const { this->put_char(c); } @@ -504,8 +486,8 @@ class Printer { * @param[in] string[] String to be printed * @param format Unused */ - void print (const char string[], const Format format = DEFAULT_FORMAT, - const bool bypassLock = false) const { + void print (const char string[], + const Format format = DEFAULT_FORMAT) const { this->puts(string); } @@ -515,16 +497,14 @@ class Printer { * @param[in] x Unsigned value to be printed * @param format */ - void print (const uint32_t x, const Format format = DEFAULT_FORMAT, - const bool bypassLock = false) const { + void print (const uint32_t x, + const Format format = DEFAULT_FORMAT) const { switch (format.radix) { case 16: - this->put_hex(x, format.width, format.fillChar, - bypassLock); + this->put_hex(x, format.width, format.fillChar); break; default: - this->put_uint(x, format.width, format.fillChar, - bypassLock); + this->put_uint(x, format.width, format.fillChar); } } @@ -534,9 +514,9 @@ class Printer { * @param[in] x Unsigned value to be printed * @param format */ - void print (const int32_t x, const Format format = DEFAULT_FORMAT, - const bool bypassLock = false) const { - this->put_int(x, format.width, format.fillChar, bypassLock); + void print (const int32_t x, + const Format format = DEFAULT_FORMAT) const { + this->put_int(x, format.width, format.fillChar); } /** @@ -545,15 +525,13 @@ class Printer { * @param[in] x Unsigned value to be printed * @param format */ - void print (const double f, const Format format = DEFAULT_FORMAT, - const bool bypassLock = false) const { - this->put_float(f, format.width, format.precision, format.fillChar, - bypassLock); + void print (const double f, + const Format format = DEFAULT_FORMAT) const { + this->put_float(f, format.width, format.precision, format.fillChar); } protected: const PrintCapable *m_printCapable; - int32_t m_lock; // Only used in PropWare::SynchronousPrinter }; } diff --git a/PropWare/synchronousprinter.h b/PropWare/synchronousprinter.h index 4dcff47f..fd02a308 100644 --- a/PropWare/synchronousprinter.h +++ b/PropWare/synchronousprinter.h @@ -33,7 +33,7 @@ namespace PropWare { * @brief IMPORTANT! SynchronousPrinter is not yet working! DO NOT attempt to * use SynchronousPrinter until this note disappears */ -class SynchronousPrinter: public Printer { +class SynchronousPrinter { public: /** * @brief Creates a synchronous instance of a Printer that can be used @@ -44,7 +44,7 @@ class SynchronousPrinter: public Printer { * shared across multiple cogs */ SynchronousPrinter (PrintCapable const *printCapable) - : Printer(printCapable) { + : m_printCapable(printCapable) { this->m_lock = locknew(); lockclr(this->m_lock); } @@ -90,83 +90,9 @@ class SynchronousPrinter: public Printer { return this->hasLock(); } - /** - * @see PropWare::Printer::put_char - */ - void put_char (const char c) const { - while (lockset(this->m_lock)); - Printer::put_char(c); - lockclr(this->m_lock); - } - - /** - * @see PropWare::Printer::puts - */ - void puts (const char string[]) const { - while (lockset(this->m_lock)); - this->m_printCapable->puts(string); - lockclr(this->m_lock); - } - - /** - * @see PropWare::Printer::put_int - */ - void put_int (int32_t x, uint16_t width = 0, const char fillChar = ' ', - const bool bypassLock = false) const { - if (bypassLock) - Printer::put_int(x, width, fillChar, true); - else { - while (lockset(this->m_lock)); - Printer::put_int(x, width, fillChar, true); - lockclr(this->m_lock); - } - } - - /** - * @see PropWare::Printer::put_uint - */ - void put_uint (uint32_t x, uint16_t width = 0, - const char fillChar = ' ', - const bool bypassLock = false) const { - if (bypassLock) - Printer::put_uint(x, width, fillChar, true); - else { - while (lockset(this->m_lock)); - Printer::put_uint(x, width, fillChar, true); - lockclr(this->m_lock); - } - } - - /** - * @see PropWare::Printer::put_hex - */ - void put_hex (uint32_t x, uint16_t width = 0, const char fillChar = ' ', - const bool bypassLock = false) const { - if (bypassLock) - Printer::put_hex(x, width, fillChar, true); - else { - while (lockset(this->m_lock)); - Printer::put_hex(x, width, fillChar, true); - lockclr(this->m_lock); - } - } - -#ifdef ENABLE_PROPWARE_PRINT_FLOAT - /** - * @see PropWare::Printer::put_float - */ - void put_float (double f, uint16_t width, uint16_t precision, - const char fillChar, - const bool bypassLock = false) const { - if (bypassLock) - Printer::put_float(f, width, precision, fillChar, true); - else { - while (lockset(this->m_lock)); - Printer::put_float(f, width, precision, fillChar, true); - lockclr(this->m_lock); - } - } -#endif + protected: + const PrintCapable *m_printCapable; + int m_lock; }; }