Skip to content

Commit

Permalink
优化OTA提示,完善功能
Browse files Browse the repository at this point in the history
  • Loading branch information
神奇海螺 committed May 13, 2019
1 parent 50b0f1e commit b6c9ed0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
13 changes: 11 additions & 2 deletions TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TCDeviceInfoTableViewController: UITableViewController {
let update = UIAlertAction(title: "马上更新", style: .destructive, handler: { (_) in
TC1ServiceManager.share.publishMessage(["mac":self.deviceModel.mac,"setting":["ota":"http://home.wula.vip:4380/TC1_OTA.bin"]])
DispatchQueue.main.async {
HUD.flash(.labeledProgress(title: "正在更新", subtitle: "请勿退出程序"), delay: 2)
HUD.show(.labeledProgress(title: "正在更新", subtitle: "请勿断开设备电源!"))
}
})
alert.addAction(update)
Expand All @@ -119,7 +119,16 @@ extension TCDeviceInfoTableViewController:TC1ServiceReceiveDelegate{

func TC1ServiceReceivedMessage(message: Data) {
let messageJSON = try! JSON(data: message)
print(messageJSON)
let otaProgress = messageJSON["ota_progress"].floatValue
if otaProgress > 0{
print("OTA 进度 ---> \(otaProgress)")
}
if otaProgress == 100 {
DispatchQueue.main.async {
HUD.flash(.labeledSuccess(title: "更新成功!", subtitle: nil))
}
}

}

func TC1ServicePublish(messageId: Int) {
Expand Down
4 changes: 4 additions & 0 deletions TC1-NG/Controller/Device/TCDeviceMainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ extension TCDeviceMainViewController:TC1ServiceReceiveDelegate{
self.powerView.animateToProgress(progress: 1/2500 * power)
self.powerLabel.text = "\(power)W";
}
if let ip = messageJSON["ip"].string{
self.deviceModel.ip = ip
TCSQLManager.updateTCDevice(self.deviceModel)
}
self.plugMessageReload(message: messageJSON)
}
}
Expand Down
6 changes: 1 addition & 5 deletions TC1-NG/Controller/MainList/TCListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class TCListViewController: UIViewController {
self.tableView.reloadData()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
TC1ServiceManager.share.closeService()
}

private func discoverDevices(mac:String){
TC1ServiceManager.share.delegate = self
TC1ServiceManager.share.connectService()
Expand Down Expand Up @@ -153,6 +148,7 @@ extension TCListViewController:UITableViewDelegate,UITableViewDataSource{

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let vc = UIStoryboard(name: "TCDeviceMain", bundle: nil).instantiateInitialViewController() as? TCDeviceMainViewController{
TC1ServiceManager.share.closeService()
vc.deviceModel = self.dataSource[indexPath.row]
vc.title = self.dataSource[indexPath.row].name
self.navigationController?.pushViewController(vc, animated: true)
Expand Down
1 change: 1 addition & 0 deletions TC1-NG/TC1ServiceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ extension TC1ServiceManager{
"plug_5":["setting":["name":nil]]
] as [String : Any?]
self.publishMessage(cmd as [String : Any],qos: 1)
self.sendDeviceReportCmd()
}
}

Expand Down

0 comments on commit b6c9ed0

Please sign in to comment.