Add cumulative stitch statistics from SERVICE_COUNT command

Implement support for fetching and displaying the machine's cumulative
stitch statistics using the SERVICE_COUNT (0x0100) command.

The SERVICE_COUNT command returns two uint32 values:
- serviceCount: Cumulative service counter
- totalCount: Total stitches sewn by the machine (lifetime)

Changes:
- Add serviceCount and totalCount fields to MachineInfo interface
- Implement getServiceCount() method in BrotherPP1Service
- Call getServiceCount() when fetching machine info on connect
- Display "Total Stitches" in Machine Connection panel
- Format stitch count with locale-specific thousand separators
- Handle errors gracefully if SERVICE_COUNT command fails

The total stitch count is now visible in the Machine Connection section,
providing users with insight into their machine's lifetime usage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik 2025-12-06 23:33:10 +01:00
parent c842334efc
commit 18e7b5afd3
3 changed files with 37 additions and 0 deletions

View file

@ -145,6 +145,14 @@ export function MachineConnection({
{(machineInfo.maxWidth / 10).toFixed(1)} × {(machineInfo.maxHeight / 10).toFixed(1)} mm {(machineInfo.maxWidth / 10).toFixed(1)} × {(machineInfo.maxHeight / 10).toFixed(1)} mm
</span> </span>
</div> </div>
{machineInfo.totalCount !== undefined && (
<div className="flex justify-between text-sm">
<span className="font-medium text-gray-600 dark:text-gray-400">Total Stitches:</span>
<span className="font-semibold text-gray-900 dark:text-gray-100">
{machineInfo.totalCount.toLocaleString()}
</span>
</div>
)}
</div> </div>
)} )}
</div> </div>

View file

@ -252,6 +252,17 @@ export class BrotherPP1Service {
.join(":") .join(":")
.toUpperCase(); .toUpperCase();
// Fetch service count data (cumulative statistics)
let serviceCount: number | undefined;
let totalCount: number | undefined;
try {
const serviceData = await this.getServiceCount();
serviceCount = serviceData.serviceCount;
totalCount = serviceData.totalCount;
} catch (err) {
console.warn('[BrotherPP1] Failed to fetch service count:', err);
}
return { return {
serialNumber, serialNumber,
modelNumber: modelCode, modelNumber: modelCode,
@ -260,6 +271,22 @@ export class BrotherPP1Service {
maxWidth, maxWidth,
maxHeight, maxHeight,
macAddress, macAddress,
serviceCount,
totalCount,
};
}
async getServiceCount(): Promise<{ serviceCount: number; totalCount: number }> {
const response = await this.sendCommand(Commands.SERVICE_COUNT);
const data = response.slice(2);
// Read uint32 values in little-endian format
const readUInt32LE = (offset: number) =>
data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24);
return {
serviceCount: readUInt32LE(0), // Bytes 0-3
totalCount: readUInt32LE(4), // Bytes 4-7
}; };
} }

View file

@ -56,6 +56,8 @@ export interface MachineInfo {
maxWidth: number; // in 0.1mm units maxWidth: number; // in 0.1mm units
maxHeight: number; // in 0.1mm units maxHeight: number; // in 0.1mm units
macAddress: string; macAddress: string;
serviceCount?: number; // Cumulative service counter
totalCount?: number; // Total stitches sewn by machine
} }
export interface PatternInfo { export interface PatternInfo {