//
//  PrinterPort.swift
//  iOSPrinterDemo
//
//  Created by mellow on 2017/4/19.
//  Copyright © 2017年 Mellow. All rights reserved.
//

import Foundation

public class PrinterPort: NSObject {
    
    class func send(Data data: Data) {
        
        print("data:\(data)")
        PTDispatcher.share().send(data)
        PTDispatcher.share().whenSendSuccess { (usedTime) in
            print("向打印机发送数据成功,用时:\(usedTime!)")
        }
        
        PTDispatcher.share().whenSendFailure {
            print("向打印机发送数据失败")
        }
        
        PTDispatcher.share().whenReadRSSI { (RSSI) in
            //            print("当前连接打印机信号强度：\(RSSI!)")
        }
        
        PTDispatcher.share().whenReceiveData { (data: Data?) in
            
//            AlertVC.show(message: "打印机返回数据:\(data!)", target: self)
            
            if data! == Data.init(bytes: [0x45]) {
                print("开盖")
            }
            print(data! as NSData)
        }
    }
    
    // 注册打印机状态
    func regiserBluetoothStatus() {
        
        PTDispatcher.share().whenUnconnect { (usedTime) in
            AlertVC.show(message: "和打印机断开连接", target: self)
//            self.disconnectButton!.isEnabled = false
//            self.connectButton!.isEnabled = true
        }
        
        PTDispatcher.share().whenSendProgressUpdate { (progress: NSNumber?) in
            
            print("发送进度:\(progress!.floatValue * 100)")
        }
    }
}
