Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ハードウェア対応のリアル.pdf

たまねぎ
May 16, 2023
66

 ハードウェア対応のリアル.pdf

たまねぎ

May 16, 2023
Tweet

Transcript

  1. ϝΠϯػͱ͸ผͷೖग़ྗ୺຤ͱ࿈ܞ͢ΔରԠ ܾࡁ୺຤ υϩΞʔ όʔίʔυεΩϟφʔ ΧελϚʔσΟεϓϨΠ #FBDPO ϚΠΫ εϐʔΧʔ ϖϯγϧ Ϛ΢ε

    ΩʔϘʔυ ΠϠϗϯ ೖྗ ग़ྗ ϓϦϯλʔ εϚʔτϑΥϯ୯ମͰ͸ ղܾͰ͖ͳ͍՝୊ʹϦʔνͰ͖Δ
  2. ར༻͍ͯ͠Δٕज़ ୺຤ ར༻ٕज़ ܾࡁ୺຤ #MVFUPPUI ϓϦϯλʔ υϩΞʔ #MVFUPPUI όʔίʔυεΩϟφʔ #MVFUPPUI

    ΧελϚʔσΟεϓϨΠ 
 ʢεϚʔτϑΥϯʣ -PDBM/FUXPSL ղܾͰ͖Δ՝୊΋େ͖͍͕ɺ։ൃɾӡ༻ͷίετ΋େ͖͍
  3. ࣮૷ϋʔυϧ͕ߴ͍ w ୺຤ͱͷ࿈ܞ෦෼Ͱ 
 ௿ϨΠϠʔͳ࣮૷͕ඞཁ w ઀ଓ؅ཧɾ௨৴ॲཧͰͷ 
 ࡉ͔͍έΞ͕େม w

    ඇಉظॲཧ͕ଟ͘ɺ 
 ॲཧͷྲྀΕ͕௫ΈͮΒ͍ uint8_t *pos_papercut(cy_printer const printer, size_t *out_len) { if(printer & cy_paper_cut) { INIT_BUF(); size_t nl_len; uint8_t * const newlines = pos_cutter_newlines(printer, &nl_len); if(nl_len > 0) APPEND_BUF(newlines, nl_len); if(CY_PRINTER_TYPE(printer) == cy_sm_desktop_printer) APPEND_BUF_AUTO(POS_LM_CUTPAPER); else APPEND_BUF_AUTO(POS2_CUTPAPER); if(out_len) *out_len = BUF_LEN(); return BUF(); } else return pos_cutter_newlines(printer, out_len); } $ݴޠʹΑΔ࣮૷ίʔυ
  4. detectPaperWidth { guard $0 != PaperWidth.unknown else { // Ϩγʔτ෯ͷऔಘʹࣦഊͨ͠৔߹ɺ1౓͚ͩϦτϥΠ͢Δ

    _ = detectPaperWidth { update(paperWidth: $0) } return } update(paperWidth: $0) } var paperWidth = await paperWidthDetector.getWidth() if paperWidth == .unknown { // Ϩγʔτ෯ͷऔಘʹࣦഊͨ͠৔߹ɺ1౓͚ͩϦτϥΠ͢Δ paperWidth = await paperWidthDetector.getWidth() } update(paperWidth: paperWidth) ωετ͕গͳ͘ɺॲཧͷྲྀΕ͕௫Έ΍͘͢ͳͬͨ $PNQMFUJPO)BOEMFS%FMFHBUF 4XJGU$PODVSSFODZ ˞ཁ఺ΛߜΔͨΊσϑΥϧϝͯ͠·͢ XJUI$IFDLFE$POUJOVBUJPOͰɺ 
 ڧ੍తʹ4XJGU$PODVSSFODZͷܗ΁
  5. func getWidth() async -> PaperWidth { await withCheckedContinuation { (continuation:

    CheckedContinuation<PaperWidth, Never>) in session.listen { inputStream, _ in var input: UInt8 = 0 let inputLength = inputStream.read(&input, maxLength: 4096) if inputLength > 0 { let paperWidth = getPaperWidth( printerModel: printerModel, fromResponseValue: Data(bytes: &input, count: inputLength).ex.toBytes() ) continuation.resume(returning: paperWidth) } } session.write(Data(bytes: cmd, count: cmdLength)) } } ֎͔Βݟͨ࣌͸BTZODBXBJUͷγϯϓϧͳ*' $PNQMFUJPO)BOEMFSϕʔεͷ۪௚ͳ࣮૷͸ ด͡ࠐΊͯந৅Խ͢Δ
  6. let print = { printReceiptML(receiptML) _ = cutPaper() completion() }

    let supportedVariableWidth = (printerType & cy_variable_paper_width) != 0 if supportedVariableWidth { let continuePrint = { (width: PrinterWidth) in paperWidth = width print() } detectPaperWidth { guard $0 != PrinterWidth.unknown else { _ = detectPaperWidth { continuePrint($0) } return } continuePrint($0) } } else { print() } guard let activePrinter, let receipt = PaymentReceipt(order: order, store: store)?.build(), let image = try? await receipt.image( width: CGFloat(await activePrinter.receiptWidth()) ) else { return } activePrinter.printReceiptImage(image) ϨΨγʔͳ෦෼ΛϞμϯͳٕज़Ͱϥοϓ ҹ࡮໋ྩΛߦ͏ؔ਺ͷαϯϓϧ ॲཧͷྲྀΕ͕௥͍΍͘͢ͳΓɺίʔυͷ࡟ݮ΋Ͱ͖ͨ