Skip to content

Understand receipt printer feature#74

Open
dony0720 wants to merge 4 commits into
mainfrom
cursor/understand-receipt-printer-feature-f9c8
Open

Understand receipt printer feature#74
dony0720 wants to merge 4 commits into
mainfrom
cursor/understand-receipt-printer-feature-f9c8

Conversation

@dony0720
Copy link
Copy Markdown
Owner

작업내용

  • Sewoo SLK-TS100 USB 프린터 출력 기능의 미구현 부분을 완성했습니다.
  • types/printer.ts: 프린터 관련 모든 타입(영수증 데이터, 설정, 상태 등)을 정의하여 타입 안전성을 확보했습니다.
  • utils/SewooThermalPrinter.ts: Sewoo SLK-TS100 모델에 특화된 ESC/POS 기반 프린터 서비스 구현체를 작성했습니다.
  • utils/printerService.ts: 프린터 서비스 팩토리 함수와 유틸리티를 제공하여 의존성 역전 원칙(DIP)을 따랐습니다.
  • hooks/usePrinter.ts: 프린터 연결, 출력, 상태 관리 및 에러 처리를 담당하는 React 커스텀 훅을 구현했습니다.
  • app/(tabs)/history.tsx: usePrinter 훅을 연동하여 주문 영수증 및 현금 점검 영수증 출력 기능을 추가했습니다.
  • app.json: Android USB OTG 연결을 위한 권한 및 인텐트 필터 설정을 추가했습니다.
  • PRINTER_SETUP_GUIDE.md: Sewoo SLK-TS100 프린터 설정 및 사용에 대한 상세 가이드를 작성했습니다.

고민하거나 궁금한 부분

  • 현재 구현은 프린터 서비스의 로직과 ESC/POS 명령어 생성까지 완료되었으며, 실제 USB 통신 라이브러리 연동만 남은 상태입니다.
  • SewooThermalPrinter.tsrequestUSBPermission(), findPrinterDevice(), sendRawData() 메서드에 선택하신 USB 라이브러리(react-native-usb-serialport 등)를 활용한 실제 통신 로직을 구현해야 합니다.
  • 프린터의 정확한 Vendor ID와 Product ID를 확인하여 utils/printerService.tsDEFAULT_PRINTER_CONFIGSewooThermalPrinter.ts 생성자에 업데이트가 필요합니다.
  • Expo Managed Workflow에서 USB 라이브러리 사용을 위해 expo-dev-client를 통한 개발 빌드 또는 EAS Build 설정이 필요합니다.

캡처 또는 영상 (optional)


Open in Cursor Open in Web

Co-authored-by: wndtjr720 <wndtjr720@gmail.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Sep 30, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 3 commits September 30, 2025 08:01
Co-authored-by: wndtjr720 <wndtjr720@gmail.com>
Co-authored-by: wndtjr720 <wndtjr720@gmail.com>
Co-authored-by: wndtjr720 <wndtjr720@gmail.com>
@dony0720 dony0720 marked this pull request as ready for review May 16, 2026 04:35
@dony0720
Copy link
Copy Markdown
Owner Author

@codex 코드 리뷰해줘

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ccf29715b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter data-generated="true">
<action android:name="android.intent.action.android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use the correct USB attach intent action

The USB attach intent action string is malformed here (android.intent.action.android.hardware.usb.action.USB_DEVICE_ATTACHED), so Android will not match real USB attach broadcasts. As a result, the app cannot be notified when the printer is plugged in, breaking the intended USB auto-detection flow on device.

Useful? React with 👍 / 👎.

Comment on lines +423 to +425
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.USB_PERMISSION || 'android.permission.USB_PERMISSION',
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove invalid runtime USB permission request

This requests USB_PERMISSION through PermissionsAndroid, but USB host access is not granted via Android runtime permissions, so this check can fail even when a USB printer is connected. Because connect() returns immediately on this false result, printer connection is blocked before device discovery and serial open are attempted.

Useful? React with 👍 / 👎.

Comment thread hooks/usePrinter.ts
});

// 프린터 서비스 인스턴스 (싱글톤 패턴)
const [printerService] = useState<PrinterService>(() => createPrinterService());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Share printer connection state across screens

usePrinter() creates a new PrinterService instance per hook call, so connection state is isolated per screen. In practice, connecting from the printer test page does not carry over to History, and History's print actions are gated on isPrinterConnected, causing receipt printing to be rejected as disconnected in that screen.

Useful? React with 👍 / 👎.

Comment on lines +491 to +494
// 프린터가 특정되지 않으면 첫 번째 기기 사용 (테스트용)
if (deviceList.length > 0) {
console.log('Sewoo 프린터를 찾지 못했습니다. 첫 번째 기기를 사용합니다:', deviceList[0]);
return deviceList[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject non-matching USB devices instead of defaulting to first

When no Sewoo match is found, this code falls back to deviceList[0], which can connect to an unrelated USB peripheral (for example, a scanner or another serial device) and then send ESC/POS bytes to it. That creates false-positive “connected” states and can break printing or interfere with other attached hardware whenever multiple USB devices are present.

Useful? React with 👍 / 👎.

Comment on lines +26 to +28
<intent-filter data-generated="true">
<action android:name="android.intent.action.android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add required USB device-filter metadata to activity

For USB_DEVICE_ATTACHED discovery, Android expects an <intent-filter> and matching <meta-data> pair that points to an XML device filter; declaring only the intent filter prevents the system from matching target devices and granting attach-time access flow. As written, USB attach auto-launch/auto-detect behavior will not work even after fixing the action string.

Useful? React with 👍 / 👎.

Comment thread app/(tabs)/history.tsx
Comment on lines +220 to +223
name: item.menuItem.name,
quantity: item.quantity,
unitPrice: item.menuItem.price,
totalPrice: item.menuItem.price * item.quantity,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute receipt item totals from actual charged prices

The receipt conversion sets each item's totalPrice to menuItem.price * quantity, which ignores option surcharges, temperature surcharge logic, and discount rules used by the checkout calculator. For discounted/customized orders, printed line totals will not match what was actually charged, producing inaccurate receipts and inconsistent totals.

Useful? React with 👍 / 👎.

Comment on lines +9 to +16
<resources>
<!-- Sewoo SLK-TS100 프린터 디바이스 필터 -->
<usb-device
vendor-id="6656"
product-id="1"
class="7"
subclass="1"
protocol="2" />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Package USB filter XML from Android resources

This device filter file is placed at repo root instead of android/app/src/main/res/xml, so it is not packaged as an Android XML resource and cannot be used by the manifest @xml/... USB attach flow. Even if intent metadata is added later, this file location prevents the filter from taking effect.

Useful? React with 👍 / 👎.

Comment thread app/(tabs)/history.tsx
Comment on lines +225 to +228
discount: item.discount ? {
name: item.discount.name,
amount: item.discount.value,
} : undefined,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve discount type when mapping receipt line discounts

Order discounts can be percentage-based or fixed-amount, but this mapping stores only value as a currency amount. Downstream receipt rendering formats that value as , so percentage discounts are printed as if they were fixed won discounts, yielding incorrect discount details on printed receipts.

Useful? React with 👍 / 👎.

Comment thread app/(tabs)/history.tsx
Comment on lines +232 to +234
subtotal: transaction.totalAmount,
discountAmount: 0, // TODO: 할인 금액 계산
finalAmount: transaction.totalAmount,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Calculate receipt summary discount instead of hardcoding zero

The receipt summary always sets discountAmount to 0 and subtotal equal to totalAmount, so any order with discounts will print a summary that claims no discount was applied. This creates accounting-visible mismatches between payment totals and printed receipt breakdowns.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants