Convert dispatch functionality

This commit is contained in:
Matthias Neeracher 2016-11-13 13:27:19 +01:00 committed by Matthias Neeracher
parent 58015d3e78
commit 88d18d1209
4 changed files with 18 additions and 16 deletions

View File

@ -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)
})
}
}

View File

@ -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)
})
}

View File

@ -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]];
}

View File

@ -161,10 +161,11 @@ 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
if let newData = handle.availableDataIgnoringExceptions(),
let newString = String(data: newData, encoding: String.Encoding.ascii)
{
self.serialData += newString
DispatchQueue.main.async(execute: { () -> Void in
DispatchQueue.main.async(execute: {
self.logView.setString(self.serialData)
if self.scrollToBottom {
self.logView.gotoLine(1000000000, column: 0, animated: true)
@ -173,6 +174,7 @@ class ASSerialWin: NSWindowController {
}
}
}
}
@IBAction func sendInput(_: AnyObject) {
let line = inputLine.stringValue + (sendCR ? "\r" : "") + (sendLF ? "\n" : "")