Working tree changes 2024-08-18 01:00
All checks were successful
Test project build / Build (push) Successful in 1m14s
All checks were successful
Test project build / Build (push) Successful in 1m14s
This commit is contained in:
parent
4a4bc2184e
commit
7fbc01222d
@ -60,6 +60,63 @@
|
||||
localStorage.setItem("saved_canvas_props", JSON.stringify(labelProps));
|
||||
};
|
||||
|
||||
const onExportClicked = () => {
|
||||
const json: string = JSON.stringify({
|
||||
canvas: fabricCanvas.toJSON(),
|
||||
label: labelProps,
|
||||
});
|
||||
const link = document.createElement("a");
|
||||
const file: Blob = new Blob([json], { type: "text/json" });
|
||||
link.href = URL.createObjectURL(file);
|
||||
link.download = "canvas.json";
|
||||
link.click();
|
||||
URL.revokeObjectURL(link.href);
|
||||
};
|
||||
|
||||
const onImportClicked = () => {
|
||||
const input: HTMLInputElement = document.createElement("input");
|
||||
const reader = new FileReader();
|
||||
|
||||
input.type = "file";
|
||||
|
||||
input.onchange = (e: Event) => {
|
||||
let target = e.target as HTMLInputElement;
|
||||
if (target.files !== null) {
|
||||
let file: File = target.files[0];
|
||||
|
||||
if (file.type === "application/json") {
|
||||
reader.readAsText(file, "UTF-8");
|
||||
reader.onload = (readerEvt: ProgressEvent<FileReader>) => {
|
||||
if (readerEvt?.target?.result) {
|
||||
const json = readerEvt.target.result as string;
|
||||
const data = JSON.parse(json);
|
||||
|
||||
// todo: validation and merge with onLoadClicked
|
||||
labelProps = data.label;
|
||||
onUpdateLabelProps();
|
||||
|
||||
fabricCanvas.loadFromJSON(
|
||||
data.canvas,
|
||||
() => {
|
||||
fabricCanvas.requestRenderAll();
|
||||
},
|
||||
(src: object, obj: fabric.Object, error: any) => {
|
||||
obj.set({ snapAngle: 10 });
|
||||
// console.log(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
reader.onerror = (readerEvt: ProgressEvent<FileReader>) => {
|
||||
console.error(readerEvt);
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
input.click();
|
||||
};
|
||||
|
||||
const onLoadClicked = () => {
|
||||
const props = localStorage.getItem("saved_canvas_props");
|
||||
if (props) {
|
||||
@ -124,7 +181,12 @@
|
||||
if (savedLabelPropsStr != null) {
|
||||
try {
|
||||
const obj = JSON.parse(savedLabelPropsStr);
|
||||
if ("size" in obj && "width" in obj.size && "height" in obj.size && ["top", "left"].includes(obj.printDirection)) {
|
||||
if (
|
||||
"size" in obj &&
|
||||
"width" in obj.size &&
|
||||
"height" in obj.size &&
|
||||
["top", "left"].includes(obj.printDirection)
|
||||
) {
|
||||
labelProps = obj as LabelProps;
|
||||
}
|
||||
} catch (e) {
|
||||
@ -198,8 +260,22 @@
|
||||
<div class="toolbar d-flex flex-wrap gap-1 justify-content-center align-items-center">
|
||||
<LabelPropsEditor {labelProps} onChange={onUpdateLabelProps} />
|
||||
|
||||
<button class="btn btn-secondary btn-sm" on:click={onSaveClicked}><FaIcon icon="floppy-disk" /></button>
|
||||
<button class="btn btn-secondary btn-sm" on:click={onLoadClicked}><FaIcon icon="folder-open" /></button>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<button class="btn btn-secondary btn-sm" on:click={onSaveClicked}><FaIcon icon="floppy-disk" /></button>
|
||||
|
||||
<button class="btn btn-secondary dropdown-toggle px-1" data-bs-toggle="dropdown"> </button>
|
||||
<div class="dropdown-menu px-2">
|
||||
<button class="btn btn-secondary btn-sm" on:click={onExportClicked}>Export JSON</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<button class="btn btn-secondary btn-sm" on:click={onLoadClicked}><FaIcon icon="folder-open" /></button>
|
||||
<button class="btn btn-secondary dropdown-toggle px-1" data-bs-toggle="dropdown"> </button>
|
||||
<div class="dropdown-menu px-2">
|
||||
<button class="btn btn-secondary btn-sm" on:click={onImportClicked}>Import JSON</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<IconPicker onSubmit={onIconPicked} />
|
||||
<ObjectPicker onSubmit={onObjectPicked} />
|
||||
|
@ -4,6 +4,7 @@
|
||||
@import "bootstrap/scss/containers";
|
||||
@import "bootstrap/scss/grid";
|
||||
@import "bootstrap/scss/buttons";
|
||||
@import "bootstrap/scss/button-group";
|
||||
@import "bootstrap/scss/forms";
|
||||
@import "bootstrap/scss/dropdown";
|
||||
@import "bootstrap/scss/modal";
|
||||
|
@ -155,5 +155,7 @@ export class NiimbotBluetoothClient extends NiimbotAbstractClient {
|
||||
} else {
|
||||
await this.mutex.runExclusive(send);
|
||||
}
|
||||
|
||||
await Utils.sleep(2);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
ResponseCommandId,
|
||||
SoundSettingsItemType,
|
||||
SoundSettingsType,
|
||||
ProtocolVersion
|
||||
ProtocolVersion,
|
||||
} from ".";
|
||||
import { EncodedImage, ImageEncoder, ImageRow as ImagePart } from "../image_encoder";
|
||||
import { Utils } from "../utils";
|
||||
@ -73,7 +73,6 @@ export class PacketGenerator {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static getSoundSettings(soundType: SoundSettingsItemType): NiimbotPacket {
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.SoundSettings,
|
||||
@ -96,16 +95,19 @@ export class PacketGenerator {
|
||||
}
|
||||
|
||||
public static setDensity(value: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetDensity, [value]);
|
||||
return new NiimbotPacket(RequestCommandId.SetDensity, [value], [ResponseCommandId.In_SetDensity]);
|
||||
}
|
||||
|
||||
public static setLabelType(value: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetLabelType, [value]);
|
||||
return new NiimbotPacket(RequestCommandId.SetLabelType, [value], [ResponseCommandId.In_SetLabelType]);
|
||||
}
|
||||
|
||||
|
||||
public static setPageSizeV1(rows: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetPageSize, [...Utils.u16ToBytes(rows)]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.SetPageSize,
|
||||
[...Utils.u16ToBytes(rows)],
|
||||
[ResponseCommandId.In_SetPageSize]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,7 +119,11 @@ export class PacketGenerator {
|
||||
* @param cols Width in pixels
|
||||
*/
|
||||
public static setPageSizeV2(rows: number, cols: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetPageSize, [...Utils.u16ToBytes(rows), ...Utils.u16ToBytes(cols)]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.SetPageSize,
|
||||
[...Utils.u16ToBytes(rows), ...Utils.u16ToBytes(cols)],
|
||||
[ResponseCommandId.In_SetPageSize]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,20 +132,24 @@ export class PacketGenerator {
|
||||
* @param copiesCount Page instances
|
||||
*/
|
||||
public static setPageSizeV3(rows: number, cols: number, copiesCount: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetPageSize, [
|
||||
...Utils.u16ToBytes(rows),
|
||||
...Utils.u16ToBytes(cols),
|
||||
...Utils.u16ToBytes(copiesCount),
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.SetPageSize,
|
||||
[...Utils.u16ToBytes(rows), ...Utils.u16ToBytes(cols), ...Utils.u16ToBytes(copiesCount)],
|
||||
[ResponseCommandId.In_SetPageSize]
|
||||
);
|
||||
}
|
||||
|
||||
public static setPageSizeV5(rows: number, cols: number, copiesCount: number, someSize: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.SetPageSize, [
|
||||
...Utils.u16ToBytes(rows),
|
||||
...Utils.u16ToBytes(cols),
|
||||
...Utils.u16ToBytes(copiesCount),
|
||||
...Utils.u16ToBytes(someSize),
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.SetPageSize,
|
||||
[
|
||||
...Utils.u16ToBytes(rows),
|
||||
...Utils.u16ToBytes(cols),
|
||||
...Utils.u16ToBytes(copiesCount),
|
||||
...Utils.u16ToBytes(someSize),
|
||||
],
|
||||
[ResponseCommandId.In_SetPageSize]
|
||||
);
|
||||
}
|
||||
|
||||
public static setPrintQuantity(quantity: number): NiimbotPacket {
|
||||
@ -148,15 +158,14 @@ export class PacketGenerator {
|
||||
}
|
||||
|
||||
public static printStatus(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintStatus, [1], [
|
||||
ResponseCommandId.In_PrintStatus,
|
||||
ResponseCommandId.In_PrintError
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.PrintStatus,
|
||||
[1],
|
||||
[ResponseCommandId.In_PrintStatus, ResponseCommandId.In_PrintError]
|
||||
);
|
||||
}
|
||||
public static printerReset(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrinterReset, [1], [
|
||||
ResponseCommandId.In_PrinterReset,
|
||||
]);
|
||||
return new NiimbotPacket(RequestCommandId.PrinterReset, [1], [ResponseCommandId.In_PrinterReset]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,15 +174,15 @@ export class PacketGenerator {
|
||||
* D110 behavior: ordinary.
|
||||
* */
|
||||
public static printStart(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintStart, [1]);
|
||||
return new NiimbotPacket(RequestCommandId.PrintStart, [1], [ResponseCommandId.In_PrintStart]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static printStartV3(totalPages: number): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintStart, [
|
||||
...Utils.u16ToBytes(totalPages)
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.PrintStart,
|
||||
[...Utils.u16ToBytes(totalPages)],
|
||||
[ResponseCommandId.In_PrintStart]
|
||||
);
|
||||
}
|
||||
|
||||
// 5555 01 07 -- 00 01 00 00 00 00 00 -- 07aaaa
|
||||
@ -186,36 +195,29 @@ export class PacketGenerator {
|
||||
* @param totalPages Declare how many pages will be printed
|
||||
*/
|
||||
public static printStartV4(totalPages: number, pageColor: number = 0): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintStart, [
|
||||
...Utils.u16ToBytes(totalPages),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
pageColor
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.PrintStart,
|
||||
[...Utils.u16ToBytes(totalPages), 0x00, 0x00, 0x00, 0x00, pageColor],
|
||||
[ResponseCommandId.In_PrintStart]
|
||||
);
|
||||
}
|
||||
|
||||
public static printStartV5(totalPages: number, pageColor: number = 0, quality: number = 0): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintStart, [
|
||||
...Utils.u16ToBytes(totalPages),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
pageColor,
|
||||
quality
|
||||
]);
|
||||
return new NiimbotPacket(
|
||||
RequestCommandId.PrintStart,
|
||||
[...Utils.u16ToBytes(totalPages), 0x00, 0x00, 0x00, 0x00, pageColor, quality],
|
||||
[ResponseCommandId.In_PrintStart]
|
||||
);
|
||||
}
|
||||
|
||||
public static printEnd(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PrintEnd, [1]);
|
||||
return new NiimbotPacket(RequestCommandId.PrintEnd, [1], [ResponseCommandId.In_PrintEnd]);
|
||||
}
|
||||
public static pageStart(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PageStart, [1]);
|
||||
return new NiimbotPacket(RequestCommandId.PageStart, [1], [ResponseCommandId.In_PageStart]);
|
||||
}
|
||||
public static pageEnd(): NiimbotPacket {
|
||||
return new NiimbotPacket(RequestCommandId.PageEnd, [1]);
|
||||
return new NiimbotPacket(RequestCommandId.PageEnd, [1], [ResponseCommandId.In_PageEnd]);
|
||||
}
|
||||
|
||||
public static printEmptySpace(pos: number, repeats: number): NiimbotPacket {
|
||||
|
Reference in New Issue
Block a user