summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog8
-rw-r--r--Lcd.cpp34
-rw-r--r--Lcd.h34
3 files changed, 73 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index c2535d2..ce673e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,15 @@
+2009-03-27 Josh Kropf <josh@slashdev.ca>
+
+ * Lcd.h, Lcd.cpp
+ (print): added method overrides for printing numbers
+
+
2008-09-17 Josh Kropf <josh@slashdev.ca>
* Lcd.h: use protected member to store 4bit flag instead of line function
* Lcd.cpp: use flag to check if 4bit mode is enabled
(check_bf): fixed bug resulting in wrong pin selected for BF check
- (check_bf); do second enable pin pulse in 4bit mode
+ (check_bf): do second enable pin pulse in 4bit mode
2008-09-14 Josh Kropf <josh@slashdev.ca>
diff --git a/Lcd.cpp b/Lcd.cpp
index 1ea20b8..e15e0f5 100644
--- a/Lcd.cpp
+++ b/Lcd.cpp
@@ -269,6 +269,40 @@ Lcd::print(char* s)
}
void
+Lcd::print(unsigned long n, uint8_t base)
+{
+ char buf[8 * sizeof(long)];
+ int 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
+Lcd::print(long n, uint8_t base)
+{
+ if (n < 0) {
+ print('-');
+ n = -n;
+ }
+
+ print((unsigned long)n);
+}
+
+void
Lcd::define_char(uint8_t index, uint8_t data[])
{
int h = _function & FUNCTION_5x11? 11 : 8;
diff --git a/Lcd.h b/Lcd.h
index d0a3892..a9e6fac 100644
--- a/Lcd.h
+++ b/Lcd.h
@@ -90,7 +90,7 @@
* Default pin arrangement is (4pin mode uses D4~D7):
* D0=4, D1=5... , D7=11
*
- * Version: 0.3
+ * Version: 0.4
*/
class Lcd {
protected:
@@ -196,7 +196,37 @@ public:
* current cursor position.
*/
void print(char* str);
-
+
+ /**
+ * Print a number to the LCD screen at the current cursor position.
+ * \param n unsigned long integer
+ * \param base number system, default is decimal (base ten)
+ */
+ void print(unsigned long n, uint8_t base = 10);
+
+ /**
+ * Print a number to the LCD screen at the current cursor position.
+ * \param n signed long integer
+ * \param base number system, default is decimal (base ten)
+ */
+ void print(long n, uint8_t base = 10);
+
+ /**
+ * Print a number to the LCD screen at the current cursor position.
+ * \param n unsigned integer
+ * \param base number system, default is decimal (base ten)
+ */
+ void print(unsigned int n, uint8_t base = 10)
+ { print((unsigned long)n, base); }
+
+ /**
+ * Print a number to the LCD screen at the current cursor position.
+ * \param n signed integer
+ * \param base number system, default is decimal (base ten)
+ */
+ void print(int n, uint8_t base = 10)
+ { print((long)n, base); }
+
/**
* Define character in CGRAM. This defines a custom character. When the
* LCD is setup to use 5x8 font the user can specify up to eight characters.