diff --git a/PsiMac/Assets.xcassets/Connected.imageset/5.png b/PsiMac/Assets.xcassets/Connected.imageset/5.png new file mode 100644 index 0000000..8f99fed Binary files /dev/null and b/PsiMac/Assets.xcassets/Connected.imageset/5.png differ diff --git a/PsiMac/Assets.xcassets/Connected.imageset/Contents.json b/PsiMac/Assets.xcassets/Connected.imageset/Contents.json new file mode 100644 index 0000000..90ec8dd --- /dev/null +++ b/PsiMac/Assets.xcassets/Connected.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "5.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PsiMac/Assets.xcassets/Disconnected.imageset/4.png b/PsiMac/Assets.xcassets/Disconnected.imageset/4.png new file mode 100644 index 0000000..c274fe7 Binary files /dev/null and b/PsiMac/Assets.xcassets/Disconnected.imageset/4.png differ diff --git a/PsiMac/Assets.xcassets/Disconnected.imageset/Contents.json b/PsiMac/Assets.xcassets/Disconnected.imageset/Contents.json new file mode 100644 index 0000000..6ebd06d --- /dev/null +++ b/PsiMac/Assets.xcassets/Disconnected.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "4.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PsiMac/PsiMacApp.swift b/PsiMac/PsiMacApp.swift index 8718a25..41c0087 100644 --- a/PsiMac/PsiMacApp.swift +++ b/PsiMac/PsiMacApp.swift @@ -21,11 +21,21 @@ import SwiftUI @main struct PsiMacApp: App { - let server = Server() + @State var server = Server() var body: some Scene { - WindowGroup { - ContentView() + + MenuBarExtra { + Button("Connect") { + + } + } label: { + if server.isConnected { + Image("Connected") + } else { + Image("Disconnected") + } } + } } diff --git a/PsiMac/Server.swift b/PsiMac/Server.swift index 1c91ec2..4f9b46c 100644 --- a/PsiMac/Server.swift +++ b/PsiMac/Server.swift @@ -18,30 +18,32 @@ import Foundation -struct Server { +@Observable +class Server { - func threadEntryPoint() { - - let arguments = ["ncpd", "-d", "-s", "/dev/tty.usbserial-A91MGK6M", "-b", "115200", "-v", "nl"] + var isConnected: Bool = false - let argc = Int32(arguments.count) - var argv: [UnsafeMutablePointer?] = arguments.map { strdup($0) } - argv.append(nil) // Null-terminate the array + func threadEntryPoint() { - // Convert the array to an UnsafeMutablePointer?> - let argvPointer = UnsafeMutablePointer?>.allocate(capacity: argv.count) - argvPointer.initialize(from: &argv, count: argv.count) + let context = Unmanaged.passRetained(self).toOpaque() + let callback: statusCallback_t = { context, status in + guard let context else { + return + } + print("status = \(status)") + let server = Unmanaged.fromOpaque(context).takeUnretainedValue() + DispatchQueue.main.sync { + server.isConnected = status == 1 ? true : false + } + } - // Call the C function - let result = run(argc, argvPointer) - print(result) + let device = "/dev/tty.usbserial-AL00AYCG" +// let device = "/dev/tty.usbserial-A91MGK6M" - // Free the memory allocated for the C strings - for arg in argv { - free(arg) - } - argvPointer.deallocate() +// let log: UInt16 = 1 | 2 | 4 | 8 | 18 | 32 | 64 + let log: UInt16 = 0 + ncpd(7501, 115200, "127.0.0.1", device, log, callback, context) } init() { diff --git a/dependencies/plptools b/dependencies/plptools index 6cafcb2..24b62e6 160000 --- a/dependencies/plptools +++ b/dependencies/plptools @@ -1 +1 @@ -Subproject commit 6cafcb2c0dd84d661d743859d0e0c8ca8f6e0580 +Subproject commit 24b62e6fd404048112b809f1beb88ed9a129a9cb