Display
Display
Game Display is a class that abstracts different S^3 panels into one display
Source code in display/display.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
__init__(board_objects, x_width, y_height)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
board_objects
|
int[][]
|
2d array of seven segment objects oriented how the sign is put together, i.e. [[panel0, panel1],[panel2,panel3]] |
required |
x_width
|
int
|
number of digits in the display on the x axis |
required |
y_height
|
int
|
number of pixels on the y axis (each vertical digit is split into two pixels) |
required |
Source code in display/display.py
clear()
Clear all the panels on the display
Source code in display/display.py
draw_hline(start_x, start_y, length, top=True, combine=True, push=False)
Draw horizontal line
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_x
|
int
|
x coordinate |
required |
start_y
|
int
|
y coordinate |
required |
length
|
int
|
length of line to draw |
required |
top
|
int
|
draw horizontal line on the top or bottom of the pixel |
True
|
combine
|
int
|
digits are split into two pixels, when drawing to one combine keeps what is already drawn on the other side of the digit |
True
|
push
|
int
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
draw_pixel(x, y, value, combine=True, push=False)
Draw shape to one pixel location
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate |
required |
y
|
int
|
y coordinate |
required |
value
|
int
|
which leds to turn on for the pixel (1 for bottom, 2 for left, 4 for top, 8 for right, add sides together for multiple sides) |
required |
combine
|
bool
|
digits are split into two pixels, when drawing to one combine keeps what is already drawn on the other side of the digit |
True
|
push
|
bool
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
draw_raw(x, y, value, push=False)
Draw to a specific segment on the screen
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate |
required |
y
|
int
|
y coordinate |
required |
value
|
int
|
which leds to turn on for the segment |
required |
push
|
bool
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
draw_shape_line(start_x, start_y, end_x, end_y, value, combine=True, push=False)
Draw line with given value at each pixel, can be diagonal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_x
|
int
|
starting x coordinate |
required |
start_y
|
int
|
starting y coordinate |
required |
end_x
|
int
|
ending x coordinate |
required |
end_y
|
int
|
ending y coordiante |
required |
value
|
int
|
which leds to turn on for the pixel (1 for bottom, 2 for left, 4 for top, 8 for right, add sides together for multiple sides) |
required |
combine
|
bool
|
digits are split into two pixels, when drawing to one combine keeps what is already drawn on the other side of the digit |
True
|
push
|
bool
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
draw_text(x, y, msg, combine=True, push=False)
Print a message to the screen, y_height-2 is lowest y value accepted without error. If the message is too long for the given x position, it will throw a ValueError. This function does not provide any wrapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate |
required |
y
|
int
|
y coordinate |
required |
msg
|
int
|
string message to print |
required |
combine
|
bool
|
digits are split into two pixels, when drawing to one combine keeps what is already drawn on the other side of the digit |
True
|
push
|
bool
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
draw_vline(start_x, start_y, length, left=True, combine=True, push=False)
Draw vertical line
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_x
|
int
|
x coordinate |
required |
start_y
|
int
|
y coordinate |
required |
length
|
int
|
length of line to draw |
required |
left
|
int
|
draw vertial line on the left or right of the pixel |
True
|
combine
|
bool
|
digits are split into two pixels, when drawing to one combine keeps what is already drawn on the other side of the digit |
True
|
push
|
bool
|
when true all the recent changes are pushed to the display |
False
|
Source code in display/display.py
get_pixel(x, y)
Get the value already at the pixel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate |
required |
y
|
int
|
y coordinate |
required |
Returns:
Type | Description |
---|---|
int
|
value of the pixel |
Source code in display/display.py
get_raw(x, y)
Get the value of the segment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate |
required |
y
|
int
|
y coordinate |
required |
Returns:
Type | Description |
---|---|
int
|
value of the segment |
push()
Push all the recent changes to the display
Source code in display/display.py
SegmentDisplay
SegmentDisplay is a class that abstracts the S^3 screen into individually controllable segments. Instead of making each circle of a segment a pixel, this class lets you control each segment as a pixel. This means this display is 2 times wider (there are two horizontal segments) and 3 times higher (there are three vertical segments) than the Display object.
Source code in display/segment_display.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
draw(push=True)
Updates the screen with all of the lines drawn using draw_line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
push
|
bool
|
when true all the recent changes are pushed to the display |
True
|
Source code in display/segment_display.py
draw_line(start_x, start_y, end_x, end_y)
Draws a line from coordinate to another. To display the line, you must use the draw function. This function only updates the underlying data buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_x
|
int
|
the starting x point |
required |
start_y
|
int
|
the starting y point |
required |
end_x
|
int
|
the ending x point |
required |
end_y
|
int
|
the ending y point |
required |
Source code in display/segment_display.py
undraw()
Clears all segments drawn both from the screen and from the underlying data structure.
Source code in display/segment_display.py
SevenSegment
Source code in display/seven_seg.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
__init__(num_digits=8, num_per_segment=MAX7219_DIGITS, baudrate=DEFAULT_BAUDRATE, cs_num=0, brightness=7, clear=True, segment_orientation_array=None)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_digits
|
int
|
total number of digits in your display |
8
|
num_per_segment
|
int
|
total number of digits per MAX7219 segment (default 8) |
MAX7219_DIGITS
|
baudrate
|
int
|
rate at which data is transfered (default 9000kHz), excessive rate may result in instability |
DEFAULT_BAUDRATE
|
cs_num
|
int
|
which control select line is being used |
0
|
brightness
|
int
|
starting brightness of the leds |
7
|
clear
|
bool
|
clear the screen on initialization |
True
|
segment_orientation_array
|
int[][]
|
None
|
Source code in display/seven_seg.py
brightness(value)
Sets the brightness for all of the segments ranging from 0 - 15
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
brightness value to set |
required |
Source code in display/seven_seg.py
clear(flush=True)
Clears the buffer, and if specified, flushes the display
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flush
|
bool
|
flush the display after clearing |
True
|
close(clear=True, shutdown=True)
Close the spi connection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clear
|
bool
|
clear the display before closing |
True
|
shutdown
|
bool
|
shutdown the display before closing |
True
|
Source code in display/seven_seg.py
command(register_num, value)
Sets control registers for each segment in the display
Parameters:
Name | Type | Description | Default |
---|---|---|---|
register_num
|
int
|
which register to set |
required |
value
|
int
|
value to set the register to |
required |
Source code in display/seven_seg.py
flush()
Flush all the current changes to the display
Source code in display/seven_seg.py
flush_legacy()
Cascade the buffer onto the display
Source code in display/seven_seg.py
letter(position, char, dot=False, flush=False)
Outputs ascii letter as close as it can, working letters/symbols found in symbols.py
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
int
|
position to draw the symbol |
required |
char
|
str
|
character to draw at the position |
required |
dot
|
bool
|
whether or not to draw a dot after the character |
False
|
flush
|
bool
|
flush the display after drawing |
False
|
Source code in display/seven_seg.py
letter2(x, y, char, dot=False, flush=False)
Output letter on the display at the coordinates provided if possible
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate to draw the symbol |
required |
y
|
int
|
y coordinate to draw the symbol |
required |
char
|
str
|
character to draw at the position |
required |
dot
|
bool
|
whether or not to draw a dot after the character |
False
|
flush
|
bool
|
flush the display after drawing |
False
|
Source code in display/seven_seg.py
raw(position, value, flush=False)
Given raw 0-255 value draw symbol at given postion
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position
|
int
|
position to draw the symbol |
required |
value
|
int
|
value to draw at the position |
required |
flush
|
bool
|
flush the display after drawing |
False
|
Source code in display/seven_seg.py
raw2(x, y, value, flush=False)
Given raw 0-255 value draw symbol at given coordinate
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate to draw the symbol |
required |
text(txt, start_position=0, flush=False)
Output text on the display at the start position if possible
Parameters:
Name | Type | Description | Default |
---|---|---|---|
txt
|
str
|
text to draw on the display |
required |
start_position
|
int
|
position to start drawing the text |
0
|
flush
|
bool
|
flush the display after drawing |
False
|
Source code in display/seven_seg.py
text2(x, y, txt, horizontal=True, flush=False)
Output text on the display at the given x, y - option to display horizontal or vertical text
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
x coordinate to draw the symbol |
required |
y
|
int
|
y coordinate to draw the symbol |
required |
txt
|
str
|
text to draw on the display |
required |
horizontal
|
bool
|
whether or not to draw the text horizontally |
True
|
flush
|
bool
|
flush the display after drawing |
False
|