| 23 | |
| 24 | # Convenience class to deal with converting images to a C array |
| 25 | class STLcdGraphic: |
| 26 | # Some constants for the LCD Driver |
| 27 | page_width = 8 |
| 28 | page_max_length = 132 |
| 29 | |
| 30 | array('B') |
| 31 | |
| 32 | def __init__( self, height, width ): |
| 33 | self.height = height |
| 34 | self.width = width |
| 35 | |
| 36 | # Calculate number of pages |
| 37 | self.page_count = int( self.height / self.page_width ) |
| 38 | self.page_length = self.width |
| 39 | |
| 40 | # Initialize pages to 0's |
| 41 | self.page_data = [] |
| 42 | for page in range( 0, self.page_count ): |
| 43 | self.page_data.append( array( 'B', [0] * self.page_length ) ) |
| 44 | |
| 45 | def setpixel( self, x, y ): |
| 46 | # Calculate which page |
| 47 | page = int( ( self.height - y ) / self.page_width ) |
| 48 | |
| 49 | if page == 4: |
| 50 | print("YAR", (x,y)) |
| 51 | |
| 52 | # Calculate which byte |
| 53 | byte = x |
| 54 | |
| 55 | # Calculate which bit |
| 56 | bit = int( ( self.height - y ) % self.page_width ) |
| 57 | |
| 58 | # Set pixel bit |
| 59 | self.page_data[ page ][ byte ] |= (1 << bit) |
| 60 | |
| 61 | def getpage( self, page ): |
| 62 | return self.page_data[ page ] |
| 63 | |
| 64 | def getarray( self , string=False): |
| 65 | if string is not False: |
| 66 | struct = "{\n" |
| 67 | |
| 68 | for page in range( 0, self.page_count ): |
| 69 | for elem in self.page_data[ page ]: |
| 70 | struct += "0x{0:02x}, ".format( elem ) |
| 71 | |
| 72 | if page != self.page_count - 1: |
| 73 | struct += "\n" |
| 74 | |
| 75 | struct += "\n}" |
| 76 | return struct |
| 77 | return self.page_data |
| 78 | |
| 79 | # Prints out what the image will look like on the display |
| 80 | def preview( self ): |
| 81 | # Top border first |
| 82 | display = "+" |
no outgoing calls
no test coverage detected
searching dependent graphs…