Skip to content

gofynd/fynd-kio-sdk

Repository files navigation

Fynd Kio SDK

An Android SDK for integrating and managing hardware peripherals (printers, scanners, and LED devices) for Fynd Kio kiosk systems. This SDK provides a unified interface for communication with USB and serial-connected hardware devices commonly used in retail and self-checkout applications.

Overview

The Fynd Kio SDK simplifies hardware integration by providing:

  • Printer Management: Support for thermal receipt printers via USB
  • Scanner Integration: Barcode/QR code scanning via serial port
  • LED Control: RGB LED indicator control via serial communication
  • USB Device Management: Automatic device detection, permission handling, and connection management
  • Event-Driven Architecture: Callback-based event handling for device states and operations

Features

  • ✅ Unified hardware management through KioHardwareManager
  • ✅ USB device automatic detection and permission handling
  • ✅ Support for Fynd thermal printers (CSN Printer SDK)
  • ✅ RT Scanner integration for barcode scanning
  • ✅ RGB LED control for visual feedback
  • ✅ Extensible adapter pattern for adding custom hardware
  • ✅ Lifecycle-aware initialization and cleanup
  • ✅ Comprehensive error handling and event callbacks

Requirements

  • Minimum SDK: Android 24 (Android 7.0)
  • Compile SDK: Android 35
  • Kotlin: 1.9.0+
  • Java: 11

Installation

1. Add the SDK to Your Project

Option A: As a Module (Recommended for Development)

Clone the repository and include the SDK module in your project:

// settings.gradle.kts
include(":kiosdk")

Add the dependency in your app's build.gradle.kts:

dependencies {
    implementation(project(":kiosdk"))
}

2. Configure Repositories

Ensure your settings.gradle.kts includes the required repositories:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://zebratech.jfrog.io/artifactory/EMDK-Android/") }
        maven { url = uri("https://jitpack.io") }
    }
}

3. Add Required Permissions

Add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-feature android:name="android.hardware.usb.host" />

Quick Start

Basic Setup

import com.fynd.kiosdk.hardware.KioHardwareManager
import com.fynd.kiosdk.core.printer.PrinterEvent
import com.fynd.kiosdk.core.scanner.ScannerEvent
import com.fynd.kiosdk.core.led.LEDEvent
import com.fynd.kiosdk.core.led.DeviceLight

class MainActivity : ComponentActivity() {
    private lateinit var kioHardwareManager: KioHardwareManager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Initialize the hardware manager
        kioHardwareManager = KioHardwareManager(
            context = this,
            onPrinterEvent = { event -> handlePrinterEvent(event) },
            onScannerEvent = { event -> handleScannerEvent(event) },
            onLedEvent = { event -> handleLedEvent(event) }
        )

        // Initialize hardware connections
        kioHardwareManager.init()
    }

    private fun handlePrinterEvent(event: PrinterEvent) {
        when (event) {
            PrinterEvent.DeviceConnected -> {
                // Printer connected successfully
            }
            PrinterEvent.DeviceDisconnected -> {
                // Printer disconnected
            }
            is PrinterEvent.Error -> {
                // Handle printer error
                Log.e("Printer", "Error: ${event.reason}", event.exception)
            }
            else -> {}
        }
    }

    private fun handleScannerEvent(event: ScannerEvent) {
        when (event) {
            is ScannerEvent.ScanData -> {
                // Handle scanned data
                val barcode = event.data
                Log.d("Scanner", "Scanned: $barcode")
            }
            ScannerEvent.DeviceConnected -> {
                // Scanner connected
            }
            is ScannerEvent.Error -> {
                // Handle scanner error
                Log.e("Scanner", "Error: ${event.reason}")
            }
            else -> {}
        }
    }

    private fun handleLedEvent(event: LEDEvent) {
        when (event) {
            LEDEvent.DeviceConnected -> {
                // LED device connected
            }
            is LEDEvent.Error -> {
                // Handle LED error
                Log.e("LED", "Error: ${event.reason}")
            }
            else -> {}
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        kioHardwareManager.close()
    }
}

Usage Examples

Printing a Receipt

import android.graphics.Bitmap

// Create or load your receipt bitmap
val receiptBitmap: Bitmap = createReceiptBitmap()

// Print the receipt
kioHardwareManager.print(receiptBitmap)

Controlling LED Indicators

// Turn on green light (success indicator)
kioHardwareManager.setLightColor(DeviceLight.Green)

// Turn on red light (error indicator)
kioHardwareManager.setLightColor(DeviceLight.Red)

// Turn off the light
kioHardwareManager.setLightColor(DeviceLight.Off)

Handling Scanner Data

Scanner data is automatically received through the onScannerEvent callback when a barcode is scanned. The RT Scanner operates continuously once initialized.

Architecture

Core Components

KioHardwareManager

The main entry point for hardware management. Handles:

  • Device initialization
  • USB device detection and permissions
  • Event routing to callbacks
  • Adapter management

Adapters

Hardware-specific implementations:

  • KioPrinterAdapter: Abstract base for printer implementations
  • KioScannerAdapter: Abstract base for scanner implementations
  • KioLEDAdapter: Abstract base for LED implementations
  • KioUsbAdapter: Interface for USB device adapters

Hardware Implementations

  • FyndPrinterAdapter: CSN thermal printer implementation
  • RTScannerSerialAdapter: RT scanner serial port implementation
  • FyndLedSerialAdapter: LED control via serial port

Events

Type-safe sealed interfaces for device events:

  • PrinterEvent: DeviceConnected, DeviceDisconnected, DeviceDetached, Error
  • ScannerEvent: DeviceConnected, DeviceDisconnected, DeviceDetached, Error, ScanData
  • LEDEvent: DeviceConnected, DeviceDisconnected, DeviceDetached, Error

USB Management

The SDK includes sophisticated USB device management:

  • KioUsbDeviceManager: Handles USB device lifecycle
  • UsbDevicePermissionService: Manages permission requests
  • UsbDeviceConnectionService: Handles device connections
  • UsbPermissionQueue: Queues and processes permission requests

Supported Hardware

Printers

  • CSN Thermal Printers
    • Vendor ID: 4070 (0xFE6)
    • Product ID: 33054 (0x811E)
    • Features: Thermal printing, beep, half-cut, cash drawer kick

Scanners

  • RT Scanner (Serial)
    • Port: /dev/ttyS9
    • Type: Serial barcode scanner
    • Supports ISO-8859-1 encoding

LED Devices

  • Fynd LED Controller (Serial)
    • Port: /dev/ttyS3
    • Baud Rate: 115200
    • Features: RGB color control

Extending the SDK

Adding a Custom Adapter

To add support for a new hardware device:

  1. Create an Adapter Class
class CustomPrinterAdapter(
    private val context: Context,
    override val onEvent: (PrinterEvent) -> Unit
) : KioPrinterAdapter(onEvent) {
    
    override fun canUseDevice(device: UsbDevice): Boolean {
        // Return true if this adapter can handle the device
        return device.vendorId == YOUR_VENDOR_ID && 
               device.productId == YOUR_PRODUCT_ID
    }
    
    override fun connect(device: UsbDevice) {
        // Implement connection logic
    }
    
    override fun disconnect() {
        // Implement disconnection logic
    }
    
    override fun print(bitmap: Bitmap) {
        // Implement printing logic
    }
}
  1. Register the Adapter
val customAdapter = CustomPrinterAdapter(context, onPrinterEvent)
kioHardwareManager.addAdapter(customAdapter)

Dependencies

The SDK uses the following libraries:

// USB Serial Communication
implementation("com.github.mik3y:usb-serial-for-android:3.9.0")

// Included AAR Libraries
- barcode-scanner-library-2.6.22.0.aar
- csn-printer-sdk-1.0.0.jar
- fynd-kiosk-hardware-jws-14.0.0.aar
- poslib-usb-1.0.11.aar
- rtscanner-1.0.0.aar
- scan-pro-1.0.0.jar
- scanner-sdk-2.2.2.aar

Sample App

A sample application is included in the app module demonstrating:

  • Basic SDK initialization
  • Event handling
  • UI integration with Jetpack Compose
  • Hardware lifecycle management

To run the sample:

./gradlew :app:installDebug

Building

Debug Build

./gradlew assembleDebug

Release Build

./gradlew assembleRelease

Troubleshooting

Printer Not Connecting

  • Verify USB permissions are granted
  • Check device vendor/product IDs match supported hardware
  • Ensure no other app is using the printer

Scanner Not Receiving Data

  • Verify serial port path (/dev/ttyS9) is correct
  • Check scanner is properly connected
  • Ensure barcode service is running

LED Not Responding

  • Verify serial port path (/dev/ttyS3) is correct
  • Check baud rate (115200) is supported
  • Ensure proper serial permissions

USB Permission Issues

  • USB permissions are requested automatically
  • Check AndroidManifest.xml includes USB permissions
  • Verify USB host feature is declared

Logging

The SDK uses a custom Logger utility for debugging. Enable logs by:

// In your Application class or MainActivity
Logger.setDebugMode(true)

Version History

  • 1.0.0 - Initial release
    • Printer support (CSN thermal printers)
    • Scanner support (RT serial scanners)
    • LED control (RGB serial LEDs)
    • USB device management
    • Event-driven architecture

License

This project is proprietary software developed for Fynd. All rights reserved.

Support

For issues, questions, or feature requests, please contact the Fynd development team.

Project Structure

fynd-kio-sdk/
├── app/                          # Sample application
│   └── src/main/
│       ├── java/com/fynd/fng/
│       │   └── MainActivity.kt   # Sample implementation
│       └── res/                  # App resources
├── kiosdk/                       # Main SDK module
│   ├── libs/                     # Third-party AAR/JAR files
│   └── src/main/kotlin/com/fynd/kiosdk/
│       ├── core/                 # Core SDK components
│       │   ├── led/             # LED abstractions
│       │   ├── printer/         # Printer abstractions
│       │   ├── scanner/         # Scanner abstractions
│       │   ├── usb/             # USB management
│       │   └── utils/           # Utility classes
│       └── hardware/            # Hardware implementations
│           ├── led/
│           │   └── fynd/        # Fynd LED adapter
│           ├── printer/
│           │   └── fynd/        # Fynd printer adapter
│           ├── scanner/
│           │   └── rt/          # RT scanner adapter
│           └── KioHardwareManager.kt
├── gradle/                       # Gradle configuration
├── build.gradle.kts             # Root build script
├── settings.gradle.kts          # Project settings
└── README.md                    # This file

Built with ❤️ by the Fynd Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages