Convert dispatch functionality
This commit is contained in:
parent
58015d3e78
commit
88d18d1209
|
@ -155,8 +155,8 @@ class ASBuilder {
|
|||
}
|
||||
args += ["-U", "flash:w:build/"+board+"/"+dir.lastPathComponent!+".hex:i"]
|
||||
continuation = {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2*NSEC_PER_SEC)), dispatch_get_main_queue(), {
|
||||
ASSerialWin.portAvailableAfterUpload(port)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
|
||||
ASSerialWin.portAvailableAfterUpload(port: port)
|
||||
})
|
||||
}
|
||||
case .BurnBootloader:
|
||||
|
@ -193,8 +193,8 @@ class ASBuilder {
|
|||
logOut.write(cmdLine.data(using: String.Encoding.utf8, allowLossyConversion: true)!)
|
||||
task2.launch()
|
||||
self.continuation = {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2*NSEC_PER_SEC)), dispatch_get_main_queue(), {
|
||||
ASSerialWin.portAvailableAfterUpload(port)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
|
||||
ASSerialWin.portAvailableAfterUpload(port: port)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -920,7 +920,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
|||
@IBAction func uploadProject(sender: AnyObject) {
|
||||
builder.continuation = {
|
||||
self.selectNodeInOutline(selection: self.files.uploadLog)
|
||||
dispatch_async(dispatch_get_main_queue(), {
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.builder.uploadProject(board: self.board, programmer:self.programmer, port:self.port)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -37,14 +37,14 @@ NSString * kASSerialPortsChanged = @"PortsChanged";
|
|||
watchSlashDev =
|
||||
dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd, DISPATCH_VNODE_WRITE, dispatch_get_main_queue());
|
||||
dispatch_source_set_event_handler(watchSlashDev, ^{
|
||||
[[NotificationCenter defaultCenter] postNotificationName:kASSerialPortsChanged object: nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kASSerialPortsChanged object: nil];
|
||||
});
|
||||
dispatch_resume(watchSlashDev);
|
||||
}
|
||||
|
||||
+ (NSArray<NSString *> *)ports {
|
||||
NSMutableArray * cuPorts = [NSMutableArray array];
|
||||
for (NSString * port in [[FileManager defaultManager] contentsOfDirectoryAtPath:@"/dev" error: nil]) {
|
||||
for (NSString * port in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/dev" error: nil]) {
|
||||
if ([[port substringToIndex:2] isEqualToString:@"cu"])
|
||||
[cuPorts addObject:[port substringFromIndex:3]];
|
||||
}
|
||||
|
|
|
@ -161,15 +161,17 @@ class ASSerialWin: NSWindowController {
|
|||
serialData = ""
|
||||
logView.setString(serialData)
|
||||
readHandle.readabilityHandler = {(handle) in
|
||||
let newData = handle.availableDataIgnoringExceptions()
|
||||
let newString = NSString(data: newData, encoding: String.Encoding.ascii) as! String
|
||||
self.serialData += newString
|
||||
DispatchQueue.main.async(execute: { () -> Void in
|
||||
self.logView.setString(self.serialData)
|
||||
if self.scrollToBottom {
|
||||
self.logView.gotoLine(1000000000, column: 0, animated: true)
|
||||
}
|
||||
})
|
||||
if let newData = handle.availableDataIgnoringExceptions(),
|
||||
let newString = String(data: newData, encoding: String.Encoding.ascii)
|
||||
{
|
||||
self.serialData += newString
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.logView.setString(self.serialData)
|
||||
if self.scrollToBottom {
|
||||
self.logView.gotoLine(1000000000, column: 0, animated: true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user