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