Commits

Anonymous committed 4b836fc

fix lcd constructor and variables missing

Comments (0)

Files changed (1)

src/platform/stm32f4/lcd.py

 #-----------------------------------------------------------------------------
-# Name:        lcd.py
-# Purpose:     LiquidCrystal library
-#   
-#   thx :     arduino LiquidCrystal.cpp
+#Name:        lcd.py
+#Purpose:     LiquidCrystal library (this is a python version of the 
+#             LiquidCrystal.cpp file of arduino project)
+#             
+#             If you're looking for detail :
 #
-# Author:      Stéphane Bard
+#             http://code.google.com/p/arduino/source/browse/trunk/libraries/LiquidCrystal/LiquidCrystal.cpp
+#  
+#  thx :     arduino LiquidCrystal.cpp
 #
-# Created:     2012/10/25
-# RCS-ID:      $Id: lcd.py $
-# Licence:     BSD
+#Author:      Stéphane Bard
+#
+#Created:     2012/10/25
+#RCS-ID:      $Id: lcd.py $
+#Licence:     BSD
 #-----------------------------------------------------------------------------
 
 import gpio
 import sys
 
+LCD_CURSOROFF=0x00
+LCD_BLINKON=0x01
+LCD_BLINKOFF=0x00
+LCD_DISPLAYMOVE=0x08
+LCD_CURSORMOVE=0x00
+LCD_MOVERIGHT=0x04
+LCD_MOVELEFT=0x00
 LCD_8BITMODE=0x10
 LCD_4BITMODE=0x00
 LCD_2LINE=0x08
 
 class LiquidCrystal(object):
     """
-    a liquidCrystal for STM32F4. This class is greatly inspired of
+    A liquidCrystal for STM32F4. This class is greatly inspired of
     the famous library arduino / LiquidCrystal.cpp
+
+        When the display powers up, it is configured as follows:
+
+        1. Display clear
+        2. Function set:
+           DL = 1; 8-bit interface data
+           N = 0; 1-line display
+           F = 0; 5x8 dot character font
+        3. Display on/off control:
+           D = 0; Display off
+           C = 0; Cursor off
+           B = 0; Blinking off
+        4. Entry mode set:
+           I/D = 1; Increment by 1
+           S = 0; No shift
+
+        Note, however, that resetting the Arduino doesn't reset the LCD, so we
+        can't assume that its in that state when a sketch starts (and the
+        LiquidCrystal constructor is called).
+
     """
 
-    def __init__(self, four_bit_mode, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7):
+    def __init__(self, rs, rw, enable, d0, d1, d2, d3, d4=0, d5=0, d6=0, d7=0):
         """
         each pin should be string like 'E7'
+
+        possible usage :
+
+                LiquidCrystal(rs, None, enable, d0, d1, d2, d3)
+                LiquidCrystal(rs, rw, enable, d0, d1, d2)
+                LiquidCrystal(rs, None, enable, d0, d1, d2, d3, d4, d5, d6, d7)
+                LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) 
+
+                TODO : rewrite example for STM32F4
+
         """
+        # value authorized for rw are string 'E7' or None !
+        if rw is None :
+            rw = 255
+
+        # four_bit_mode is fixed by non present keywords ...
+        four_bit_mode = 0
+        if not d4 or not d5 or not d6 or not d7 :
+            four_bit_mode = 1
+
         self.rs_pin = rs
         self.rw_pin = rw
         self.enable_pin = enable