Skip to content

Commit

Permalink
bug fixes, docs, additional commands
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellee1019 committed Apr 12, 2024
1 parent d79cd68 commit 5159b99
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The following config is used to control a single [HiLetgo MAX7219 Dot Matrix Mod
## DoCommand Examples
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.


### Border
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.
```
{
"drawings": [
Expand All @@ -25,4 +28,106 @@ A single DoCommand call will erase the display and draw a new canvas from scratc
}
]
}
```
```

### Rectangle
Draw a rectangle on the display. Options:
- `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]`.
{
"drawings": [
{
"type": "rectangle",
"pixels": [
0,
0,
4,
5
]
}
]
}

### Text
Write text to the display. Options:
- `message`: The text to display
- `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]`.
- `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.
```
{
"drawings": [
{
"type": "text",
"message": "VIAM",
"start_pixel": [
3,
0
]
}
]
}
```

### Point
Light up a single pixel on the display. Options:
- `pixel` The xy coordinates of the pixel. Provide the coordinates a list of two integers like `[x, y]`.

{
"drawings": [
{
"type": "point",
"pixel": [
3,
0
]
}
]
}

### Line
Draw a line of pixels on the display. Options:
- `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]`.

{
"drawings": [
{
"type": "line",
"pixels": [
0,
0,
0,
5
]
}
]
}

### Multiple drawings.
Provide a list of drawings to place multiple elements on to the screen. The next DoCommand will erase the screen
{
"drawings": [
{
"type": "point",
"pixel": [
0,
0
]
},
{
"type": "text",
"message": "VIAM",
"start_pixel": [
3,
0
]
},
{
"type": "line",
"pixels": [
31,
0,
31,
7
]
}
]
}
21 changes: 17 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,29 @@ async def do_command(
match drawing["type"]:
case "border":
self.border(draw)
case "rectangle":
pixels = drawing["pixels"]
self.rectangle(draw, pixels)
case "text":
message = drawing["message"]
start_pixel = drawing["start_pixel"]
font = drawing.get("font", "CP437_FONT")
font = drawing.get("font")
self.text(draw, start_pixel, message, font)
case "point":
pixel = drawing["pixel"]
self.point(draw, pixel)
case "line":
pixels = drawing["pixels"]
self.point(draw, pixels)
width = drawing.get("width")
self.line(draw, pixels, width)
result["drawings"] = True
return result

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

def rectangle(self, draw, pixels: list[int]):
draw.rectangle(pixels, outline="white")
def text(self, draw, start_pixel: list[int], message: str, font):
font_cls = CP437_FONT
if font is "LCD_FONT":
Expand All @@ -75,12 +81,19 @@ def text(self, draw, start_pixel: list[int], message: str, font):
def point(self, draw, pixel: list[int]):
draw.point(pixel, fill="white")

def line(self, draw, pixels: list[int]):
draw.line(pixels, fill="white")
def line(self, draw, pixels: list[int], width):
if not width:
width=1
draw.line(pixels, fill="white", width=width)

def reconfigure(self,
config: ComponentConfig,
dependencies: Mapping[ResourceName, ResourceBase]):

#Cleanup the screen and previous drawings on reconfigure
if self.device is not None:
self.device.cleanup()

spi_bus = int(config.attributes.fields["spi_bus"].string_value)
chip_select = int(config.attributes.fields["chip_select"].string_value)
block_orientation = int(config.attributes.fields["block_orientation"].number_value)
Expand Down

0 comments on commit 5159b99

Please sign in to comment.