//
//  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("sendData == \(data.count)")
        PTDispatcher.share().send(data)
        PTDispatcher.share().whenSendSuccess { (usedTime) in
            print("send data success == \(usedTime!)")
        }
        
        PTDispatcher.share().whenSendFailure {
            print("send data fail")
        }
        
        PTDispatcher.share().whenReadRSSI { (RSSI) in
            //            print("：\(RSSI!)")
        }
       
        
        PTDispatcher.share().whenReceiveData { (data: Data?) in
            
            //            AlertVC.show(message: "backData:\(data!)", target: self)
            
            if data! == Data.init(bytes: [0x45]) {
                print("open")
            }
        }
        
        
        
        
    }
    
    func regiserBluetoothStatus() {
        
        PTDispatcher.share().whenUnconnect { (usedTime) in
            AlertVC.show(message: "unconnected", target: self)
//            self.disconnectButton!.isEnabled = false
//            self.connectButton!.isEnabled = true
        }
        
        PTDispatcher.share().whenSendProgressUpdate { (progress: NSNumber?) in
            
            print("Send progress:\(progress!.floatValue * 100)")
        }
    }
}












