gpR3.ts 1.06 KB
import { buildEscPosLabelData, buildEscPosTestPrintData } from '../protocols/escPosBuilder'
import type { PrinterCandidate, PrinterDriver } from '../types/printer'

const KEYWORDS = [
  'gp-r3',
  'gp r3',
  'gpr3',
]

function score (device: PrinterCandidate): number {
  const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase()
  let total = 0
  KEYWORDS.forEach((keyword) => {
    if (text.includes(keyword)) total += 60
  })
  if (text.includes('gprinter')) total += 10
  return total
}

export const gpR3Driver: PrinterDriver = {
  key: 'gp-r3',
  brand: 'Gprinter',
  model: 'GP-R3',
  displayName: 'Gprinter GP-R3',
  protocol: 'esc',
  preferredConnection: 'classic',
  preferredBleMtu: 20,
  imageMaxWidthDots: 384,
  imageDpi: 203,
  keywords: KEYWORDS,
  matches (device) {
    return score(device)
  },
  resolveConnectionType (device) {
    if (device.type === 'ble') return 'ble'
    return 'classic'
  },
  buildTestPrintData () {
    return buildEscPosTestPrintData()
  },
  buildLabelData (payload) {
    return buildEscPosLabelData(payload)
  },
}