1
2
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
20 '''
21 Class that represents a OLED display.
22 '''
31
33 '''
34 Shows the given text with automatic line scrolling.
35 '''
36 self._checkRobot()
37 self.robot.sendCommand(self.device + ".println.'" + text + "'")
38
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
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
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
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
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
121