pragma ComponentBehavior: Bound import QtQuick import QtQuick.Controls import QtQuick.Layouts import Xpl2 ApplicationWindow { id: root // Set from C++ via setInitialProperties (--printheads CLI arg, default 10). required property int demoPhCount height: 700 title: "XPL2 Demo" visible: true width: 900 Component.onCompleted: { for (let i = 1; i <= root.demoPhCount; ++i) phModel.append({ "phId": i, "versionInfo": "" }); } ListModel { id: phModel } Connections { function onConnectedChanged() { debugConsole.appendLog(Xpl2Client.connected ? "Connected" : "Disconnected"); } function onErrorOccurred(error: string) { debugConsole.appendLog("ERROR: " + error); } function onPhVersionReceived(controllerId: int, printheadId: int, mcuFirmwareVersion: string, mcuHardwareVersion: string, mcuFirmwareVariant: string, fpgaFirmwareVersion: string, fpgaHardwareVersion: string, bootloaderVersion: string) { for (let i = 0; i < phModel.count; ++i) { if (phModel.get(i).phId === printheadId) { phModel.setProperty(i, "versionInfo", "MCU %1/%2 (%3) | FPGA %4/%5 | Boot %6".arg( mcuFirmwareVersion).arg( mcuHardwareVersion).arg( mcuFirmwareVariant).arg( fpgaFirmwareVersion).arg( fpgaHardwareVersion).arg( bootloaderVersion)); break; } } } function onStatusMessage(message: string) { debugConsole.appendLog(message); } target: Xpl2Client } ColumnLayout { anchors.fill: parent spacing: 0 ColumnLayout { Layout.fillHeight: true Layout.fillWidth: true Layout.margins: 16 spacing: 12 // --- Connection --- GroupBox { Layout.fillWidth: true title: "Connection" RowLayout { anchors.fill: parent Label { text: "Host:" } TextField { id: hostField Layout.fillWidth: true text: Xpl2Client.host onEditingFinished: Xpl2Client.host = text } Button { text: Xpl2Client.connected ? "Disconnect" : "Connect" onClicked: { if (Xpl2Client.connected) Xpl2Client.disconnectFromServer(); else Xpl2Client.connectToServer(); } } } } // --- JC Version --- GroupBox { Layout.fillWidth: true enabled: Xpl2Client.connected title: "Jetting Controller" RowLayout { anchors.fill: parent Button { text: "Get JC Version" onClicked: Xpl2Client.getJcVersion() } Label { text: Xpl2Client.controllerId > 0 ? "Controller: %1 | FW: %2 | HW: %3 | PHs: %4".arg( Xpl2Client.controllerId).arg( Xpl2Client.firmwareVersion).arg( Xpl2Client.hardwareVersion).arg( Xpl2Client.printheadCount) : "No version data" } } } // --- Control --- GroupBox { Layout.fillWidth: true enabled: Xpl2Client.connected title: "Control" GridLayout { anchors.fill: parent columns: 4 Button { text: "Jetting All On" onClicked: Xpl2Client.jettingAllOn() } Button { text: "Jetting Off" onClicked: Xpl2Client.jettingOff() } Button { text: "JC LED On" onClicked: Xpl2Client.jcIdLedOn() } Button { text: "JC LED Off" onClicked: Xpl2Client.jcIdLedOff() } Button { text: "JC Calibration" onClicked: Xpl2Client.jcCalibration() } Button { text: "Reset Fault Codes" onClicked: Xpl2Client.jcResetFaultCodes() } } } // --- Printheads --- GroupBox { Layout.fillHeight: true Layout.fillWidth: true enabled: Xpl2Client.connected title: "Printheads (%1)".arg(root.demoPhCount) ColumnLayout { anchors.fill: parent Button { text: "Get All PH Versions" onClicked: { for (let i = 0; i < phModel.count; ++i) Xpl2Client.getPhVersion(phModel.get(i).phId); } } ScrollView { Layout.fillHeight: true Layout.fillWidth: true ListView { model: phModel spacing: 4 delegate: RowLayout { id: phDelegate required property int phId required property string versionInfo width: ListView.view.width Label { Layout.preferredWidth: 50 font.bold: true text: "PH %1".arg(phDelegate.phId) } Button { text: "Version" onClicked: Xpl2Client.getPhVersion( phDelegate.phId) } Label { Layout.fillWidth: true elide: Text.ElideRight text: phDelegate.versionInfo || "—" } } } } } } } // --- Debug Console --- Rectangle { id: debugConsole function appendLog(msg: string): void { let ts = new Date().toLocaleTimeString(Qt.locale(), "HH:mm:ss.zzz"); debugLog.text += "[" + ts + "] " + msg + "\n"; debugLog.cursorPosition = debugLog.text.length; } Layout.fillWidth: true Layout.preferredHeight: 160 border.color: "#444" color: "#1e1e1e" radius: 4 ScrollView { anchors.fill: parent anchors.margins: 4 TextArea { id: debugLog background: null color: "#cccccc" font.family: "monospace" font.pointSize: 9 readOnly: true wrapMode: TextEdit.Wrap } } } } }