@mmote/niimblue-node 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,10 +6,20 @@ Command line interface, simple REST server are also included.
6
6
 
7
7
  Tested with:
8
8
 
9
+ Windows:
10
+
9
11
  * Windows 10
10
12
  * Bluetooth adapter (TP-LINK UB500)
11
13
  * USB serial connection
12
- * Printers: B1, D110
14
+ * Printers: B1, D110, B21_C2B, B21_PRO
15
+
16
+ Mac:
17
+
18
+ * macOS 15.5
19
+ * Integrated Bluetooth adapter
20
+ * Printer: D110
21
+
22
+ [Protocol tested with these models (niimbluelib repo)](https://github.com/MultiMote/niimbluelib/issues/1).
13
23
 
14
24
  Usage example:
15
25
 
@@ -32,6 +42,11 @@ Windows requirements:
32
42
  - C++ build tools with `Windows SDK >=22000` must be installed
33
43
  * Python 3
34
44
 
45
+ Mac requirements:
46
+
47
+ * [Xcode](https://apps.apple.com/ca/app/xcode/id497799835)
48
+ * Permissions: Open "System Settings" → "Privacy & Security" → "Bluetooth" and then add your terminal to allowed applications.
49
+
35
50
  See [node-gyp](https://github.com/nodejs/node-gyp) and [noble](https://github.com/abandonware/noble) installation.
36
51
 
37
52
  ### Command-line usage
@@ -72,12 +87,26 @@ D110 BLE:
72
87
  niimblue-cli print -d -t ble -a 26:03:03:c3:f9:11 -p D110 -o left label_15x30.png
73
88
  ```
74
89
 
75
- B1 serial, long parameter names (will resize image to fit 50x30 label keeping aspect ration):
90
+ D110 BLE via name:
91
+
92
+ _Connecting via the Bluetooth device name instead of address is required on macOS. Find the device name with `niimblue-cli scan -t ble`._
93
+
94
+ ```bash
95
+ niimblue-cli print -d -t ble -a 'D110-XXXXXXXXXX' -p D110 -o left -w 192 -h 96 label_15x30.png
96
+ ```
97
+
98
+ B1 serial, long parameter names (will resize image to fit 50x30 label, keeping aspect ratio):
76
99
 
77
100
  ```bash
78
101
  niimblue-cli print --debug --transport serial --address COM8 --print-task B1 --print-direction top --label-width 384 --label-height 240 label_15x30.png
79
102
  ```
80
103
 
104
+ B21_PRO BLE, long parameter names (will resize image to fit 50x30 300dpi label, don't keep aspect ratio):
105
+
106
+ ```bash
107
+ niimblue-cli print --debug --transport ble --address c3:16:13:04:06:18 --print-task D110M_V4 --print-direction top --label-width 584 --label-height 354 --image-fit fill label_15x30.png
108
+ ```
109
+
81
110
  B1 firmware upgrade via serial:
82
111
 
83
112
  ```bash
@@ -98,4 +127,6 @@ Enable debug logging, set host and port, enable CORS:
98
127
  niimblue-cli server -d -h 0.0.0.0 -p 5000 --cors
99
128
  ```
100
129
 
101
- [Server API docs](https://multimote.github.io/niimblue-node/server/)
130
+ See [sharp docs](https://sharp.pixelplumbing.com/api-resize/) for image resize options.
131
+
132
+ [Server API docs](https://niimnode-docs.pages.dev/server/)
package/dist/cli/index.js CHANGED
@@ -17,7 +17,7 @@ extra_typings_1.program
17
17
  .description("Printer information")
18
18
  .requiredOption("-d, --debug", "Debug information", false)
19
19
  .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"]))
20
- .requiredOption("-a, --address <string>", "Device bluetooth address or serial port name/path")
20
+ .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path")
21
21
  .action(worker_1.cliPrinterInfo);
22
22
  extra_typings_1.program
23
23
  .command("scan")
@@ -31,7 +31,7 @@ extra_typings_1.program
31
31
  .argument("<path>", "PNG image path")
32
32
  .requiredOption("-d, --debug", "Debug information", false)
33
33
  .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"]))
34
- .requiredOption("-a, --address <string>", "Device bluetooth address or serial port name/path")
34
+ .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path")
35
35
  .addOption(new extra_typings_1.Option("-o, --print-direction <dir>", "Print direction").choices(["left", "top"]))
36
36
  .addOption(new extra_typings_1.Option("-p, --print-task <type>", "Print task").choices(niimbluelib_1.printTaskNames))
37
37
  .requiredOption("-l, --label-type <type number>", "Label type", intOption, 1)
@@ -46,7 +46,7 @@ extra_typings_1.program
46
46
  "fill",
47
47
  "inside",
48
48
  "outside",
49
- ]).default("contain"))
49
+ ]))
50
50
  .addOption(new extra_typings_1.Option("-m, --image-position <dir>", "Image position while resizing (label-width and label-height must be set)").choices([
51
51
  "left",
52
52
  "top",
@@ -57,7 +57,7 @@ extra_typings_1.program
57
57
  "bottom",
58
58
  "left bottom",
59
59
  "left top",
60
- ]).default("centre"))
60
+ ]))
61
61
  .action(worker_1.cliConnectAndPrintImageFile);
62
62
  extra_typings_1.program
63
63
  .command("server")
@@ -72,7 +72,7 @@ extra_typings_1.program
72
72
  .description("Flash firmware")
73
73
  .requiredOption("-d, --debug", "Debug information", false)
74
74
  .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"]))
75
- .requiredOption("-a, --address <string>", "Device bluetooth address or serial port name/path")
75
+ .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path")
76
76
  .requiredOption("-f, --file <path>", "Firmware path")
77
77
  .requiredOption("-n, --new-version <version>", "New firmware version")
78
78
  .action(worker_1.cliFlashFirmware);
@@ -31,8 +31,8 @@ export interface PrintOptions {
31
31
  threshold: number;
32
32
  labelWidth?: number;
33
33
  labelHeight?: number;
34
- imageFit: SharpImageFit;
35
- imagePosition: SharpImagePosition;
34
+ imageFit?: SharpImageFit;
35
+ imagePosition?: SharpImagePosition;
36
36
  debug: boolean;
37
37
  }
38
38
  export declare const cliConnectAndPrintImageFile: (path: string, options: PrintOptions & TransportOptions) => Promise<never>;
@@ -20,8 +20,8 @@ const cliConnectAndPrintImageFile = async (path, options) => {
20
20
  if (options.labelWidth !== undefined && options.labelHeight !== undefined) {
21
21
  image = image.resize(options.labelWidth, options.labelHeight, {
22
22
  kernel: sharp_1.default.kernel.nearest,
23
- fit: options.imageFit,
24
- position: options.imagePosition,
23
+ fit: options.imageFit ?? "contain",
24
+ position: options.imagePosition ?? "centre",
25
25
  background: "#fff",
26
26
  });
27
27
  }
@@ -8,7 +8,7 @@ export declare class NiimbotHeadlessBleClient extends NiimbotAbstractClient {
8
8
  private device;
9
9
  private channel;
10
10
  constructor();
11
- /** Set device mac address for connect */
11
+ /** Set device mac address or name for connect */
12
12
  setAddress(address: string): void;
13
13
  static waitAdapterReady(): Promise<void>;
14
14
  static scan(timeoutMs?: number): Promise<ScanItem[]>;
@@ -11,9 +11,9 @@ class NiimbotHeadlessBleClient extends niimbluelib_1.NiimbotAbstractClient {
11
11
  super();
12
12
  this.addr = "";
13
13
  }
14
- /** Set device mac address for connect */
14
+ /** Set device mac address or name for connect */
15
15
  setAddress(address) {
16
- this.addr = address.toLowerCase();
16
+ this.addr = address;
17
17
  }
18
18
  static async waitAdapterReady() {
19
19
  if (noble_1.default._state === "poweredOn") {
@@ -63,7 +63,8 @@ class NiimbotHeadlessBleClient extends niimbluelib_1.NiimbotAbstractClient {
63
63
  return new Promise((resolve, reject) => {
64
64
  let timer;
65
65
  noble_1.default.on("discover", async (peripheral) => {
66
- if (peripheral.address === address) {
66
+ if (peripheral.address === address.toLowerCase() ||
67
+ peripheral.advertisement.localName === address) {
67
68
  clearTimeout(timer);
68
69
  resolve(peripheral);
69
70
  }
@@ -115,7 +116,7 @@ class NiimbotHeadlessBleClient extends niimbluelib_1.NiimbotAbstractClient {
115
116
  async connect() {
116
117
  await this.disconnect();
117
118
  if (!this.addr) {
118
- throw new Error("Device address not set");
119
+ throw new Error("Device address or name not set");
119
120
  }
120
121
  await this.connectToDevice(this.addr);
121
122
  try {
@@ -15,7 +15,7 @@ export declare const connected: () => Promise<{
15
15
  export declare const info: () => Promise<{
16
16
  printerInfo: import("@mmote/niimbluelib").PrinterInfo;
17
17
  modelMetadata: import("@mmote/niimbluelib").PrinterModelMeta | undefined;
18
- detectedPrintTask: "D11_V1" | "D110" | "B1" | "B21_V1" | "V5" | undefined;
18
+ detectedPrintTask: "D11_V1" | "D110" | "B1" | "B21_V1" | "D110M_V4" | undefined;
19
19
  }>;
20
20
  export declare const print: (r: IncomingMessage) => Promise<{
21
21
  message: string;
package/dist/utils.js CHANGED
@@ -66,7 +66,7 @@ const printImage = async (client, printTaskName, encoded, options) => {
66
66
  catch (e) {
67
67
  console.error(e);
68
68
  }
69
- await client.abstraction.printEnd();
69
+ await printTask.printEnd();
70
70
  };
71
71
  exports.printImage = printImage;
72
72
  const loadImageFromBase64 = async (b64) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmote/niimblue-node",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Headless clients for niimbluelib. Command line interface, simple REST server are also included.",
5
5
  "keywords": [
6
6
  "command-line",
@@ -9,6 +9,7 @@
9
9
  "niimbot",
10
10
  "niimbot-d110",
11
11
  "niimbot-b1",
12
+ "niimbot-b21",
12
13
  "bluetooth",
13
14
  "serial"
14
15
  ],
@@ -39,11 +40,12 @@
39
40
  "dependencies": {
40
41
  "@abandonware/noble": "^1.9.2-26",
41
42
  "@commander-js/extra-typings": "^12.1.0",
42
- "@mmote/niimbluelib": "0.0.1-alpha.24",
43
+ "@mmote/niimbluelib": "0.0.1-alpha.29",
43
44
  "async-mutex": "^0.5.0",
44
45
  "commander": "^12.1.0",
45
46
  "serialport": "^12.0.0",
46
47
  "sharp": "^0.33.5",
47
48
  "zod": "^3.23.8"
48
- }
49
+ },
50
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
49
51
  }