diff --git a/pyproject.toml b/pyproject.toml index 99f9e01..76fbb0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "frame-sdk" -version = "1.2.1" +version = "1.2.2" authors = [{ name = "Roger Pincombe", email = "pip@betechie.com" },{ name = "Brilliant Labs", email = "info@brilliant.xyz" }] description = "Python Developer SDK for Brilliant Frame glasses" readme = "readme.md" diff --git a/src/frame_sdk/display.py b/src/frame_sdk/display.py index 3ef5a78..55689ba 100644 --- a/src/frame_sdk/display.py +++ b/src/frame_sdk/display.py @@ -519,6 +519,90 @@ async def draw_rect(self, x: int, y: int, w: int, h: int, color: PaletteColors = w = w // 8 * 8 await self.frame.run_lua(self._draw_rect_lua(x, y, w, h, color)) + + def _draw_vector_lua(self, x: int, y: int, w: int, h: int, color: PaletteColors): + """Helper function to generate Lua code for vector drawing using bitmap.""" + if isinstance(color, PaletteColors): + color = color.value + + # Determine color mode based on color value + if color <= 1: + # 2-color mode: 8 pixels per byte + color_mode = 2 + pixels_per_byte = 8 + elif color <= 3: + # 4-color mode: 4 pixels per byte + color_mode = 4 + pixels_per_byte = 4 + else: + # 16-color mode: 2 pixels per byte + color_mode = 16 + pixels_per_byte = 2 + + # Adjust width based on color mode + w = w // pixels_per_byte * pixels_per_byte + + # Calculate bytes needed based on color mode + bytes_needed = (w // pixels_per_byte) * h + + if color_mode == 2: + pattern = "\\xFF" + elif color_mode == 4: + pattern = "\\xFF" + else: + pattern = "\\xFF" + + return f"frame.display.bitmap({x},{y},{w},{color_mode},{color},string.rep(\"{pattern}\",{bytes_needed}))" + + async def draw_vector(self, x1: int, y1: int, x2: int, y2: int, color: PaletteColors = PaletteColors.WHITE): + """ + Draws a vector (including diagonals) using bitmap on the display. + + Args: + x1 (int): The x coordinate of the start point. + y1 (int): The y coordinate of the start point. + x2 (int): The x coordinate of the end point. + y2 (int): The y coordinate of the end point. + color (PaletteColors): The color of the line (uses palette offset) + """ + if isinstance(color, PaletteColors): + color = color.value + + # Determine color mode and minimum bitmap width + if color <= 1: + min_width = 8 # 2-color mode: 8 pixels per byte + elif color <= 3: + min_width = 4 # 4-color mode: 4 pixels per byte + else: + min_width = 2 # 16-color mode: 2 pixels per byte + + dx = abs(x2 - x1) + dy = abs(y2 - y1) + sx = 1 if x1 < x2 else -1 + sy = 1 if y1 < y2 else -1 + + if dx > dy: + # More horizontal movement + error = dx / 2 + while x1 != x2: + # Draw bitmap with appropriate width + await self.frame.run_lua(self._draw_vector_lua(x1, y1, min_width, 1, color)) + error -= dy + if error < 0: + y1 += sy + error += dx + x1 += sx + else: + # More vertical movement + error = dy / 2 + while y1 != y2: + # Draw bitmap with appropriate width + await self.frame.run_lua(self._draw_vector_lua(x1, y1, min_width, 1, color)) + error -= dx + if error < 0: + x1 += sx + error += dy + y1 += sy async def draw_rect_filled(self, x: int, y: int, w: int, h: int, border_width: int, border_color: PaletteColors, fill_color: PaletteColors): """