Control your Desktopia Pro X from Swift.
Add swift-desktopia as a dependency to your Package.swift:
let package = Package(
// name, platforms, products, etc.
dependencies: [
// other dependencies
.package(url: "https://github.com/sgade/swift-desktopia", from: "1.0.0"),
],
targets: [
.executableTarget(
name: "<your target>",
dependencies: [
// other dependencies
.product(name: "DesktopiaProX", package: "swift-desktopia"),
]
),
// other targets
]
)Connect your device to the desk controller via the USB connection, and then find the device name for that connection. Since it is a serial connection, you will need to find the corresponding device on your file system.
On macOS, these devices are usually called something like /dev/cu.usbserial-X, where X is a number.
With that device name, you can create a connection to the desk:
import DesktopiaProX
let desk = Desk(port: "/dev/cu.usbserial-123", keepAlive: true)
try await desk.connect()The connection to the desk is in both ways, so you can send commands and the desk can send commands on its own.
You can get a stream of commands to read:
Task {
let stream = try await desk.readCommands()
for await command in stream {
// interpret command...
}
}To send commands to the desk, all you need to do is:
try await desk.send(command: .showStatus)The protocol has been reverse engineered from the official app (beta). Contributions and corrections are welcome.
See LICENSE.