windsor-bot 0.2.11 → 0.2.12

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.
@@ -3,6 +3,7 @@ import { SerialPort } from 'serialport';
3
3
  import { Jimp, ResizeStrategy } from 'jimp';
4
4
  const COLS_NORMAL = 48;
5
5
  const COLS_DOUBLE = 24;
6
+ const PRINTER_INIT = '\x1B@\x1Bt\x02\x1BM\x00\x1DL\x00\x00\x1DW\x00\x02';
6
7
  function wrapText(text, width) {
7
8
  const words = text.split(' ');
8
9
  const lines = [];
@@ -24,8 +25,6 @@ function wrapText(text, width) {
24
25
  return lines.length > 0 ? lines : [''];
25
26
  }
26
27
  function chooseFontForLines(totalLines) {
27
- // Keep short messages large without relying on the printer's
28
- // double-width glyph capacity, which varies by model and font.
29
28
  if (totalLines <= 8) {
30
29
  return { fontSize: 'tall', cols: COLS_NORMAL };
31
30
  }
@@ -39,6 +38,8 @@ function countLayoutLines(lines) {
39
38
  export async function buildEscpBuffer(job) {
40
39
  const conn = new InMemory();
41
40
  const printer = await Printer.CONNECT('TM-T20', conn);
41
+ // Reset state that may persist between direct USB/serial jobs.
42
+ await conn.write(Buffer.from(PRINTER_INIT, 'ascii'));
42
43
  const { fontSize, cols } = chooseFontForLines(countLayoutLines(job.lines));
43
44
  // Header
44
45
  if (job.header) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windsor-bot",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Self-hosted Discord bot automation for household list and todo printing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",