Anonymous avatar Anonymous committed b20aaf0 Draft

bugfix python port

Comments (0)

Files changed (1)

src/platform/stm32f4/lcd.py

 #-----------------------------------------------------------------------------
 # Name:        lcd.py
 # Purpose:     LiquidCrystal library (this is a python version of the 
-#             LiquidCrystal.cpp file of arduino project)
+#              LiquidCrystal.cpp file of arduino project)
 #             
 #             If you're looking for detail :
-#
 #             http://code.google.com/p/arduino/source/browse/trunk/libraries/LiquidCrystal/LiquidCrystal.cpp
 #  
 #  thx :     arduino LiquidCrystal.cpp
 LCD_5x10DOTS=0x04
 LCD_5x8DOTS=0x00
 
+# TODO: rewrite example for STM32F4
+# TODO: rewrite easy function to make a digital_write with simple parameter
+
 class LiquidCrystal(object):
     """
     A liquidCrystal for STM32F4. This class is greatly inspired of
         """
         each pin should be string like 'E7'
 
+        rw argument is kept in the same position.
+
         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) 
+                
+                d0, d1, d2, d3 ... should be STM32F4 string composed
+                by letter and a digit like "E7" etc ...
 
-                TODO : rewrite example for STM32F4
 
         """
         # value authorized for rw are string 'E7' or None !
         self.data_pins = [d0, d1, d2, d3, d4, d5, d6, d7]
 
         self.set_output(self.rs_pin)
-        self.set_output(self.rw_pin)
+
+        # we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
+        if self.rw_pin!= 255 :
+            self.set_output(self.rw_pin)
+
         self.set_output(self.enable_pin)
 
         if fourbitmode :
             self._displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS
         else :
             self._displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS
+
         self.begin(16, 1)
 
     def begin(self, cols, lines, dotsize):
         gpio.digital_write(self.rs_pin[0], int(self.rs_pin[1]), gpio.LOW)
         gpio.digital_write(self.enable_pin[0], int(self.enable_pin[1]), gpio.LOW)
 
-        if _rw_pin != 255 : 
+        if self.rw_pin != 255 : 
               gpio.digital_write(self.rw_pin[0], int(self.rw_pin[1]), gpio.LOW)
 
         # //put the LCD into 4 bit or 8 bit mode
-        if not (self._displayfunction and LCD_8BITMODE) :
+        if not (self._displayfunction & LCD_8BITMODE) :
            # this is according to the hitachi HD44780 datasheet
            # figure 24, pg 46
            # we start in 8bit mode, try to set 4 bit mode
         # Initialize to default text direction (for romance languages)
         self._displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
         # set the entry mode
-        self.command(LCD_ENTRYMODESET | _displaymode)
+        self.command(LCD_ENTRYMODESET | self._displaymode)
     
     def set_output(self, pin):
         """
         Turn the display on/off (quickly)
         """
         self._displaycontrol &= ~LCD_DISPLAYON
-        self.command(LCD_DISPLAYCONTROL | _displaycontrol)
+        self.command(LCD_DISPLAYCONTROL | self._displaycontrol)
 
     def display(self):
         """
         """
         self._displaycontrol |= LCD_DISPLAYON
-        self.command(LCD_DISPLAYCONTROL | _displaycontrol)
+        self.command(LCD_DISPLAYCONTROL | self._displaycontrol)
 
     def noCursor(self):
         """
         Turns the underline cursor on/off
         """
         self._displaycontrol &= ~LCD_CURSORON
-        self.command(LCD_DISPLAYCONTROL | _displaycontrol)
+        self.command(LCD_DISPLAYCONTROL | self._displaycontrol)
 
     def cursor(self):
         """
         """
         self._displaycontrol |= LCD_CURSORON
-        self.command(LCD_DISPLAYCONTROL | _displaycontrol)
+        self.command(LCD_DISPLAYCONTROL | self._displaycontrol)
 
     def noBlink(self):
         """
 
     def noAutoscroll(self):
         """
-            This will 'left justify' text from the cursor
+        This will 'left justify' text from the cursor
         """
         self._displaymode &= ~LCD_ENTRYSHIFTINCREMENT
         self.command(LCD_ENTRYMODESET | self._displaymode)
 
     def createChar(self, location, charmap):
         """
-          Allows us to fill the first 8 CGRAM locations
-          with custom characters
+        Allows us to fill the first 8 CGRAM locations
+        with custom characters
         """
         # we only have 8 locations 0-7
         location &= 0x7 
         if (self.rw_pin != 255) :
            gpio.digital_write(self.rw_pin[0], int(self.rw_pin[1]), gpio.LOW)
       
-        if (self._displayfunction and LCD_8BITMODE):
+        if (self._displayfunction & LCD_8BITMODE):
            self.write8bits(value)
         else :
            self.write4bits(value>>4)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.