Add support to draw images via MCP on the RLCD display
This commit is contained in:
@@ -169,6 +169,20 @@ class MCPServer:
|
||||
"name": "get_screenshot",
|
||||
"description": "Capture the current reflective LCD screen rendering as a PNG image.",
|
||||
"inputSchema": {"type": "object", "properties": {}}
|
||||
},
|
||||
{
|
||||
"name": "draw_image",
|
||||
"description": "Draw an image (PNG, JPEG, GIF, BMP, etc.) on the screen. The image will be converted to 1-bit monochrome and fit to display boundaries.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"image_base64": {"type": "string", "description": "Base64 encoded string of the source image file"},
|
||||
"x": {"type": "integer", "description": "X coordinate to place the image (default 0)", "default": 0},
|
||||
"y": {"type": "integer", "description": "Y coordinate to place the image (default 0)", "default": 0},
|
||||
"dither": {"type": "boolean", "description": "Whether to use Floyd-Steinberg dithering (default true)", "default": True}
|
||||
},
|
||||
"required": ["image_base64"]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -280,6 +294,35 @@ class MCPServer:
|
||||
return f"__PBM_BASE64__:{b64}"
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Screenshot capture failed: {e}")
|
||||
|
||||
elif name == "draw_image":
|
||||
self.override_active = True
|
||||
self.override_timeout = time.ticks_ms() + 30000 # 30-sec override
|
||||
|
||||
pbm_b64 = args.get("pbm_base64")
|
||||
x = int(args.get("x", 0))
|
||||
y = int(args.get("y", 0))
|
||||
|
||||
if not pbm_b64:
|
||||
raise ValueError("Missing pbm_base64 parameter (preprocessed by bridge)")
|
||||
|
||||
import binascii
|
||||
pbm_bytes = binascii.a2b_base64(pbm_b64)
|
||||
|
||||
filename = 'temp_recv.pbm'
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(pbm_bytes)
|
||||
|
||||
try:
|
||||
self.display.draw_pbm(filename, x, y, scale=1)
|
||||
self.display.show()
|
||||
finally:
|
||||
import os
|
||||
try:
|
||||
os.remove(filename)
|
||||
except:
|
||||
pass
|
||||
return "Image displayed successfully."
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unknown tool: {name}")
|
||||
|
||||
Reference in New Issue
Block a user