// // SBTSetChargeVCtr.swift // SolarBT // // Created by weclouds on 2019/3/20. // Copyright © 2019 weclouds. All rights reserved. // import UIKit import SwiftPopup import IQKeyboardManagerSwift /* 1、 显示原来的 2、 电池类型切换 充电器数据变化 读取回来 ? 还是设置进去 isDemo? */ class SBTSetChargeVCtr: SwiftPopup { var isDemo :Bool? var peripheralName :String? var isOld: Bool? var MaxVoltage :String? //放大倍数 var Multiple : Float? // 默认为1倍 //IchageRage var IchageRage : String? //额定充电电流 //完成回调 var completehandle:(()->Void)? var difeffrentUIArr : [Int]? = [Int]() var CellBatteryType :BatteryType? = .USER{ didSet{ if isOld == true { if let batteryType = self.CellBatteryType { switch batteryType { case .USER: self.difeffrentUIArr = [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1] case .SLD: self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1] case .FLD: self.difeffrentUIArr = [1,1,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1] case .GEL: self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1] case .LI: self.difeffrentUIArr = [1,1,1,1, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1] } } }else{ if let batteryType = self.CellBatteryType { switch batteryType { case .USER: self.difeffrentUIArr = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] case .SLD: self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0] case .FLD: self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0] case .GEL: self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0] case .LI: self.difeffrentUIArr = [0,0,0,0, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,0] } } } } } var selectedIndexPath :IndexPath?{ didSet{ } } var dataSources:[String]? = [String](){ didSet{ } } var sb_SelectedArr : [Bool]? = [false,false,false,false,false,false,false,false,false,false,false, false,false,false,false,false,false,false,false,false,false,false] let cellid1 = "cellid1" let cellid2 = "cellid2" let cellid3 = "cellid3" var istemp : String? @IBOutlet weak var closeLabel: UILabel! @IBOutlet weak var chageLabel: UILabel! @IBOutlet weak var saveBtn: UIButton! @IBOutlet weak var cancelBtn: UIButton! var collectionView:UICollectionView? @IBOutlet weak var contentView: UIView! var cmdArr : [String]? = [String]() var canEdit : Bool = true var itemTitles = [String]() override func viewDidLoad() { super.viewDidLoad() let def = UserDefaults.standard istemp = def.value(forKey: TEMPISCENTIGRADE) as? String var Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)" var Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)" var Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)" var Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)" if istemp == "0"{ Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℉)" Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℉)" Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℉)" Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℉)" }else if istemp == "1"{ Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)" Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)" Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)" Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)" } itemTitles = ["Maximum_charge_current(A)".da_localizedStr(), "Charge_on/off".da_localizedStr(), Upper_limit_of_charge_temperature, Lower_limit_of_charge_temperature, "Overvoltage".da_localizedStr(), "Limited_charge_voltage".da_localizedStr(), "Boost_charge_voltage".da_localizedStr(), "Floating_charge_voltage".da_localizedStr(), "Boost_charge_return_voltage".da_localizedStr(), "Boost_charge_time".da_localizedStr(), "Temperature_compensation_coefficient".da_localizedStr(), "Equalizing_charge_voltage".da_localizedStr(), "Equalizing_charge_time".da_localizedStr(), "Equalizing_charge_interval".da_localizedStr(), "Manual_equalizing".da_localizedStr(), "Over_discharge_return_voltage".da_localizedStr(), "Undervoltage_warning_voltage".da_localizedStr(), "Over_discharge_voltage".da_localizedStr(), "Discharge_cutoff_voltage".da_localizedStr(), "Over_discharge_delay_time".da_localizedStr(), Upper_limit_of_discharge_temperature, Lower_limit_of_discharge_temperature] createUI() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) NotificationCenter.default.addObserver(self, selector: #selector(notifionCationSetBatteryType), name: NSNotification.Name(rawValue: kNotifionCationSetBatteryType), object: nil) } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) NotificationCenter.default.removeObserver(self) } override func viewDidLayoutSubviews() { super .viewDidLayoutSubviews() if let indexPath = self.selectedIndexPath { // log.debug("当前的IndexPath、\(indexPath)") self.collectionView?.scrollToItem(at: indexPath, at: .centeredVertically, animated: true) } } override func viewDidAppear(_ animated: Bool) { super .viewDidAppear(animated) if let indexPath = self.selectedIndexPath { // log.debug("当前的IndexPath、\(indexPath)") if indexPath.row == 1 { let cell = self.collectionView?.cellForItem(at: indexPath) as! SBTParamSetSwitch_Item cell.sb_selected = true }else if indexPath.row == 14{ let cell = self.collectionView?.cellForItem(at: indexPath) as! SBTParamSet_balance_Item cell.sb_becameFirstResonder() cell.sb_selected = true }else{ let cell = self.collectionView?.cellForItem(at: indexPath) as! SBTParamSet_Item cell.sb_selected = true cell.subTitleTextfield.becomeFirstResponder() } } } @IBAction func saveAction(_ sender: Any) { if self.cmdArr?.count != 0 { // setChargerParam(cmdArr!) if isDemo == false{ BabyBluetoothSwift.shareInstance()?.writeData2222(cmdArr, completionHandler: { (result) in self.completehandle!() g_showHUD("Successful".da_localizedStr()) }) }else{ g_showHUD("Current_demo_data".da_localizedStr()) } } log.debug(cmdArr!) dismiss() } @IBAction func cancelAction(_ sender: Any) { dismiss() } override func touchesBegan(_ touches: Set, with event: UIEvent?) { dismiss() } } extension SBTSetChargeVCtr{ //设置区别颜色 @objc func notifionCationSetBatteryType() { let batteryType = AppShare.batteryType self.CellBatteryType = batteryType self.collectionView?.reloadData() } func createUI() { self.chageLabel.text = "Charger_settings".da_localizedStr() self.closeLabel.text = "Retract".da_localizedStr() self.saveBtn.setTitle("Setup".da_localizedStr(), for: .normal) self.cancelBtn.setTitle("Cancel".da_localizedStr(), for: .normal) self.backViewColor = UIColor(white: 1, alpha: 0.84) let bgLayer1 = CAGradientLayer() bgLayer1.colors = [UIColor(red: 0.82, green: 0.82, blue: 0.82, alpha: 1).cgColor, UIColor(red: 0.74, green: 0.74, blue: 0.74, alpha: 1).cgColor] bgLayer1.locations = [0, 1] bgLayer1.frame = self.cancelBtn.bounds bgLayer1.startPoint = CGPoint(x: 0.09, y: 0.31) bgLayer1.endPoint = CGPoint(x: 0.83, y: 0.83) self.cancelBtn.layer.addSublayer(bgLayer1) // fillCode let bgLayer2 = CAGradientLayer() bgLayer2.colors = [UIColor(red: 1, green: 0.52, blue: 0.07, alpha: 1).cgColor, UIColor(red: 1, green: 0.67, blue: 0, alpha: 1).cgColor] bgLayer2.locations = [0, 1] bgLayer2.frame = self.saveBtn.bounds bgLayer2.startPoint = CGPoint(x: 1, y: 1) bgLayer2.endPoint = CGPoint(x: 0, y: 0) self.saveBtn.layer.addSublayer(bgLayer2) let layout = UICollectionViewFlowLayout() let itemWidth = (KSCREENWIDTH - 25 * 3 ) / 2 layout.itemSize = CGSize(width:itemWidth , height: 89) layout.minimumLineSpacing = 12.5 //列间距 layout.minimumInteritemSpacing = 10 //行间距 layout.scrollDirection = .vertical collectionView = UICollectionView(frame: CGRect(x: 25, y: 0, width: KSCREENWIDTH - 50, height: 110 * 4 ), collectionViewLayout: layout) collectionView?.backgroundColor = UIColor.white collectionView?.showsVerticalScrollIndicator = false collectionView?.showsHorizontalScrollIndicator = false // collectionView?.isScrollEnabled = false collectionView?.dataSource = self collectionView?.delegate = self collectionView?.bounces = false collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: cellid1) collectionView?.register(SBTParamSetSwitch_Item.self, forCellWithReuseIdentifier: cellid2) collectionView?.register(SBTParamSet_balance_Item.self, forCellWithReuseIdentifier: cellid3) for i in 0..<22 { if i != 1 { let identifier = "cellid_" + "\(i)" collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: identifier) } } self.contentView.addSubview(collectionView!) } } extension SBTSetChargeVCtr :UICollectionViewDelegate,UICollectionViewDataSource{ // 判断输入的字符串是否为数字,不含其它字符 func isPurnInt(string:String) -> Bool { let scan : Scanner = Scanner(string: string) var val : Int = 0 return scan.scanInt(&val) && scan.isAtEnd } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.dataSources!.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { // log.debug(difeffrentUIArr) if indexPath.row == 1 { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellid2, for: indexPath) as! SBTParamSetSwitch_Item cell.differenceUI = self.difeffrentUIArr![indexPath.row] cell.canEdit = canEdit cell.title = itemTitles[indexPath.row] cell.sb_selected = sb_SelectedArr![indexPath.row] let cmd = dataSources![indexPath.row] if cmd == "开" || cmd == "On"{ cell.isOn = true }else if cmd == "关" || cmd == "Off"{ cell.isOn = false } cell.backgroundColor = UIColor.white cell.switchCallback = {(isOn) in var switchStr = "" if isOn == true{ switchStr = "0001" }else{ switchStr = "0000" } let switchCMD = "FF06DF00" + switchStr self.cmdArr?.append(switchCMD) } return cell }else if indexPath.row == 14{ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellid3, for: indexPath) as! SBTParamSet_balance_Item cell.differenceUI = self.difeffrentUIArr![14] cell.title = itemTitles[indexPath.row] cell.sb_selected = sb_SelectedArr![indexPath.row] cell.canEdit = canEdit cell.subTitle = dataSources![indexPath.row] cell.backgroundColor = UIColor.white cell.balanceTypeCallback = {(balanceType) in //FF06E00B0087; if balanceType != -1{ var balance = "" if balanceType == 0{ balance = "0000" }else if balanceType == 1{ balance = "0001" } let balanceCMD = "FF06DF0D" + balance self.cmdArr?.append(balanceCMD) } } return cell } else{ let identifier = "cellid_" + "\(indexPath.row)" let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! SBTParamSet_Item cell.title = itemTitles[indexPath.row] cell.differenceUI = self.difeffrentUIArr![indexPath.row] cell.sb_selected = sb_SelectedArr![indexPath.row] cell.subTitle = dataSources![indexPath.row]; cell.canEdit = canEdit cell.backgroundColor = UIColor.white if indexPath.row == 0 { // 最大充电电流 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 2{ cell.itemKeyboardType = .numberPad }else if indexPath.row == 3{ cell.itemKeyboardType = .numbersAndPunctuation }else if indexPath.row == 4{ // 超压电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 5{ //充电限制电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 6{ // 提升充电电压 cell.itemKeyboardType = .decimalPad // cell.ChangeCharactersCallback = { (value) in // log.debug("返回的数据 --- \(value)") // // } }else if indexPath.row == 7{ // 浮充充电电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 8{ // 提升返回电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 9{ // 提升充电时间 cell.itemKeyboardType = .numberPad }else if indexPath.row == 10{ // 温度补偿系数 cell.itemKeyboardType = .numberPad }else if indexPath.row == 11{ // 均衡充电电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 12{ // 均衡充电时间 cell.itemKeyboardType = .numberPad } else if indexPath.row == 13{ // 均衡充电间隔 cell.itemKeyboardType = .numberPad }else if indexPath.row == 15{ // 过放返回电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 16{ // 欠压警告电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 17{ //过放电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 18{ //放电限制电压 cell.itemKeyboardType = .decimalPad }else if indexPath.row == 19{ //过放延时时间 cell.itemKeyboardType = .numberPad }else if indexPath.row == 20{ //放电上限温度 cell.itemKeyboardType = .numberPad }else if indexPath.row == 21{ //放电下限温度 cell.itemKeyboardType = .numbersAndPunctuation } cell.resultCallback = {(result,textfield) in // self.cmdArr?.removeAll() if indexPath.row == 0 {// 最大充电电流 0-255 let result_Double = Double(result) let maxstr = String(format: "%.2f", Double(self.IchageRage!) as! CVarArg) let max = Double(maxstr)! * 100.0 if result_Double! < 0 || result_Double! > max { self.g_toast("Maximum_current_range".da_localizedStr() + "\(max)A") textfield.text = "" return }else{ //let MaxVoltInt = Int(self.MaxVoltage!) let result_int = Int(result_Double! * 100) //最后要转换为整形 let cmd = String(format: "FF06E001%04X" ,result_int) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 2{ // 充电上限温度 var result_Int = Int(result) let min = 30 let max = 120 var msg = "Charge_upper_temperature_range".da_localizedStr() if self.istemp == "0" {//摄氏度转华氏 let result2 = result.fahrenheitToCentigrade_int() result_Int = Int(result2) msg = "Charge_upper_temperature_range_F".da_localizedStr() } if result_Int! < min || result_Int! > max { self.g_toast(msg) textfield.text = "" return }else{ let cmd = String(format: "FF06E015%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 3{ // 充电下限温度 if self.isPurnInt(string: result) == false{ self.g_toast("Please_enter_the_correct_number".da_localizedStr()) return } if result.contains(".") == true{ self.g_toast("Cannot_enter_decimals".da_localizedStr()) return } var result_Int = Int(result) var min = -40 var max = 20 var zero = 0 var msg = "Lower_charging_temperature_range".da_localizedStr() if self.istemp == "0" {//华氏度转摄氏度 msg = "Lower_charging_temperature_range_F".da_localizedStr() let result2 = result.fahrenheitToCentigrade_int() result_Int = Int(result2) } if result_Int! < min || result_Int! > max { self.g_toast(msg) textfield.text = "" return }else{ var cmd = "" if result_Int! >= min && result_Int! < zero { //判断负数 let res = "\(result_Int!)" let resutA = res.subString(start: 1) let resubB = Int(resutA) let resubC = resubB! | 128 cmd = String(format: "FF06E016%04X", resubC) // 转化为十六进制 }else{ cmd = String(format: "FF06E016%04X", result_Int!) // 转化为十六进制 } self.cmdArr?.append(cmd) } }else if indexPath.row == 4{ //超压电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast( "Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) log.debug(reslutData) let cmd = String(format: "FF06E005%04X", reslutDataInt) // 转化为十六进制 log.debug("指令 -- \(cmd)") self.cmdArr?.append(cmd) } }else if indexPath.row == 5{ //充电限制电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E006%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 6{ // 提升充电电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ if self.CellBatteryType == BatteryType.LI { //修改界面的值 let importV = Float(result) self.dataSources![4] = String(format: "%.1f", importV! + 2.0) //超压电压 self.dataSources![5] = String(format: "%.1f", importV! + 1.1) //充电限制电压 self.dataSources![6] = String(format: "%.1f", importV! ) self.dataSources![7] = String(format: "%.1f", importV! ) // 浮充充电电压 self.dataSources![8] = String(format: "%.1f", importV! - 1.2) //提升返回电压 self.dataSources![11] = String(format: "%.1f", importV!) //均衡充电电压 self.collectionView?.reloadData() //添加数据 4 let reslutData4 = ( result_float! + 2.0 ) * 10 / Double(self.Multiple!) let reslutDataInt4 = Int(reslutData4) log.debug(reslutData4) let cmd4 = String(format: "FF06E005%04X", reslutDataInt4) // 转化为十六进制 log.debug("指令 -- \(cmd4)") self.cmdArr?.append(cmd4) //5 let reslutData5 = (result_float! + 1.1) * 10 / Double(self.Multiple!) let reslutDataInt5 = Int(reslutData5) let cmd5 = String(format: "FF06E006%04X", reslutDataInt5) // 转化为十六进制 self.cmdArr?.append(cmd5) // // //7 // let reslutData7 = result_float! * 10 / Double(self.Multiple!) let reslutDataInt7 = Int(reslutData7) let cmd7 = String(format: "FF06E009%04X", reslutDataInt7) // 转化为十六进制 self.cmdArr?.append(cmd7) //8 let reslutData8 = (result_float! - 1.2) * 10 / Double(self.Multiple!) let reslutDataInt8 = Int(reslutData8) let cmd8 = String(format: "FF06E00A%04X", reslutDataInt8) // 转化为十六进制 self.cmdArr?.append(cmd8) //11 let reslutData11 = result_float! * 10 / Double(self.Multiple!) let reslutDataInt11 = Int(reslutData11) let cmd11 = String(format: "FF06E007%04X", reslutDataInt11) // 转化为十六进制 self.cmdArr?.append(cmd11) } //6 let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E008%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 7{ // 浮充充电电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E009%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 8{ // 提升充电返回电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E00A%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 9{ // 提升充电时间 let result_Int = Int(result) if result_Int! < 10 || result_Int! > 300 { self.g_toast("Increase_charging_time_range") textfield.text = "" return }else{ let cmd = String(format: "FF06E012%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 10{ // 温度补偿系数 // if result.contains(".") == true{ // self.g_toast("不能输入小数") // return // } let result_Int = Int(result) if result_Int! > 5 { self.g_toast("Temperature_compensation_coefficient_range") textfield.text = "" return }else{ // let res = result.subString(start: 1)//去掉负号 if result_Int! == 0 { textfield.text = "0" let cmd = String(format: "FF06E014%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) }else if result_Int! > 0 && result_Int! <= 5{ textfield.text = "-" + result let cmd = String(format: "FF06E014%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) }else{ textfield.text = "" return } } }else if indexPath.row == 11{ // 均衡充电电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E007%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 12{ // 均衡充电时间 let result_Int = Int(result) if result_Int! < 0 || result_Int! > 300 { self.g_toast("Balanced_charging_time_range".da_localizedStr()) textfield.text = "" return }else{ let cmd = String(format: "FF06E011%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 13{ // 自动均衡 let result_Int = Int(result) if result_Int! < 0 || result_Int! > 255 { self.g_toast("Automatic_equalization_range".da_localizedStr()) textfield.text = "" return }else{ let cmd = String(format: "FF06E013%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 15{ // 过放返回电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E00B%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 16{ // 欠压警告电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E00C%04X", reslutDataInt) // 转化为十六进制 log.debug(cmd) self.cmdArr?.append(cmd) } }else if indexPath.row == 17{ // 过放电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ if self.CellBatteryType == BatteryType.LI { //修改界面的值 let overV = Float(result) self.dataSources![16] = String(format: "%.1f", overV! + 1.0) //欠压警告电压 self.dataSources![17] = String(format: "%.1f", overV! ) //过放电压 self.dataSources![18] = String(format: "%.1f", overV! - 0.5) //放点截止电压 self.collectionView?.reloadData() //16 let reslutData16 = (result_float! + 1.0) * 10 / Double(self.Multiple!) let reslutDataInt16 = Int(reslutData16) let cmd16 = String(format: "FF06E00C%04X", reslutDataInt16) // 转化为十六进制 log.debug(cmd16) self.cmdArr?.append(cmd16) //18 let reslutData18 = (result_float! - 0.5) * 10 / Double(self.Multiple!) let reslutDataInt18 = Int(reslutData18) let cmd18 = String(format: "FF06E00E%04X", reslutDataInt18) // 转化为十六进制 self.cmdArr?.append(cmd18) } //18 let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E00D%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 18{ // 放电限制电压 *10 let result_float = Double(result) if result_float! < 7.0 * Double(self.Multiple!) || result_float! > 17.0 * Double(self.Multiple!) { self.g_toast("Voltage_range".da_localizedStr() + "\(7.0 * Double(self.Multiple!) )V~\(17.0 * Double(self.Multiple!))V") textfield.text = "" return }else{ let reslutData = result_float! * 10 / Double(self.Multiple!) let reslutDataInt = Int(reslutData) let cmd = String(format: "FF06E00E%04X", reslutDataInt) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 19{ // 过放延时d时间 let result_Int = Int(result) if result_Int! < 0 || result_Int! > 120 { self.g_toast("discharge_delay_time_range".da_localizedStr()) textfield.text = "" return }else{ let cmd = String(format: "FF06E010%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 20{ //放电上限温度 // let result_Int = Int(result) var result_Int = Int(result) let min = 30 let max = 120 var msg = "Upper_discharge_temperature_range".da_localizedStr() if self.istemp == "0" {//华氏度转摄氏度 msg = "Upper_discharge_temperature_range_F".da_localizedStr() let result2 = result.fahrenheitToCentigrade_int() result_Int = Int(result2) } if result_Int! <= min || result_Int! >= max { self.g_toast(msg) textfield.text = "" return }else{ let cmd = String(format: "FF06E017%04X", result_Int!) // 转化为十六进制 self.cmdArr?.append(cmd) } }else if indexPath.row == 21{ //放电下限温度, if self.isPurnInt(string: result) == false{ self.g_toast("Please_enter_the_correct_number".da_localizedStr()) return } if result.contains(".") == true{ self.g_toast("Cannot_enter_decimals".da_localizedStr()) return } var result_Int = Int(result) let min = -40 let max = 20 let zero = 0 var msg = "Lower_discharge_temperature_range".da_localizedStr() if self.istemp == "0" {//摄氏度 msg = "Lower_discharge_temperature_range_F".da_localizedStr() let result2 = result.fahrenheitToCentigrade_int() result_Int = Int(result2) } if result_Int! < min || result_Int! > max { self.g_toast(msg) textfield.text = "" return }else{ var cmd = "" if result_Int! >= min && result_Int! < zero { //判断负数 let res = "\(result_Int!)" let resutA = res.subString(start: 1) let resubB = Int(resutA) let resubC = resubB! | 128 cmd = String(format: "FF06E018%04X", resubC) // 转化为十六进制 }else{ // 0~20 cmd = String(format: "FF06E018%04X", result_Int!) // 转化为十六进制 } self.cmdArr?.append(cmd) } } } return cell } } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { // for i in 0..<22 { // if i == indexPath.row{ // // sb_SelectedArr![i] = true // if indexPath.row == 1 { // // }else if indexPath.row == 14{ // // // }else{ // let cell = self.collectionView?.cellForItem(at: indexPath) as! SBTParamSet_Item // // cell.sb_selected = true // } // self.collectionView?.reloadData() // // // }else{ // // sb_SelectedArr![i] = false // if indexPath.row == 1 { // // }else if indexPath.row == 14{ // // // }else{ // let cell = self.collectionView?.cellForItem(at: indexPath) as! SBTParamSet_Item // // cell.sb_selected = false // } // self.collectionView?.reloadData() // } // } // // // log.debug("当前的IndexPath、\(indexPath)") // } //数据范围 func juDageDataRange(_ indexPath :IndexPath ,result :String) { } }