From bb28428a445d4e840f19e945f47f6153defeca1e Mon Sep 17 00:00:00 2001 From: "rjbatista@gmail.com" Date: Thu, 15 Dec 2011 23:02:04 +0000 Subject: [PATCH] ISSUE #10: Support for starting position on setDisplayToString() methods --- CHANGES.txt | 3 +++ TM1638.cpp | 18 +++++++++++------- TM1638.h | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d3ed19a..7094d82 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +- ISSUE #10: Support for starting position on setDisplayToString() methods. + WARNING: setDisplayToString methods have changed prototype and are incompatible with code compiled for 1.5.x (if you specified a custom font) + Version 1.5.2 - ISSUE #9: Backwards compatibility with previous Arduino IDE. diff --git a/TM1638.cpp b/TM1638.cpp index b4d76b3..df93151 100644 --- a/TM1638.cpp +++ b/TM1638.cpp @@ -124,22 +124,26 @@ void TM1638::clearDisplay() } } -void TM1638::setDisplayToString(const char* string, const byte dots, const byte font[]) +void TM1638::setDisplayToString(const char* string, const byte dots, const byte pos, const byte font[]) { - for (int i = 0; i < 8; i++) { - sendChar(i, font[string[i] - 32], dots & (1 << (7 - i))); + for (int i = 0; i < 8 - pos; i++) { + if (string[i] != '\0') { + sendChar(i + pos, font[string[i] - 32], dots & (1 << (7 - i))); + } else { + break; + } } } -void TM1638::setDisplayToString(const String string, const byte dots, const byte font[]) +void TM1638::setDisplayToString(const String string, const byte dots, const byte pos, const byte font[]) { int stringLength = string.length(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8 - pos; i++) { if (i < stringLength) { - sendChar(i, font[string.charAt(i) - 32], dots & (1 << (7 - i))); + sendChar(i + pos, font[string.charAt(i) - 32], dots & (1 << (7 - i))); } else { - sendChar(i, 0, dots & (1 << (7 - i))); + break; } } } diff --git a/TM1638.h b/TM1638.h index a3e5c5f..ed069a1 100644 --- a/TM1638.h +++ b/TM1638.h @@ -60,9 +60,11 @@ class TM1638 /** Clear the display */ void clearDisplay(); /** Set the display to the string (defaults to built in font) */ - void setDisplayToString(const char* string, const byte dots = 0, const byte font[] = FONT_DEFAULT); + void setDisplayToString(const char* string, const byte dots = 0, const byte pos = 0, + const byte font[] = FONT_DEFAULT); /** Set the display to the String (defaults to built in font) */ - void setDisplayToString(String string, const byte dots = 0, const byte font[] = FONT_DEFAULT); + void setDisplayToString(String string, const byte dots = 0, const byte pos = 0, + const byte font[] = FONT_DEFAULT); /** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */ virtual void setLED(byte color, byte pos);