Module OLED1306
[hide private]
[frames] | no frames]

Source Code for Module OLED1306

  1  # OLED1306.py 
  2  # Remote mode 
  3   
  4  ''' 
  5   This software is part of the raspibrick module. 
  6   It is Open Source Free Software, so you may 
  7   - run the code for any purpose 
  8   - study how the code works and adapt it to your needs 
  9   - integrate all or parts of the code in your own programs 
 10   - redistribute copies of the code777 
 11   - improve the code and release your improvements to the public 
 12   However the use of the code is entirely your responsibility. 
 13   ''' 
 14   
 15  from RobotInstance import RobotInstance 
 16  from Tools import Tools 
 17  import time 
 18   
19 -class OLED1306():
20 ''' 21 Class that represents a OLED display. 22 '''
23 - def __init__(self):
24 ''' 25 Creates a OLED instance for the SSD1306 based chip. 26 ''' 27 self._checkRobot() 28 self.device = "oled" 29 self.robot = RobotInstance.getRobot() 30 self.robot.sendCommand(self.device + ".create")
31
32 - def println(self, text):
33 ''' 34 Shows the given text with automatic line scrolling. 35 ''' 36 self._checkRobot() 37 self.robot.sendCommand(self.device + ".println.'" + text + "'")
38
39 - def setFontSize(self, fontSize):
40 ''' 41 Sets a new font size of current font. 42 @fontSize: the new font size 43 ''' 44 self._checkRobot() 45 self.robot.sendCommand(self.device + ".setFontSize." + str(fontSize))
46 47
48 - def clear(self):
49 ''' 50 Erases the display and clears the text buffer. 51 ''' 52 self._checkRobot() 53 self.robot.sendCommand(self.device + ".clear")
54
55 - def setText(self, text, lineNum = 0, fontSize = None, indent = 0):
56 ''' 57 Displays text at given line left adjusted. 58 The old text of this line is erased, other text is not modified 59 The line distance is defined by the font size (text height + 1). 60 If no text is attributed to a line, the line is considered to consist of a single space 61 character with the font size of the preceeding line. 62 The position of the text cursor is not modified. 63 Text separated by \n is considered as a multiline text. In this case lineNum is the line number of the 64 first line. 65 @param text: the text to display. If emtpy, text with a single space character is assumed. 66 @param lineNum: the line number where to display the text (default: 0) 67 @param fontSize: the size of the font (default: None, set to current font size) 68 @indent: the line indent in pixels (default: 0) 69 ''' 70 self._checkRobot() 71 self.robot.sendCommand(self.device + ".setText.'" + text + "'." + 72 str(lineNum) + "." + str(fontSize) + "." + str(indent))
73 74
75 - def startBlinker(self, count = 3, offTime = 1000, onTime = 1000, blocking = False):
76 ''' 77 Blicks the entire screen for given number of times (off-on periods). 78 @param count: the number of blinking (default: 3) 79 @param offTime: the time the display is erased (in ms, default: 1000) 80 @param onTime: the time the display is shown (in ms, default: 1000) 81 @param blocking: if True, the function blocks until the blinking is finished; otherwise 82 it returns immediately 83 ''' 84 self._checkRobot() 85 blockingStr = '1' if blocking else "0" 86 self.robot.sendCommand(self.device + ".startBlinker." + 87 str(count) + "." + str(offTime) + "." + str(onTime) + 88 "." + blockingStr)
89
90 - def stopBlinker(self):
91 ''' 92 Stops a running blinker. 93 The method blocks until the blinker thread is finished and isBlinkerAlive() returns False. 94 ''' 95 self._checkRobot() 96 self.robot.sendCommand(self.device + ".stopBlinker")
97
98 - def isBlinking(self):
99 ''' 100 @return: True, if the blinker is displaying; otherwise False 101 ''' 102 time.sleep(0.001) 103 rc = self.robot.sendCommand(self.device + ".isBlinking") 104 v = True if rc == "True" else False 105 return v
106
107 - def setInverse(self, inverse):
108 ''' 109 @param inverse: if True, the background is white and the text is black; 110 otherwise the background is black and the text is white (default) 111 ''' 112 self._checkRobot() 113 inverseStr = "1" if inverse else "0" 114 self.robot.sendCommand(self.device + ".setInverse." + inverseStr)
115 116 117
118 - def _checkRobot(self):
119 if RobotInstance.getRobot() == None: 120 raise Exception("Create Robot instance first")
121