mirror of
https://github.com/jhbruhn/respira.git
synced 2026-04-28 01:55:45 +00:00
Compare commits
No commits in common. "3e6a6688e3847f637b7d04c1bd120fb943fe3d41" and "270a464742bf19fbdf464f29fc97d2e6cd1db9ce" have entirely different histories.
3e6a6688e3
...
270a464742
3 changed files with 25 additions and 40 deletions
|
|
@ -71,12 +71,12 @@ export function ProgressMonitor() {
|
||||||
const isMaskTraceComplete =
|
const isMaskTraceComplete =
|
||||||
machineStatus === MachineStatus.MASK_TRACE_COMPLETE;
|
machineStatus === MachineStatus.MASK_TRACE_COMPLETE;
|
||||||
|
|
||||||
// Use our own PEN stitch count as the source of truth for total stitches.
|
// Use PEN stitch count as fallback when machine reports 0 total stitches
|
||||||
// The machine's patternInfo.totalStitches uses a different counting method than
|
const totalStitches = patternInfo
|
||||||
// currentStitch (e.g. excludes lock stitches), so it can't be used as the max.
|
? patternInfo.totalStitches === 0 && displayPattern?.penStitches
|
||||||
const totalStitches = displayPattern?.penStitches
|
|
||||||
? displayPattern.penStitches.stitches.length
|
? displayPattern.penStitches.stitches.length
|
||||||
: (patternInfo?.totalStitches ?? 0);
|
: patternInfo.totalStitches
|
||||||
|
: 0;
|
||||||
|
|
||||||
// Use adjustedStitchIndex (from step control) when available, otherwise machine-reported
|
// Use adjustedStitchIndex (from step control) when available, otherwise machine-reported
|
||||||
const currentStitch =
|
const currentStitch =
|
||||||
|
|
@ -156,10 +156,8 @@ export function ProgressMonitor() {
|
||||||
totalStitches={totalStitches}
|
totalStitches={totalStitches}
|
||||||
lastRolledBackError={lastRolledBackError}
|
lastRolledBackError={lastRolledBackError}
|
||||||
colorBlocks={colorBlocks}
|
colorBlocks={colorBlocks}
|
||||||
onAdjustPosition={(offset) =>
|
onAdjustPosition={adjustStitchPosition}
|
||||||
adjustStitchPosition(offset, totalStitches)
|
onSetPosition={setStitchPosition}
|
||||||
}
|
|
||||||
onSetPosition={(index) => setStitchPosition(index, totalStitches)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ interface MachineState {
|
||||||
startSewing: () => Promise<void>;
|
startSewing: () => Promise<void>;
|
||||||
resumeSewing: () => Promise<void>;
|
resumeSewing: () => Promise<void>;
|
||||||
deletePattern: () => Promise<void>;
|
deletePattern: () => Promise<void>;
|
||||||
setStitchPosition: (index: number, maxStitches?: number) => Promise<void>;
|
setStitchPosition: (index: number) => Promise<void>;
|
||||||
adjustStitchPosition: (offset: number, maxStitches?: number) => Promise<void>;
|
adjustStitchPosition: (offset: number) => Promise<void>;
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
initialize: () => void;
|
initialize: () => void;
|
||||||
|
|
@ -338,11 +338,11 @@ export const useMachineStore = create<MachineState>((set, get) => ({
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set stitch position to an absolute index
|
// Set stitch position to an absolute index
|
||||||
setStitchPosition: async (index: number, maxStitches?: number) => {
|
setStitchPosition: async (index: number) => {
|
||||||
const { isConnected, service, patternInfo } = get();
|
const { isConnected, service, patternInfo } = get();
|
||||||
if (!isConnected) return;
|
if (!isConnected) return;
|
||||||
|
|
||||||
const totalStitches = maxStitches ?? patternInfo?.totalStitches ?? 0;
|
const totalStitches = patternInfo?.totalStitches || 0;
|
||||||
const clamped = Math.max(0, Math.min(index, totalStitches));
|
const clamped = Math.max(0, Math.min(index, totalStitches));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -359,11 +359,11 @@ export const useMachineStore = create<MachineState>((set, get) => ({
|
||||||
},
|
},
|
||||||
|
|
||||||
// Adjust stitch position by a relative offset
|
// Adjust stitch position by a relative offset
|
||||||
adjustStitchPosition: async (offset: number, maxStitches?: number) => {
|
adjustStitchPosition: async (offset: number) => {
|
||||||
const { sewingProgress, adjustedStitchIndex } = get();
|
const { sewingProgress, adjustedStitchIndex } = get();
|
||||||
const currentIndex =
|
const currentIndex =
|
||||||
adjustedStitchIndex ?? sewingProgress?.currentStitch ?? 0;
|
adjustedStitchIndex ?? sewingProgress?.currentStitch ?? 0;
|
||||||
await get().setStitchPosition(currentIndex + offset, maxStitches);
|
await get().setStitchPosition(currentIndex + offset);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle automatic stitch rollback for thread errors
|
// Handle automatic stitch rollback for thread errors
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,6 @@ export interface ThreadColorInfo {
|
||||||
// Type-safe Brother color data
|
// Type-safe Brother color data
|
||||||
const brotherColors = brotherColorData as BrotherColor[];
|
const brotherColors = brotherColorData as BrotherColor[];
|
||||||
|
|
||||||
// Maximum RGB Euclidean distance to accept a catalog number match.
|
|
||||||
// PES catalog numbers from pystitch use a different numbering scheme than our
|
|
||||||
// Brother color database, so a catalog hit can resolve to the wrong color.
|
|
||||||
// A match is only trusted if the database entry's RGB is within this distance.
|
|
||||||
const CATALOG_COLOR_MATCH_THRESHOLD = 50;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert RGB values to hex color string
|
* Convert RGB values to hex color string
|
||||||
*/
|
*/
|
||||||
|
|
@ -272,32 +266,25 @@ export function enhanceThreadWithBrotherColor(
|
||||||
): ThreadColorInfo {
|
): ThreadColorInfo {
|
||||||
const { matchByRGB = true } = options;
|
const { matchByRGB = true } = options;
|
||||||
|
|
||||||
|
// First, try to match by catalog number
|
||||||
|
if (thread.catalogNumber) {
|
||||||
|
const brotherInfo = mapThreadCode(thread.catalogNumber);
|
||||||
|
if (brotherInfo) {
|
||||||
|
// Found a Brother color match by catalog number - use Brother data
|
||||||
|
return brotherInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, try exact RGB matching if enabled (replicates BrotherColor.FromColor logic)
|
||||||
const cleanHex = thread.hex.replace("#", "");
|
const cleanHex = thread.hex.replace("#", "");
|
||||||
const r = parseInt(cleanHex.slice(0, 2), 16);
|
const r = parseInt(cleanHex.slice(0, 2), 16);
|
||||||
const g = parseInt(cleanHex.slice(2, 4), 16);
|
const g = parseInt(cleanHex.slice(2, 4), 16);
|
||||||
const b = parseInt(cleanHex.slice(4, 6), 16);
|
const b = parseInt(cleanHex.slice(4, 6), 16);
|
||||||
|
|
||||||
// First, try to match by catalog number — but only accept the match if the
|
|
||||||
// catalog entry's RGB is close to the thread's actual color. PES catalog
|
|
||||||
// numbers from pystitch use a different numbering scheme than our Brother
|
|
||||||
// color database, so a catalog hit can be the wrong color entirely.
|
|
||||||
if (thread.catalogNumber) {
|
|
||||||
const brotherInfo = mapThreadCode(thread.catalogNumber);
|
|
||||||
if (brotherInfo?.rgb) {
|
|
||||||
const dr = brotherInfo.rgb.r - r;
|
|
||||||
const dg = brotherInfo.rgb.g - g;
|
|
||||||
const db = brotherInfo.rgb.b - b;
|
|
||||||
const distance = Math.sqrt(dr * dr + dg * dg + db * db);
|
|
||||||
if (distance <= CATALOG_COLOR_MATCH_THRESHOLD) {
|
|
||||||
return brotherInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try exact RGB matching (replicates BrotherColor.FromColor logic)
|
|
||||||
if (matchByRGB) {
|
if (matchByRGB) {
|
||||||
const brotherColor = findBrotherColorByRGB(r, g, b);
|
const brotherColor = findBrotherColorByRGB(r, g, b);
|
||||||
if (brotherColor) {
|
if (brotherColor) {
|
||||||
|
// Found exact RGB match - use Brother data
|
||||||
return brotherColorToThreadInfo(brotherColor);
|
return brotherColorToThreadInfo(brotherColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue