Repository navigation
Add a Bluetooth LE transport - #452
#452Open
lagnat wants to merge 5 commits into
Open
lagnat wants to merge 5 commits into
lagnat wants to merge 5 commits into
Conversation
Add a transport for cutters that take their commands over a BLE GATT
service, such as the Silhouette Cameo 4. It uses bleak, running on the
application's asyncio event loop. Writes are serialized so commands
stay ordered, and status notifications are fed to protocol.data_received.
A BLE connect takes a while, and each jog asks to connect while one is
still running, so concurrent requests share the connect in progress;
otherwise two clients end up attached to one machine.
The service and characteristics are set by the transport config rather
than hard coded. Drivers provide them under
default_config['connection']['ble']: service_uuid and write_uuid are
required, notify_uuid is optional for machines that report status.
Nothing is detected from the device. They are not shown in the settings
view; the module docstring explains how to find the values for a new
cutter.
Cameo 4 gains 'ble' alongside 'printer' with its values, taken from a
GATT dump of a Cameo 4 Plus. Its service has two characteristics with
identical write/indicate properties; only testing showed which one
reports status.
Two settings are needed to make a Cameo respond, and the Cameo 4 driver
turns both on:
- writes must be made with a response. The machine ignores
write-without-response entirely.
- each write must end with ETX. The GPGL protocol puts ETX before each
command, so the latest one is not run until the next is sent.
The scan is filtered by name so the list shows cutters instead of every
phone and TV nearby. A BLE connection can only be made to a device that
is advertising, so connecting always finds the device by a scan first,
even with a saved address. A device connected elsewhere stops
advertising, and the error says so.
Tested against a Cameo 4 Plus: connects, homes, and reports busy/ready
status back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Cameo 4 Plus is the 15" model of the Cameo 4. It takes the same commands and has the same BLE service and characteristics (checked on a Cameo 4 Plus, which is where the Cameo 4 values came from), so only the cutting width differs: 38.1cm. Rather than copy the Cameo 4 entry, it is moved into a Cameo4Driver enamldef that both models declare, the Plus overriding model and length. Overrides replace an attribute whole, so a variant that needs a different default_config has to restate it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Cameo answers queries (FG for its name, ESC ENQ for its state, ESC NAK for the tools loaded) on a different characteristic from the one it reports status on, and the transport only subscribed to the status one, so a protocol could send a query but never see the answer. Add read_uuid for the reply characteristic. Replies on it go to protocol.data_received and last_read, like a serial port's input. The status characteristic is still subscribed but now only logged: the machine sends "1" (busy) and "0"/"2" (ready, with or without media) unasked whenever it moves, and passing those on would let a protocol take an unrelated "busy" as the answer to its query. A protocol that wants the state asks with ESC ENQ, which works the same over USB. A machine with no read_uuid answers on notify_uuid, which then stays the reply stream as before. Cameo 4 gets read_uuid 8dcf199a-..., found by subscribing to both characteristics on a Cameo 4 Plus and sending each query. The docstring's GATT table and status values are corrected to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Terminating each command with ETX is a GPGL matter, not a BLE one, so it moves from the BLE transport config to a new GPGLConfig, with a checkbox in the protocol settings. The Cameo 4 driver sets it under protocol/gpgl, and it now also applies over USB. The ETX characters GPGL already puts before each command were raw control characters in the source; they are written as \x03 escapes now so they can be seen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 27, 2026
On macOS a checkbox is laid out at a smaller size than it is drawn, leaving room for its focus ring, so in a container with no padding the widget runs past the container's edge and is clipped: 9 px at the right of both checkboxes here, and 4 px at the bottom of the last. Pad those containers by as much. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #441, which closed when its base branch
asynciowas merged and deleted. Same commits, now againstmaster, plus one movingappend_etxinto the GPGL protocol as requested there.Adds a Bluetooth LE transport (
ble) using bleak,for cutters that take their commands over a BLE GATT service, such as the
Silhouette Cameo 4. Also adds a Cameo 4 Plus driver.
Behaviour worth knowing
write-without-response.
append_etxis now a GPGL protocol option (GPGLConfig, with acheckbox in the protocol settings) rather than a BLE one. It ends each
command with ETX; GPGL already puts ETX before each command, so without
it the latest command isn't run until the next arrives. The Cameo 4 driver
turns it on under
default_config['protocol']['gpgl'].queries (
FG,ESC ENQ,ESC NAK) on one, and on another reports1(busy) /
0or2(ready, with or without media) unasked whenever itmoves. Replies (
read_uuid) go toprotocol.data_receivedandlast_read, like a serial port's input. Status (notify_uuid) is onlylogged, so an unrelated "busy" can't be taken as the answer to a query; a
protocol that wants the state asks with
ESC ENQ, as it would over USB. Amachine with no
read_uuidanswers onnotify_uuid, which is then thereply stream.
can only be made to a device that is advertising, and a device connected
elsewhere (Silhouette Studio, a phone) stops advertising. The error says so.
Cameo 4 Plus
The 15" Cameo 4 Plus takes the same commands and has the same BLE service
and characteristics (the Cameo 4 values were in fact taken from a 4 Plus),
so only its cutting width differs. Rather than copy the Cameo 4 entry, it is
moved into a
Cameo4Driverenamldef that both models declare:For discussion: where the UUIDs live
The transport needs a service UUID and a write characteristic UUID (plus
optional read and notify ones) to work at all, so they are really part of
the driver's definition rather than defaults. They currently go in
default_config['connection']['ble'], read through the existingget_connection_config:We didn't see a better place. Top-level
DeviceDriverattributes would putBLE-specific fields on every driver. One consequence: a saved device keeps a
copy of its driver from when it was added, so existing Cameo 4 devices don't
get these values and need to be added again to use BLE.
For discussion: transport shutdown
Transports get no notification when Inkcut quits, and by then the event loop
has stopped. If a BLE scan is still running at exit (e.g. quitting during a
connect), CoreBluetooth delivers a callback into a half torn down interpreter
and the process aborts on macOS. Cancelling outstanding tasks after
run_forever()returns and running the loop until they finish, asasyncio.run()does, fixes it in a quick test, since bleak stops scanningwhen its task is cancelled. I've left this out since it's core app code and
you may have a shutdown hook for transports in mind.
bleakis added toinstall_requires. Happy to make it an optional extrainstead if you'd prefer.
🤖 Generated with Claude Code