mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 18:33:41 +00:00
Fix TRIM command encoding in PES to PEN conversion
Correct the encoding of TRIM commands to use the proper bit flag (bit 1) instead of incorrectly treating them the same as JUMP commands (bit 0). The PEN format uses two separate flags in the Y-coordinate low byte: - Bit 0 (0x01): FEED_DATA - Jump stitch (move without stitching) - Bit 1 (0x02): CUT_DATA - Trim/cut thread command Previously, both JUMP and TRIM commands were encoded with bit 0, which prevented the machine from distinguishing between jumps and thread cuts. Changes: - Add PEN_CUT_DATA constant (0x02) for TRIM commands - Update encoding logic to set bit 0 for JUMP (cmd=1) - Update encoding logic to set bit 1 for TRIM (cmd=2) - Add detailed comments explaining the PEN format flags - Document that Y-coordinate flags can be combined - Document that X-coordinate flags are mutually exclusive This fix ensures thread cutting happens when intended, matching the behavior of the original C# implementation in the Asura app. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
711f291eff
commit
be3f15eace
1 changed files with 13 additions and 5 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
import { pyodideLoader } from './pyodideLoader';
|
import { pyodideLoader } from './pyodideLoader';
|
||||||
|
|
||||||
// PEN format flags
|
// PEN format flags
|
||||||
const PEN_FEED_DATA = 0x01; // Y-coordinate low byte, bit 0 (jump)
|
// Y-coordinate low byte flags (can be combined)
|
||||||
const PEN_COLOR_END = 0x03; // X-coordinate low byte, bits 0-2
|
const PEN_FEED_DATA = 0x01; // Bit 0: Jump stitch (move without stitching)
|
||||||
const PEN_DATA_END = 0x05; // X-coordinate low byte, bits 0-2
|
const PEN_CUT_DATA = 0x02; // Bit 1: Trim/cut thread command
|
||||||
|
|
||||||
|
// X-coordinate low byte flags (bits 0-2, mutually exclusive)
|
||||||
|
const PEN_COLOR_END = 0x03; // Last stitch before color change
|
||||||
|
const PEN_DATA_END = 0x05; // Last stitch of entire pattern
|
||||||
|
|
||||||
// Embroidery command constants (from pyembroidery)
|
// Embroidery command constants (from pyembroidery)
|
||||||
const MOVE = 0x10;
|
const MOVE = 0x10;
|
||||||
|
|
@ -153,10 +157,14 @@ for i, stitch in enumerate(pattern.stitches):
|
||||||
let xEncoded = (absX << 3) & 0xFFFF;
|
let xEncoded = (absX << 3) & 0xFFFF;
|
||||||
let yEncoded = (absY << 3) & 0xFFFF;
|
let yEncoded = (absY << 3) & 0xFFFF;
|
||||||
|
|
||||||
// Add jump flag if this is a JUMP (1) or TRIM (2) command
|
// Add command flags to Y-coordinate based on stitch type
|
||||||
// PyStitch constants: STITCH=0, JUMP=1, TRIM=2
|
// PyStitch constants: STITCH=0, JUMP=1, TRIM=2
|
||||||
if (cmd === 1 || cmd === 2) {
|
if (cmd === 1) {
|
||||||
|
// JUMP: Set bit 0 (FEED_DATA) - move without stitching
|
||||||
yEncoded |= PEN_FEED_DATA;
|
yEncoded |= PEN_FEED_DATA;
|
||||||
|
} else if (cmd === 2) {
|
||||||
|
// TRIM: Set bit 1 (CUT_DATA) - cut thread command
|
||||||
|
yEncoded |= PEN_CUT_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is the last stitch
|
// Check if this is the last stitch
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue