1
- """ Base class for all RGB Display devices """
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2017 Radomir Dopieralski and Adafruit Industries
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+ """
23
+ `adafruit_RGB_Display.rgb`
24
+ ====================================================
25
+
26
+ Base class for all RGB Display devices
27
+
28
+ * Author(s): Radomir Dopieralski, Michael McWethy
29
+ """
30
+
2
31
import time
3
32
from micropython import const
4
33
try :
17
46
18
47
19
48
def color565 (r , g , b ):
20
- """Format color code for device"""
49
+ """Convert red, green and blue values (0-255) into a 16-bit 565 encoding. As
50
+ a convenience this is also available in the parent adafruit_rgb_display
51
+ package namespace."""
21
52
return (r & 0xf8 ) << 8 | (g & 0xfc ) << 3 | b >> 3
22
53
23
54
24
55
class DummyPin :
25
- """A fake gpio pin for when you want to skip pins ."""
56
+ """Can be used in place of a ``Pin()`` when you don't want to skip it ."""
26
57
def init (self , * args , ** kwargs ):
27
58
"""Dummy Pin init"""
28
59
pass
@@ -37,7 +68,10 @@ def high(self):
37
68
38
69
39
70
class Display : #pylint: disable-msg=no-member
40
- """Base class for all RGB display devices"""
71
+ """Base class for all RGB display devices
72
+ :param width: number of pixels wide
73
+ :param height: number of pixels high
74
+ """
41
75
_PAGE_SET = None
42
76
_COLUMN_SET = None
43
77
_RAM_WRITE = None
@@ -83,7 +117,7 @@ def _decode_pixel(self, data):
83
117
return color565 (* struct .unpack (self ._DECODE_PIXEL , data ))
84
118
85
119
def pixel (self , x , y , color = None ):
86
- """Read or write a pixel."""
120
+ """Read or write a pixel at a given position ."""
87
121
if color is None :
88
122
return self ._decode_pixel (self ._block (x , y , x , y ))
89
123
@@ -93,7 +127,8 @@ def pixel(self, x, y, color=None):
93
127
94
128
#pylint: disable-msg=too-many-arguments
95
129
def fill_rectangle (self , x , y , width , height , color ):
96
- """Draw a filled rectangle."""
130
+ """Draw a rectangle at specified position with specified width and
131
+ height, and fill it with the specified color."""
97
132
x = min (self .width - 1 , max (0 , x ))
98
133
y = min (self .height - 1 , max (0 , y ))
99
134
width = min (self .width - x , max (1 , width ))
@@ -109,7 +144,7 @@ def fill_rectangle(self, x, y, width, height, color):
109
144
#pylint: enable-msg=too-many-arguments
110
145
111
146
def fill (self , color = 0 ):
112
- """Fill whole screen ."""
147
+ """Fill the whole display with the specified color ."""
113
148
self .fill_rectangle (0 , 0 , self .width , self .height , color )
114
149
115
150
def hline (self , x , y , width , color ):
0 commit comments