From 218e3e0f373c8de92df6635366231feb453468d3 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 May 2013 00:03:21 -0300 Subject: [PATCH 01/13] Create EoL_HandlingAnd4LineSupport.py --- .../EoL_HandlingAnd4LineSupport.py | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py diff --git a/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py b/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py new file mode 100644 index 00000000..c8de0c49 --- /dev/null +++ b/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py @@ -0,0 +1,106 @@ +#---------------------------------------------------------------- +# Author: Chris Crumpacker +# Date: May 2013 +# +# Heavily modified version of the "message" function from Adafruit's +# CharLCD code as written for the RaspberryPi LCD Plate. This handles +# the end of row/line So that it is actually is cut off and does not +# overflow into the buffer on the 16x2 displays and worse onto +# line 3 on the 20x4 displays +# +# All orginal functionality is retained with the addition of handling the +# \n's Cariage returns for all 4 lines on the 20x4 +# +# When calling the message function you can add a "mode" variable to the end +# to describe how to handle strings over the length of the display. +# +# MODE: +# 0 or empty = Normal handling as it was from Adafruit +# 1 = Truncates the string right at the display's limit +# 2 = Truncates the string 3 short of the limit and adds an elipse +# +# Future plans will be to both handle proper cariage returns and to +# cut at the spaces as to not leave partial words. +# +# Orginal was written by Adafruit Industries. +# Under MIT license. +# +# "This is essentially a complete rewrite, but the calling syntax +# and constants are based on code from lrvick and LiquidCrystal. +# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py +# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp" +#---------------------------------------------------------------- + +from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate + +lcd = Adafruit_CharLCDPlate() + +class CrumpLCD_EoL_Handling(Adafruit_CharLCDPlate): + + def __init__(self, cols=20, rows=4): # Defaulted to 20x4 displays + self.numrows = rows + self.numcols = cols # Added a var for the column count to act as the line length limit (say that 10x fast) + + + def message(self, text, limitMode = 0): + """ Send string to LCD. Newline wraps to next line""" + lines = str(text).split('\n') # Split at newline(s) + for i, line in enumerate(lines): # For each substring... + if i == 1: # If newline(s), + lcd.write(0xC0) # set DDRAM address to 2nd line + elif i == 2: + lcd.write(0x94) + elif i >= 3: + lcd.write(0xD4) + """Now depending on the limit mode set by the function call this will handle """ + lineLength = len(line) + limit = self.numcols + if limitMode == 0: + lcd.write(line, True) + elif lineLength >= limit and limitMode == 1: + '''With the limit mode set to 1 the line is truncated + at the number of columns available on the display''' + limitedLine = line[0:self.numcols] + lcd.write(limitedLine, True) + elif lineLength >= limit and limitMode == 2: + '''With the limit mode set to 2 the line is truncated + at the number of columns minus 3 to add in an elipse''' + limitedLine = line[0:self.numcols-3]+'...' + lcd.write(limitedLine, True) + elif lineLength >= limit and limitMode == 3: + '''Future todo, add in proper line after line cariage return''' + print lines + else: + lcd.write(line, True) + +#!/usr/bin/python + +if __name__ == '__main__': + from time import sleep + + numcolumns = 20 + numrows = 4 + + eol = CrumpLCD_EoL_Handling(numcolumns, numrows) + + lcd.backlight(lcd.ON) + lcd.begin(numcolumns, numrows) + + eol.message("CrumpLCD\nEnd of Line Handling\nWith Forced\nCarriage Returns") + sleep(2) + + lcd.clear() + eol.message("Short String") + sleep(2) + + lcd.clear() + eol.message("Longer string then can't fit in one line",0) + sleep(2) + + lcd.clear() + eol.message("Longer string then can't fit in one line",1) + sleep(2) + + lcd.clear() + eol.message("Longer string then can't fit in one line",2) + sleep(2) From 2e397a9594b1ab426c86c7ea97b8f5b0a36c1b41 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 May 2013 00:05:15 -0300 Subject: [PATCH 02/13] Update EoL_HandlingAnd4LineSupport.py --- Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py b/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py index c8de0c49..2181db11 100644 --- a/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py +++ b/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py @@ -35,7 +35,7 @@ lcd = Adafruit_CharLCDPlate() -class CrumpLCD_EoL_Handling(Adafruit_CharLCDPlate): +class LCD_EoL_Handling(Adafruit_CharLCDPlate): def __init__(self, cols=20, rows=4): # Defaulted to 20x4 displays self.numrows = rows @@ -81,12 +81,12 @@ def message(self, text, limitMode = 0): numcolumns = 20 numrows = 4 - eol = CrumpLCD_EoL_Handling(numcolumns, numrows) + eol = LCD_EoL_Handling(numcolumns, numrows) lcd.backlight(lcd.ON) lcd.begin(numcolumns, numrows) - eol.message("CrumpLCD\nEnd of Line Handling\nWith Forced\nCarriage Returns") + eol.message("CharLCD\nEnd of Line Handling\nWith Forced\nCarriage Returns") sleep(2) lcd.clear() From 8ce5e150d04b815420643edd27809f328cdd309a Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 May 2013 00:19:36 -0300 Subject: [PATCH 03/13] Create LCD_examples_w4LineSupport.py --- .../LCD_examples_w4LineSupport.py | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py diff --git a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py new file mode 100644 index 00000000..607391fb --- /dev/null +++ b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py @@ -0,0 +1,144 @@ +#!/usr/bin/python + +#---------------------------------------------------------------- +# Author: Chris Crumpacker +# Date: May 2013 +# +# A demo of some of the built in helper functions of +# the Adafruit_CharLCDPlate.py and Using the EoL_HandlingAnd4LineSupport.py +# +# Using Adafruit_CharLCD code with the I2C and MCP230xx code as well +#---------------------------------------------------------------- + +from time import sleep +from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate +from EoL_HandlingAnd4LineSupport import LCD_EoL_Handling + +lcd = Adafruit_CharLCDPlate() +eol = LCD_EoL_Handling() + +numcolumns = 20 +numrows = 4 + +lcd.begin(numcolumns, numrows) + +lcd.backlight(lcd.ON) +eol.message("LCD 20x4\nDemonstration") +sleep(2) + +while True: + #Text on each line alone. + lcd.clear() + eol.message("Line 1") + sleep(1) + + lcd.clear() + lcd.setCursor(0,1) + eol.message("Line 2") + sleep(1) + + lcd.clear() + lcd.setCursor(0,2) + eol.message("Line 3") + sleep(1) + + lcd.clear() + lcd.setCursor(0,3) + eol.message("Line 4") + sleep(1) + + lcd.clear() + eol.message("Line 1") + sleep(1) + + # Using the "\n" new line marker + lcd.clear() + eol.message("Line 1\nLine 2") + sleep(1) + + lcd.clear() + eol.message("Line 1\nLine 2\nLine 3") + sleep(1) + + lcd.clear() + eol.message("Line 1\nLine 2\nLine 3\nLine 4") + sleep(1) + + # Auto line limiting by length as to not overflow the display + # This is line by line and does not to any caraige returns + lcd.clear() + eol.message("This String is 33 Characters long",1) + sleep(2) + + lcd.clear() + eol.message("This String has elpise",2) + sleep(2) + + #Scroll text to the right + messageToPrint = "Scrolling Right" + i=0 + while i<20: + lcd.clear() + suffix = " " * i + eol.message(suffix + messageToPrint,0) + sleep(.25) + i += 1 + + # Scroll test in from the Left + messageToPrint = "Scrolling Left" + i=20 + while i>=0: + lcd.clear() + suffix = " " * i + eol.message(suffix + messageToPrint,0) + sleep(.25) + i -= 1 + sleep(2) + + # Printing text backwards, NOT right justified + lcd.clear() + eol.message("Right to left:") + lcd.setCursor(10,1) + lcd.rightToLeft() + eol.message("Testing") + sleep(2) + + # Printing normally from the middle of the line + lcd.clear() + eol.message("Left to Right:") + lcd.setCursor(10,1) + lcd.message("Testing") + sleep(2) + + # Enabling the cursor and having it blink + lcd.clear() + lcd.cursor() + lcd.blink() + eol.message("Cursor is blinking") + lcd.setCursor(0,1) + sleep(3) + lcd.noCursor() + lcd.noBlink() + + # Turning the backlight off and showing a simple count down + lcd.clear() + eol.message("Backlight off in") + lcd.setCursor(0,3) + eol.message("Back on in 3sec") + lcd.setCursor(17,0) #Reseting the cursor here keeps us from having to clear the screen, this over writes the previous character + eol.message("3") + sleep(1) + + lcd.setCursor(17,0) + eol.message("2") + sleep(1) + + lcd.setCursor(17,0) + eol.message("1") + sleep(1) + + lcd.backlight(lcd.OFF) + lcd.clear() + sleep(3) + lcd.backlight(lcd.ON) + eol.message("Backlight on") From 39a222ab8c36d0d37e95dd006fc0771207aad877 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 May 2013 00:20:15 -0300 Subject: [PATCH 04/13] Rename EoL_HandlingAnd4LineSupport.py to LCD_EoL_HandlingAnd4LineSupport.py --- ...dlingAnd4LineSupport.py => LCD_EoL_HandlingAnd4LineSupport.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Adafruit_CharLCDPlate/{EoL_HandlingAnd4LineSupport.py => LCD_EoL_HandlingAnd4LineSupport.py} (100%) diff --git a/Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py b/Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py similarity index 100% rename from Adafruit_CharLCDPlate/EoL_HandlingAnd4LineSupport.py rename to Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py From 5dd7a1480e37dc7e59ee7c0f6c238a4c54926363 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 May 2013 00:34:25 -0300 Subject: [PATCH 05/13] Create LCD_ DataTable.py --- Adafruit_CharLCDPlate/LCD_ DataTable.py | 128 ++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Adafruit_CharLCDPlate/LCD_ DataTable.py diff --git a/Adafruit_CharLCDPlate/LCD_ DataTable.py b/Adafruit_CharLCDPlate/LCD_ DataTable.py new file mode 100644 index 00000000..0c162897 --- /dev/null +++ b/Adafruit_CharLCDPlate/LCD_ DataTable.py @@ -0,0 +1,128 @@ +#!/usr/bin/python +#---------------------------------------------------------------- +# Author: Chris Crumpacker +# Date: May 2013 +# +# Testing a data table on an 20x4 LCD, +# using a RaspberyPi and an MCP23017 I2C port expander +# +# Using Adafruit_CharLCD code with the I2C and MCP230xx code as well +#---------------------------------------------------------------- + +from time import sleep +from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate +from EoL_HandlingAnd4LineSupport import LCD_EoL_Handling + +class LCD_DataTable(Adafruit_CharLCDPlate): + # Limited to 4 characters, + # position is left or right, + # line is 1-4 + def labelHalf(self, text, position, line): + if position == "left": + lcd.setCursor(0,line) + eol.message(" :") + lcd.setCursor(0,line) + eol.message(text[0:4]+':') + elif position == "right": + lcd.setCursor(10,line) + eol.message(" :") + lcd.setCursor(10,line) + eol.message('|'+text[0:4]+':') + + # Limited to 4 characters, + # position is left or right, + # line is 1-4 + def valueHalf(self, text, position, line): + if position == "left": + lcd.setCursor(5,line) + eol.message(" ") + lcd.setCursor(5,line) + eol.message(text[0:4]) + elif position == "right": + lcd.setCursor(16,line) + eol.message(" ") + lcd.setCursor(16,line) + eol.message(text[0:4]) + + # Writes up to a 9 character lable and value to a full line + def wholeLine(self, label, value, line): + self.clearLine(line) + lcd.setCursor(0,line) + eol.message(label[0:10] + ': ') + lcd.setCursor(11,line) + eol.message(value[0:10]) + + #Clears an entire line + def clearLine(self, line): + lcd.setCursor(0,line) + eol.message(" " * columns) + + # Clears just a half data set, label and value + def clearDataSet(self, position,line): + if position == "left": + lcd.setCursor(0,line) + eol.message(" " * 10) + elif position == "right": + lcd.setCursor(10,line) + eol.message(" " * 10) + + # Clears just the value portion for a half data set + def clearHalfValue(self, position,line): + if position == "left": + lcd.setCursor(5,line) + eol.message(" ") + elif position == "right": + lcd.setCursor(16,line) + eol.message(" ") + +#---------------------------------------------------------------- +# Main program, just trowing bogus data "against the wall" +#---------------------------------------------------------------- +if __name__ == '__main__': + + #lcd size reference + columns = 20 + rows = 4 + + eol = LCD_EoL_Handling() + lcd = Adafruit_CharLCDPlate() + dt = LCD_DataTable() + + lcd.begin(columns, rows) + lcd.backlight(lcd.ON) + lcd.clear() + + lcd.message("20x4 Table Testing") + sleep(2) + + #Filling the table with bogus info + lcd.clear() + dt.labelHalf("Temp","left",0) + dt.labelHalf("Mode","right",0) + dt.labelHalf("Targ","left",1) + dt.labelHalf("Fan","right",1) + dt.valueHalf("Cool","right",0) + dt.valueHalf("75.5","left",0) + dt.valueHalf("Auto","right",1) + dt.valueHalf("74.0","left",1) + dt.wholeLine("Tempurature", "Too Hot",2) + + #Start testing updating and clearing parts + sleep(5) + dt.clearLine(0) + sleep(2) + dt.labelHalf("Temp","left",0) + dt.valueHalf("76.0","left",0) + sleep(2) + dt.valueHalf("74.75","left",0) + sleep(2) + dt.labelHalf("Mode","right",0) + dt.valueHalf("Both","right",0) + sleep(2) + dt.valueHalf("On","right",0) + sleep(2) + dt.clearDataSet("left",0) + sleep(2) + dt.labelHalf("Tempurature","left",0) + dt.valueHalf("85","left",0) + sleep(5) From 4728d9b2c7508ed8af56663a4eafa61c520d8bc7 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 11:09:55 -0300 Subject: [PATCH 06/13] Update LCD_examples_w4LineSupport.py Have to set the cursor back to 0,0 after a clear for some reason... will look into it more soon. --- .../LCD_examples_w4LineSupport.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py index 607391fb..b3026565 100644 --- a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py +++ b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py @@ -12,7 +12,7 @@ from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate -from EoL_HandlingAnd4LineSupport import LCD_EoL_Handling +from LCD_EoL_HandlingAnd4LineSupport import LCD_EoL_Handling lcd = Adafruit_CharLCDPlate() eol = LCD_EoL_Handling() @@ -29,6 +29,7 @@ while True: #Text on each line alone. lcd.clear() + lcd.setCursor(0,0) eol.message("Line 1") sleep(1) @@ -47,30 +48,36 @@ eol.message("Line 4") sleep(1) + # Using the "\n" new line marker lcd.clear() + lcd.setCursor(0,0) eol.message("Line 1") sleep(1) - # Using the "\n" new line marker lcd.clear() + lcd.setCursor(0,0) eol.message("Line 1\nLine 2") sleep(1) lcd.clear() + lcd.setCursor(0,0) eol.message("Line 1\nLine 2\nLine 3") sleep(1) lcd.clear() + lcd.setCursor(0,0) eol.message("Line 1\nLine 2\nLine 3\nLine 4") sleep(1) # Auto line limiting by length as to not overflow the display # This is line by line and does not to any caraige returns lcd.clear() + lcd.setCursor(0,0) eol.message("This String is 33 Characters long",1) sleep(2) lcd.clear() + lcd.setCursor(0,0) eol.message("This String has elpise",2) sleep(2) @@ -79,6 +86,7 @@ i=0 while i<20: lcd.clear() + lcd.setCursor(0,0) suffix = " " * i eol.message(suffix + messageToPrint,0) sleep(.25) @@ -89,6 +97,7 @@ i=20 while i>=0: lcd.clear() + lcd.setCursor(0,0) suffix = " " * i eol.message(suffix + messageToPrint,0) sleep(.25) @@ -97,6 +106,7 @@ # Printing text backwards, NOT right justified lcd.clear() + lcd.setCursor(0,0) eol.message("Right to left:") lcd.setCursor(10,1) lcd.rightToLeft() @@ -105,6 +115,7 @@ # Printing normally from the middle of the line lcd.clear() + lcd.setCursor(0,0) eol.message("Left to Right:") lcd.setCursor(10,1) lcd.message("Testing") @@ -112,6 +123,7 @@ # Enabling the cursor and having it blink lcd.clear() + lcd.setCursor(0,0) lcd.cursor() lcd.blink() eol.message("Cursor is blinking") @@ -122,6 +134,7 @@ # Turning the backlight off and showing a simple count down lcd.clear() + lcd.setCursor(0,0) eol.message("Backlight off in") lcd.setCursor(0,3) eol.message("Back on in 3sec") @@ -139,6 +152,7 @@ lcd.backlight(lcd.OFF) lcd.clear() + lcd.setCursor(0,0) sleep(3) lcd.backlight(lcd.ON) eol.message("Backlight on") From cef7af17a23878ce4623aecb341dc7b323bdacaa Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 11:11:10 -0300 Subject: [PATCH 07/13] Update LCD_ DataTable.py --- Adafruit_CharLCDPlate/LCD_ DataTable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_CharLCDPlate/LCD_ DataTable.py b/Adafruit_CharLCDPlate/LCD_ DataTable.py index 0c162897..f34f9d96 100644 --- a/Adafruit_CharLCDPlate/LCD_ DataTable.py +++ b/Adafruit_CharLCDPlate/LCD_ DataTable.py @@ -11,7 +11,7 @@ from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate -from EoL_HandlingAnd4LineSupport import LCD_EoL_Handling +from LCD_EoL_HandlingAnd4LineSupport import LCD_EoL_Handling class LCD_DataTable(Adafruit_CharLCDPlate): # Limited to 4 characters, From d43d072beddacce1e64d0ed20eb680c84705c593 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 11:14:56 -0300 Subject: [PATCH 08/13] Update LCD_examples_w4LineSupport.py --- Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py index b3026565..8df72c51 100644 --- a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py +++ b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py @@ -5,7 +5,7 @@ # Date: May 2013 # # A demo of some of the built in helper functions of -# the Adafruit_CharLCDPlate.py and Using the EoL_HandlingAnd4LineSupport.py +# the Adafruit_CharLCDPlate.py and Using the LCD_EoL_HandlingAnd4LineSupport.py # # Using Adafruit_CharLCD code with the I2C and MCP230xx code as well #---------------------------------------------------------------- From a6d2bda7eb6beac3d8e3d122f192af934eda4202 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 15:38:35 -0300 Subject: [PATCH 09/13] Update LCD_ DataTable.py Rewrote a bit and organized the examples to flow better --- Adafruit_CharLCDPlate/LCD_ DataTable.py | 127 +++++++++++++++++------- 1 file changed, 92 insertions(+), 35 deletions(-) diff --git a/Adafruit_CharLCDPlate/LCD_ DataTable.py b/Adafruit_CharLCDPlate/LCD_ DataTable.py index f34f9d96..3c2c2c7a 100644 --- a/Adafruit_CharLCDPlate/LCD_ DataTable.py +++ b/Adafruit_CharLCDPlate/LCD_ DataTable.py @@ -17,22 +17,19 @@ class LCD_DataTable(Adafruit_CharLCDPlate): # Limited to 4 characters, # position is left or right, # line is 1-4 - def labelHalf(self, text, position, line): + def updateHalfLabel(self, text, position, line): + self.clearHalfDataSet(position,line) if position == "left": - lcd.setCursor(0,line) - eol.message(" :") lcd.setCursor(0,line) eol.message(text[0:4]+':') elif position == "right": - lcd.setCursor(10,line) - eol.message(" :") lcd.setCursor(10,line) eol.message('|'+text[0:4]+':') # Limited to 4 characters, # position is left or right, # line is 1-4 - def valueHalf(self, text, position, line): + def updateHalfValue(self, text, position, line): if position == "left": lcd.setCursor(5,line) eol.message(" ") @@ -45,20 +42,28 @@ def valueHalf(self, text, position, line): eol.message(text[0:4]) # Writes up to a 9 character lable and value to a full line - def wholeLine(self, label, value, line): - self.clearLine(line) + def updateWholeLineLabel(self, label, line): + self.clearWholeLine(line) lcd.setCursor(0,line) - eol.message(label[0:10] + ': ') - lcd.setCursor(11,line) + eol.message(label[0:9] + ': ') + + # Writes up to a 9 character lable and value to a full line + def updateWholeLineValue(self, value, line): + lcd.setCursor(10,line) eol.message(value[0:10]) #Clears an entire line - def clearLine(self, line): + def clearWholeLine(self, line): lcd.setCursor(0,line) eol.message(" " * columns) - + + #Clears an entire line + def clearWholeLineValue(self, line): + lcd.setCursor(10,line) + eol.message(" " * 10) + # Clears just a half data set, label and value - def clearDataSet(self, position,line): + def clearHalfDataSet(self, position,line): if position == "left": lcd.setCursor(0,line) eol.message(" " * 10) @@ -97,32 +102,84 @@ def clearHalfValue(self, position,line): #Filling the table with bogus info lcd.clear() - dt.labelHalf("Temp","left",0) - dt.labelHalf("Mode","right",0) - dt.labelHalf("Targ","left",1) - dt.labelHalf("Fan","right",1) - dt.valueHalf("Cool","right",0) - dt.valueHalf("75.5","left",0) - dt.valueHalf("Auto","right",1) - dt.valueHalf("74.0","left",1) - dt.wholeLine("Tempurature", "Too Hot",2) - + dt.updateHalfLabel("Temp","left",0) + dt.updateHalfLabel("Mode","right",0) + dt.updateHalfLabel("Targ","left",1) + dt.updateHalfLabel("Fan","right",1) + dt.updateHalfValue("Cool","right",0) + dt.updateHalfValue("75.5","left",0) + dt.updateHalfValue("Auto","right",1) + dt.updateHalfValue("74.0","left",1) + dt.updateWholeLineLabel("Tempurature",2) + dt.updateWholeLineValue("Too Hot!!!",2) + dt.updateWholeLineLabel("Humidity",3) + dt.updateWholeLineValue("100%!!!",3) + #Start testing updating and clearing parts - sleep(5) - dt.clearLine(0) + + # Clearing entire lines sleep(2) - dt.labelHalf("Temp","left",0) - dt.valueHalf("76.0","left",0) + dt.clearWholeLine(0) + sleep(1) + dt.clearWholeLine(3) + sleep(1) + + # Repopulating the lines just cleared + dt.updateHalfLabel("Temp","left",0) + dt.updateHalfValue("75.3","left",0) + dt.updateHalfLabel("Mode","right",0) + dt.updateHalfValue("Cool","right",0) + dt.updateWholeLineLabel("Humidity",3) + dt.updateWholeLineValue("100%!!!",3) sleep(2) - dt.valueHalf("74.75","left",0) + + # Clearing the entire Data set, both Label and Value + dt.clearHalfDataSet("left",0) + sleep(1) + dt.clearHalfDataSet("right",0) + sleep(1) + dt.clearHalfDataSet("left",1) + sleep(1) + dt.clearHalfDataSet("right",1) + sleep(2) + + # Repopulating the half labels and values just removed + dt.updateHalfLabel("Temp","left",0) + dt.updateHalfLabel("Mode","right",0) + dt.updateHalfLabel("Targ","left",1) + dt.updateHalfLabel("Fan","right",1) + + dt.updateHalfValue("75.5","left",0) + dt.updateHalfValue("Cool","right",0) + dt.updateHalfValue("74.0","left",1) + dt.updateHalfValue("On","right",1) sleep(2) - dt.labelHalf("Mode","right",0) - dt.valueHalf("Both","right",0) + + # Clearing the values in the half data sets + dt.clearHalfValue("left",0) + sleep(1) + dt.clearHalfValue("right",0) + sleep(1) + dt.clearHalfValue("left",1) + sleep(1) + dt.clearHalfValue("right",1) sleep(2) - dt.valueHalf("On","right",0) + + # Repopulating half data set values + dt.updateHalfValue("74.7","left",0) + sleep(1) + dt.updateHalfValue("Auto","right",0) + sleep(1) + dt.updateHalfValue("74.0","left",1) + sleep(1) + dt.updateHalfValue("On","right",1) sleep(2) - dt.clearDataSet("left",0) + + # Clearing the value on a full line entry + dt.clearWholeLineValue(2) + dt.clearWholeLineValue(3) sleep(2) - dt.labelHalf("Tempurature","left",0) - dt.valueHalf("85","left",0) - sleep(5) + + # Repopulating the values that was just removed + dt.updateWholeLineValue("Still Hot",2) + dt.updateWholeLineValue("90%",3) From eb65c85ec8697814f9e2dcc2f7def74b2b2d0e78 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 23:37:49 -0300 Subject: [PATCH 10/13] Update Adafruit_CharLCDPlate.py --- .../Adafruit_CharLCDPlate.py | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py index 06b9300c..7c6a5c5e 100644 --- a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py +++ b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py @@ -260,6 +260,7 @@ def write(self, value, char_mode=False): def begin(self, cols, lines): self.currline = 0 self.numlines = lines + self.numcols = cols self.clear() @@ -404,13 +405,35 @@ def createChar(self, location, bitmap): self.write(self.LCD_SETDDRAMADDR) - def message(self, text): - """ Send string to LCD. Newline wraps to second line""" - lines = str(text).split('\n') # Split at newline(s) - for i, line in enumerate(lines): # For each substring... - if i > 0: # If newline(s), - self.write(0xC0) # set DDRAM address to 2nd line - self.write(line, True) # Issue substring + def message(self, text, limitMode = 0): + """ Send string to LCD. Newline wraps to next line""" + lines = str(text).split('\n') # Split at newline(s) + for i, line in enumerate(lines): # For each substring... + if i == 1: # If newline(s), + self.write(0xC0) # set DDRAM address to 2nd line + elif i == 2: + self.write(0x94) + elif i >= 3: + self.write(0xD4) + """Now depending on the limit mode set by the function call this will handle """ + lineLength = len(line) + limit = self.numcols + if limitMode <= 0: + self.write(line, True) + elif lineLength >= limit and limitMode == 1: + '''With the limit mode set to 1 the line is truncated + at the number of columns available on the display''' + limitedLine = line[0:self.numcols] + self.write(limitedLine, True) + elif lineLength >= limit and limitMode == 2: + '''With the limit mode set to 2 the line is truncated + at the number of columns minus 3 to add in an elipse''' + limitedLine = line[0:self.numcols-3]+'...' + self.write(limitedLine, True) + elif lineLength >= limit and limitMode >= 3: + '''Future todo, add in proper, "line after line" cariage return''' + else: + self.write(line, True) def backlight(self, color): From 32be894e147ba341f5348bf9c8a05e9abb5fe997 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 23:38:30 -0300 Subject: [PATCH 11/13] Update LCD_examples_w4LineSupport.py --- .../LCD_examples_w4LineSupport.py | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py index 8df72c51..792cd07e 100644 --- a/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py +++ b/Adafruit_CharLCDPlate/LCD_examples_w4LineSupport.py @@ -5,80 +5,78 @@ # Date: May 2013 # # A demo of some of the built in helper functions of -# the Adafruit_CharLCDPlate.py and Using the LCD_EoL_HandlingAnd4LineSupport.py +# the Adafruit_CharLCDPlate.py and Using the EoL_HandlingAnd4LineSupport.py # # Using Adafruit_CharLCD code with the I2C and MCP230xx code as well #---------------------------------------------------------------- +numcolumns = 20 +numrows = 4 + from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate -from LCD_EoL_HandlingAnd4LineSupport import LCD_EoL_Handling lcd = Adafruit_CharLCDPlate() -eol = LCD_EoL_Handling() - -numcolumns = 20 -numrows = 4 lcd.begin(numcolumns, numrows) lcd.backlight(lcd.ON) -eol.message("LCD 20x4\nDemonstration") +lcd.message("LCD 20x4\nDemonstration") sleep(2) while True: #Text on each line alone. lcd.clear() lcd.setCursor(0,0) - eol.message("Line 1") + lcd.message("Line 1") sleep(1) lcd.clear() lcd.setCursor(0,1) - eol.message("Line 2") + lcd.message("Line 2") sleep(1) lcd.clear() lcd.setCursor(0,2) - eol.message("Line 3") + lcd.message("Line 3") sleep(1) lcd.clear() lcd.setCursor(0,3) - eol.message("Line 4") + lcd.message("Line 4") sleep(1) # Using the "\n" new line marker lcd.clear() lcd.setCursor(0,0) - eol.message("Line 1") + lcd.message("Line 1") sleep(1) lcd.clear() lcd.setCursor(0,0) - eol.message("Line 1\nLine 2") + lcd.message("Line 1\nLine 2") sleep(1) lcd.clear() lcd.setCursor(0,0) - eol.message("Line 1\nLine 2\nLine 3") + lcd.message("Line 1\nLine 2\nLine 3") sleep(1) lcd.clear() lcd.setCursor(0,0) - eol.message("Line 1\nLine 2\nLine 3\nLine 4") + lcd.message("Line 1\nLine 2\nLine 3\nLine 4") sleep(1) # Auto line limiting by length as to not overflow the display # This is line by line and does not to any caraige returns lcd.clear() lcd.setCursor(0,0) - eol.message("This String is 33 Characters long",1) + lcd.message("This String is 33 Characters long",1) sleep(2) lcd.clear() lcd.setCursor(0,0) - eol.message("This String has elpise",2) + lcd.message("This String has elpise",2) sleep(2) #Scroll text to the right @@ -88,7 +86,7 @@ lcd.clear() lcd.setCursor(0,0) suffix = " " * i - eol.message(suffix + messageToPrint,0) + lcd.message(suffix + messageToPrint,1) sleep(.25) i += 1 @@ -99,7 +97,7 @@ lcd.clear() lcd.setCursor(0,0) suffix = " " * i - eol.message(suffix + messageToPrint,0) + lcd.message(suffix + messageToPrint,1) sleep(.25) i -= 1 sleep(2) @@ -107,16 +105,16 @@ # Printing text backwards, NOT right justified lcd.clear() lcd.setCursor(0,0) - eol.message("Right to left:") + lcd.message("Right to left:") lcd.setCursor(10,1) lcd.rightToLeft() - eol.message("Testing") + lcd.message("Testing") sleep(2) # Printing normally from the middle of the line lcd.clear() lcd.setCursor(0,0) - eol.message("Left to Right:") + lcd.message("Left to Right:") lcd.setCursor(10,1) lcd.message("Testing") sleep(2) @@ -126,7 +124,7 @@ lcd.setCursor(0,0) lcd.cursor() lcd.blink() - eol.message("Cursor is blinking") + lcd.message("Cursor is blinking") lcd.setCursor(0,1) sleep(3) lcd.noCursor() @@ -135,19 +133,19 @@ # Turning the backlight off and showing a simple count down lcd.clear() lcd.setCursor(0,0) - eol.message("Backlight off in") + lcd.message("Backlight off in") lcd.setCursor(0,3) - eol.message("Back on in 3sec") + lcd.message("Back on in 3sec") lcd.setCursor(17,0) #Reseting the cursor here keeps us from having to clear the screen, this over writes the previous character - eol.message("3") + lcd.message("3") sleep(1) lcd.setCursor(17,0) - eol.message("2") + lcd.message("2") sleep(1) lcd.setCursor(17,0) - eol.message("1") + lcd.message("1") sleep(1) lcd.backlight(lcd.OFF) @@ -155,4 +153,4 @@ lcd.setCursor(0,0) sleep(3) lcd.backlight(lcd.ON) - eol.message("Backlight on") + lcd.message("Backlight on") From 80186bbc752fdb49e18cbcd97109dce3553261f9 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 23:40:43 -0300 Subject: [PATCH 12/13] Update LCD_EoL_HandlingAnd4LineSupport.py --- Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py b/Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py index 2181db11..0ae8f18f 100644 --- a/Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py +++ b/Adafruit_CharLCDPlate/LCD_EoL_HandlingAnd4LineSupport.py @@ -1,3 +1,7 @@ +######################################################################## +#### OLD!!!!! This change had been rolled into the main plate sciprt ### +######################################################################## + #---------------------------------------------------------------- # Author: Chris Crumpacker # Date: May 2013 From 859d351d8265b96cac4abb6e229e254d45cf6e87 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 May 2013 23:41:05 -0300 Subject: [PATCH 13/13] Update LCD_ DataTable.py --- Adafruit_CharLCDPlate/LCD_ DataTable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_CharLCDPlate/LCD_ DataTable.py b/Adafruit_CharLCDPlate/LCD_ DataTable.py index 3c2c2c7a..0d52f745 100644 --- a/Adafruit_CharLCDPlate/LCD_ DataTable.py +++ b/Adafruit_CharLCDPlate/LCD_ DataTable.py @@ -10,7 +10,7 @@ #---------------------------------------------------------------- from time import sleep -from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate +from Adafruit_CharLCDPlate4line import Adafruit_CharLCDPlate from LCD_EoL_HandlingAnd4LineSupport import LCD_EoL_Handling class LCD_DataTable(Adafruit_CharLCDPlate):