Skip to content

Commit 5159b99

Browse files
bug fixes, docs, additional commands
1 parent d79cd68 commit 5159b99

File tree

2 files changed

+123
-5
lines changed

2 files changed

+123
-5
lines changed

Diff for: README.md

+106-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ The following config is used to control a single [HiLetgo MAX7219 Dot Matrix Mod
1717
## DoCommand Examples
1818
A single DoCommand call will erase the display and draw a new canvas from scratch. Each DoCommand call can contain a list of drawings to be performed in a single frame, where the screen will not be cleared between each drawing.
1919

20+
21+
### Border
22+
Draws a border around the display using the provided width + height in the attributes of the component. This type has no options available to it.
2023
```
2124
{
2225
"drawings": [
@@ -25,4 +28,106 @@ A single DoCommand call will erase the display and draw a new canvas from scratc
2528
}
2629
]
2730
}
28-
```
31+
```
32+
33+
### Rectangle
34+
Draw a rectangle on the display. Options:
35+
- `pixels`: An array of integers representing the start and end pixels to draw the rectangle. Provide the coordinates a list of four integers like `[start_x, start_y, end_x, end_y]`.
36+
{
37+
"drawings": [
38+
{
39+
"type": "rectangle",
40+
"pixels": [
41+
0,
42+
0,
43+
4,
44+
5
45+
]
46+
}
47+
]
48+
}
49+
50+
### Text
51+
Write text to the display. Options:
52+
- `message`: The text to display
53+
- `start_pixel`: The xy coordinates to start the text. Helpful to center text visually. Provide the coordinates a list of two integers like `[x, y]`.
54+
- `font`: The font to use, defaults to `CP437_FONT` if not provided. The other option is `LCD_FONT` but this font isn't ideal for this display because its hight is greater than 8 pixels.
55+
```
56+
{
57+
"drawings": [
58+
{
59+
"type": "text",
60+
"message": "VIAM",
61+
"start_pixel": [
62+
3,
63+
0
64+
]
65+
}
66+
]
67+
}
68+
```
69+
70+
### Point
71+
Light up a single pixel on the display. Options:
72+
- `pixel` The xy coordinates of the pixel. Provide the coordinates a list of two integers like `[x, y]`.
73+
74+
{
75+
"drawings": [
76+
{
77+
"type": "point",
78+
"pixel": [
79+
3,
80+
0
81+
]
82+
}
83+
]
84+
}
85+
86+
### Line
87+
Draw a line of pixels on the display. Options:
88+
- `pixels`: An array of integers representing the start and end pixels to draw the line. Provide the coordinates a list of four integers like `[start_x, start_y, end_x, end_y]`.
89+
90+
{
91+
"drawings": [
92+
{
93+
"type": "line",
94+
"pixels": [
95+
0,
96+
0,
97+
0,
98+
5
99+
]
100+
}
101+
]
102+
}
103+
104+
### Multiple drawings.
105+
Provide a list of drawings to place multiple elements on to the screen. The next DoCommand will erase the screen
106+
{
107+
"drawings": [
108+
{
109+
"type": "point",
110+
"pixel": [
111+
0,
112+
0
113+
]
114+
},
115+
{
116+
"type": "text",
117+
"message": "VIAM",
118+
"start_pixel": [
119+
3,
120+
0
121+
]
122+
},
123+
{
124+
"type": "line",
125+
"pixels": [
126+
31,
127+
0,
128+
31,
129+
7
130+
]
131+
}
132+
]
133+
}

Diff for: models.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,29 @@ async def do_command(
4949
match drawing["type"]:
5050
case "border":
5151
self.border(draw)
52+
case "rectangle":
53+
pixels = drawing["pixels"]
54+
self.rectangle(draw, pixels)
5255
case "text":
5356
message = drawing["message"]
5457
start_pixel = drawing["start_pixel"]
55-
font = drawing.get("font", "CP437_FONT")
58+
font = drawing.get("font")
5659
self.text(draw, start_pixel, message, font)
5760
case "point":
5861
pixel = drawing["pixel"]
5962
self.point(draw, pixel)
6063
case "line":
6164
pixels = drawing["pixels"]
62-
self.point(draw, pixels)
65+
width = drawing.get("width")
66+
self.line(draw, pixels, width)
6367
result["drawings"] = True
6468
return result
6569

6670
def border(self, draw):
6771
draw.rectangle(self.device.bounding_box, outline="white")
6872

73+
def rectangle(self, draw, pixels: list[int]):
74+
draw.rectangle(pixels, outline="white")
6975
def text(self, draw, start_pixel: list[int], message: str, font):
7076
font_cls = CP437_FONT
7177
if font is "LCD_FONT":
@@ -75,12 +81,19 @@ def text(self, draw, start_pixel: list[int], message: str, font):
7581
def point(self, draw, pixel: list[int]):
7682
draw.point(pixel, fill="white")
7783

78-
def line(self, draw, pixels: list[int]):
79-
draw.line(pixels, fill="white")
84+
def line(self, draw, pixels: list[int], width):
85+
if not width:
86+
width=1
87+
draw.line(pixels, fill="white", width=width)
8088

8189
def reconfigure(self,
8290
config: ComponentConfig,
8391
dependencies: Mapping[ResourceName, ResourceBase]):
92+
93+
#Cleanup the screen and previous drawings on reconfigure
94+
if self.device is not None:
95+
self.device.cleanup()
96+
8497
spi_bus = int(config.attributes.fields["spi_bus"].string_value)
8598
chip_select = int(config.attributes.fields["chip_select"].string_value)
8699
block_orientation = int(config.attributes.fields["block_orientation"].number_value)

0 commit comments

Comments
 (0)