mirror of
https://github.com/MultiMote/niimblue
synced 2026-01-19 19:37:11 +03:00
Rename ProtocolVersion to PrintTaskVersion
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
type EncodedImage,
|
||||
ImageEncoder,
|
||||
LabelType,
|
||||
ProtocolVersion,
|
||||
PrintTaskVersion,
|
||||
type PrintProgressEvent,
|
||||
} from "@mmote/niimbluelib";
|
||||
import type { LabelProps, PostProcessType } from "../types";
|
||||
@@ -32,7 +32,7 @@
|
||||
let thresholdValue: number = 140;
|
||||
let imgData: ImageData;
|
||||
let imgContext: CanvasRenderingContext2D;
|
||||
let printTaskVersion: ProtocolVersion = ProtocolVersion.V3;
|
||||
let printTaskVersion: PrintTaskVersion = PrintTaskVersion.V3;
|
||||
let labelType: LabelType = LabelType.WithGaps;
|
||||
let statusTimer: NodeJS.Timeout | undefined = undefined;
|
||||
let error: string = "";
|
||||
@@ -44,7 +44,7 @@
|
||||
quantity?: number;
|
||||
density?: number;
|
||||
labelType?: LabelType;
|
||||
printTaskVersion?: ProtocolVersion;
|
||||
printTaskVersion?: PrintTaskVersion;
|
||||
};
|
||||
|
||||
const disconnected = derived(connectionState, ($connectionState) => $connectionState !== "connected");
|
||||
@@ -155,7 +155,7 @@
|
||||
});
|
||||
|
||||
if (taskVer !== undefined) {
|
||||
console.log(`Detected print task version: ${ProtocolVersion[taskVer]}`);
|
||||
console.log(`Detected print task version: ${PrintTaskVersion[taskVer]}`);
|
||||
printTaskVersion = taskVer;
|
||||
}
|
||||
|
||||
@@ -322,20 +322,20 @@
|
||||
bind:value={printTaskVersion}
|
||||
on:change={() => updateSavedProp("printTaskVersion", printTaskVersion)}
|
||||
>
|
||||
<option value={ProtocolVersion.V1} disabled
|
||||
>{#if taskVer === ProtocolVersion.V1}✔{/if} V1 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
<option value={PrintTaskVersion.V1} disabled
|
||||
>{#if taskVer === PrintTaskVersion.V1}✔{/if} V1 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
>
|
||||
<option value={ProtocolVersion.V2} disabled
|
||||
>{#if taskVer === ProtocolVersion.V2}✔{/if} V2 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
<option value={PrintTaskVersion.V2} disabled
|
||||
>{#if taskVer === PrintTaskVersion.V2}✔{/if} V2 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
>
|
||||
<option value={ProtocolVersion.V3}
|
||||
>{#if taskVer === ProtocolVersion.V3}✔{/if} V3 - D110</option
|
||||
<option value={PrintTaskVersion.V3}
|
||||
>{#if taskVer === PrintTaskVersion.V3}✔{/if} V3 - D110</option
|
||||
>
|
||||
<option value={ProtocolVersion.V4}
|
||||
>{#if taskVer === ProtocolVersion.V4}✔{/if} V4 - B1</option
|
||||
<option value={PrintTaskVersion.V4}
|
||||
>{#if taskVer === PrintTaskVersion.V4}✔{/if} V4 - B1</option
|
||||
>
|
||||
<option value={ProtocolVersion.V5} disabled
|
||||
>{#if taskVer === ProtocolVersion.V5}✔{/if} V5 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
<option value={PrintTaskVersion.V5} disabled
|
||||
>{#if taskVer === PrintTaskVersion.V5}✔{/if} V5 - {$tr("preview.not_implemented", "NOT IMPLEMENTED")}</option
|
||||
>
|
||||
</select>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
getPrintTaskVersion,
|
||||
LabelType,
|
||||
NiimbotPacket,
|
||||
ProtocolVersion,
|
||||
PrintTaskVersion,
|
||||
} from "../packets";
|
||||
import { TypedEventTarget } from "typescript-event-target";
|
||||
import { ClientEventMap, HeartbeatEvent, PacketSentEvent, PrinterInfoFetchedEvent } from "./events";
|
||||
@@ -128,7 +128,7 @@ export abstract class NiimbotAbstractClient extends TypedEventTarget<ClientEvent
|
||||
}
|
||||
|
||||
/** Determine print task version if any */
|
||||
public getPrintTaskVersion(): ProtocolVersion | undefined {
|
||||
public getPrintTaskVersion(): PrintTaskVersion | undefined {
|
||||
const meta = this.getModelMetadata();
|
||||
|
||||
if (meta === undefined) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
NiimbotAbstractClient,
|
||||
Utils,
|
||||
Validators,
|
||||
ProtocolVersion,
|
||||
PrintTaskVersion,
|
||||
PrintProgressEvent,
|
||||
} from "..";
|
||||
import { SequentialDataReader } from "./data_reader";
|
||||
@@ -289,13 +289,13 @@ export class Abstraction {
|
||||
}
|
||||
|
||||
public async print(
|
||||
protoVersion: ProtocolVersion,
|
||||
taskVersion: PrintTaskVersion,
|
||||
image: EncodedImage,
|
||||
options?: PrintOptions,
|
||||
timeout?: number
|
||||
): Promise<void> {
|
||||
this.setTimeout(timeout ?? 10_000);
|
||||
const packets: NiimbotPacket[] = PacketGenerator.generatePrintSequence(protoVersion, image, options);
|
||||
const packets: NiimbotPacket[] = PacketGenerator.generatePrintSequence(taskVersion, image, options);
|
||||
try {
|
||||
for (const element of packets) {
|
||||
await this.send(element);
|
||||
|
||||
@@ -145,7 +145,7 @@ export enum ConnectResult {
|
||||
FirmwareErrors = 90,
|
||||
}
|
||||
|
||||
export enum ProtocolVersion {
|
||||
export enum PrintTaskVersion {
|
||||
/** Used in D11 */
|
||||
V1 = 1,
|
||||
/** Used in B21, D110new */
|
||||
@@ -162,4 +162,4 @@ export * from "./packet";
|
||||
export * from "./packet_generator";
|
||||
export * from "./abstraction";
|
||||
export * from "./data_reader";
|
||||
export * from "./protocol_versions";
|
||||
export * from "./print_task_versions";
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ResponseCommandId,
|
||||
SoundSettingsItemType,
|
||||
SoundSettingsType,
|
||||
ProtocolVersion,
|
||||
PrintTaskVersion,
|
||||
} from ".";
|
||||
import { EncodedImage, ImageEncoder, ImageRow as ImagePart } from "../image_encoder";
|
||||
import { Utils } from "../utils";
|
||||
@@ -344,8 +344,6 @@ export class PacketGenerator {
|
||||
PageEnd 5555 e3 01 01 e3aaaa
|
||||
PrintStatus 5555 a3 01 01 a3aaaa (alot)
|
||||
PrintEnd 5555 f3 01 01 f3aaaa
|
||||
|
||||
|
||||
You should send PrintEnd manually after this sequence (after print finished)
|
||||
*/
|
||||
public static generatePrintSequenceV4(image: EncodedImage, options?: PrintOptions): NiimbotPacket[] {
|
||||
@@ -361,17 +359,17 @@ export class PacketGenerator {
|
||||
}
|
||||
|
||||
public static generatePrintSequence(
|
||||
protoVersion: ProtocolVersion,
|
||||
printTaskVersion: PrintTaskVersion,
|
||||
image: EncodedImage,
|
||||
options?: PrintOptions
|
||||
): NiimbotPacket[] {
|
||||
switch (protoVersion) {
|
||||
case ProtocolVersion.V3:
|
||||
switch (printTaskVersion) {
|
||||
case PrintTaskVersion.V3:
|
||||
return PacketGenerator.generatePrintSequenceV3(image, options);
|
||||
case ProtocolVersion.V4:
|
||||
case PrintTaskVersion.V4:
|
||||
return PacketGenerator.generatePrintSequenceV4(image, options);
|
||||
default:
|
||||
throw new Error(`PrintTaskVersion ${protoVersion} Not implemented`);
|
||||
throw new Error(`PrintTaskVersion ${printTaskVersion} Not implemented`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
niimbluelib/src/packets/print_task_versions.ts
Normal file
18
niimbluelib/src/packets/print_task_versions.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { PrintTaskVersion } from ".";
|
||||
import { PrinterModel as M } from "..";
|
||||
|
||||
export const getPrintTaskVersion = (model: M): PrintTaskVersion | undefined => {
|
||||
switch (model) {
|
||||
case M.D11:
|
||||
case M.D11_H:
|
||||
case M.D11S:
|
||||
return PrintTaskVersion.V1;
|
||||
case M.D110:
|
||||
case M.D110_M:
|
||||
return PrintTaskVersion.V3;
|
||||
case M.B1:
|
||||
return PrintTaskVersion.V4;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import { ProtocolVersion } from ".";
|
||||
import { PrinterModel as M } from "..";
|
||||
|
||||
export const getPrintTaskVersion = (model: M): ProtocolVersion | undefined => {
|
||||
switch (model) {
|
||||
case M.D11:
|
||||
case M.D11_H:
|
||||
case M.D11S:
|
||||
return ProtocolVersion.V1;
|
||||
case M.D110:
|
||||
case M.D110_M:
|
||||
return ProtocolVersion.V3;
|
||||
case M.B1:
|
||||
return ProtocolVersion.V4;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
Reference in New Issue
Block a user