8000 Add flow control to the GPGL protocol by lagnat · Pull Request #453 · inkcut/inkcut · GitHub
[go: up one dir, main page]

Skip to content

Add flow control to the GPGL protocol - #453

Draft
lagnat wants to merge 6 commits into
inkcut:masterfrom
lagnat:gpgl-flow-control
Draft

lagnat wants to merge 6 commits into
inkcut:masterfrom
lagnat:gpgl-flow-control

Conversation

@lagnat
@lagnat lagnat commented Nov 27, 2026
Copy link
Copy Markdown
Contributor

Builds on #452 (Bluetooth LE transport). Until that is merged its commits show here too; only the last commit, Add flow control to the GPGL protocol, is new.

Problem

Inkcut sends a job one command per write, with delays between commands estimated from the speed setting. Over BLE each write takes ~60 ms to be acknowledged, whatever its size. Curves are sent as steps of about 0.5 mm, so on a Silhouette Cameo 4 the head draws a step, stops, and waits for the next: curves crawl and stutter.

What this does

An optional GPGL setting, flow_control:

  • During a job, commands are packed into writes of up to 180 bytes, each ending with an FG query.
  • The Cameo answers a query only once it reaches it in its queue, after the commands before it. The answers therefore show how far the machine has got, and at most 8 batches are left unanswered. That keeps its buffer fed without overfilling it. Inkcut's estimated delays are turned off, as they are for spooled connections.
  • Nothing is sent while the machine is paused, because the Cameo silently discards whatever arrives then. The protocol checks the state (ESC ENQ) before each batch, and also stops as soon as the machine reports a pause unasked (the BLE transport now passes those reports to the protocol).
  • At the end of a job it waits for the last answer before Inkcut disconnects, because disconnecting clears whatever the machine has yet to run.
  • If the machine sits idle with batches unanswered (one sent just as it paused, say), they are logged and no longer waited on, so a job can't hang.

Jogging still sends each move at once, and spooled connections (printer queue, file) are left alone, since they never answer. The setting is off by default; the Cameo 4 driver turns it on, and there is a checkbox for it in the protocol settings.

DeviceProtocol gains three small hooks for this: start_job(), controls_flow() and status_received().

Measured on a Cameo 4 Plus over BLE

  • The same job: 57 s → 22 s, and the machine reports busy once at the start and ready at the end, with no stops in between (before, it stopped after nearly every move).
  • The Cameo accepted and drew at least 64 KB queued at once without dropping anything or pushing back.
  • It answers ESC ENQ while paused, but not ordinary queries such as FG, and drops whatever is sent during a pause. With the pause button pressed 74 times during a job, every batch was answered and none was lost.

Tests

New tests in tests/test_protocols.py use a fake Cameo transport to cover batching, sending immediately when not in a job, spooled connections, the window, pausing, and lost batches.

🤖 Generated with Claude Code

lagnat and others added 4 commits October 14, 2026 22:26
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>
lagnat and others added 2 commits November 27, 2026 15:53
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>
Inkcut sends a job one command per write, with delays between them
estimated from the speed setting. Over BLE each write takes ~60 ms to
be acknowledged whatever its size, so a curve made of 0.5 mm steps
stops after every step: the Cameo draws faster than single commands
arrive.

With flow control on, a job's commands go out in writes of up to 180
bytes, each ending with an FG query. The Cameo answers a query only
once it reaches it in its queue, after the commands before it, so the
answers show how far it has got. At most 8 batches are left unanswered,
which keeps its buffer fed without overfilling it, and the estimated
delays are turned off. At the end of a job the protocol waits for the
last answer, since disconnecting clears what the machine has yet to
run.

Nothing is sent while the Cameo is paused, as it silently discards what
arrives then. The protocol checks its state (ESC ENQ) before each batch
and also stops as soon as the machine reports a pause unasked, which
the BLE transport now passes to the protocol. Batches still unanswered
once the machine sits idle are logged and no longer waited on, so a
job cannot hang.

Batching only applies during a job, so jogging still sends each move
at once, and not on spooled connections, which never answer. It is off
by default and the Cameo 4 driver turns it on.

DeviceProtocol gains start_job(), controls_flow() and status_received()
for this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lagnat
lagnat marked this pull request as draft November 28, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

D 3AAB evelopment

Successfully merging this pull request may close these issues.

1 participant

0