aboutsummaryrefslogtreecommitdiffstats
path: root/demo/Main.qml
blob: 6aca2017145cac5e3e5b21a8f8779baa351aa773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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: 1200
    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
                                   ? "Controller connected" :
                                     "Controller disconnected");
        }

        function onErrorOccurred(error: string) {
            debugConsole.appendLog("ERROR: " + error);
        }

        function onJcStatusReceived(status) {
            statusPage.lastJcStatus = status;
        }

        function onListeningChanged() {
            debugConsole.appendLog(Xpl2Client.listening
                                   ? "Listening on ports 9110/9111/9112" :
                                     "Stopped listening");
        }

        function onPhStatusReceived(status) {
            statusPage.lastPhStatus = status;
        }

        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 onShuttingDown() {
            debugConsole.appendLog("SERVER SHUTTING DOWN");
        }

        function onStatusMessage(message: string) {
            debugConsole.appendLog(message);
        }

        target: Xpl2Client
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // --- Connection (always visible) ---
        GroupBox {
            Layout.bottomMargin: 0
            Layout.fillWidth: true
            Layout.margins: 16
            title: "Connection"

            RowLayout {
                anchors.fill: parent

                Label {
                    text: Xpl2Client.connected ? "Controller connected" :
                                                 "Waiting for controller…"
                }

                Item {
                    Layout.fillWidth: true
                }

                Button {
                    text: Xpl2Client.listening ? "Stop" : "Listen"

                    onClicked: {
                        if (Xpl2Client.listening)
                        Xpl2Client.stopListening();
                        else
                        Xpl2Client.startListening();
                    }
                }
            }
        }

        // --- Tab bar ---
        TabBar {
            id: tabBar

            Layout.fillWidth: true
            Layout.leftMargin: 16
            Layout.rightMargin: 16

            TabButton {
                text: "Commands"
            }

            TabButton {
                text: "Status"
            }
        }

        // --- Swipe view ---
        SwipeView {
            id: swipeView

            Layout.fillHeight: true
            Layout.fillWidth: true
            Layout.margins: 16
            currentIndex: tabBar.currentIndex

            onCurrentIndexChanged: tabBar.currentIndex = currentIndex

            CommandsPage {
                demoPhCount: root.demoPhCount
                phModel: phModel
            }

            StatusPage {
                id: statusPage

            }
        }

        // --- Debug Console ---
        DebugConsole {
            id: debugConsole

            Layout.fillWidth: true
            Layout.preferredHeight: 160
        }
    }
}