123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900 |
- //
- // 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<UITouch>, 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) {
-
- }
- }
|