49c3fe5f4b1a84acd37d15bc404dfafc3d912a7b
[mardrone] / mardrone / ardrone_harmattan.qml
1 // uiName:Harmattan
2 import QtQuick 1.0
3 import com.nokia.meego 1.0
4 import Drone 1.0
5 //import gauges 1.0
6 import JoyStick 1.0
7
8 PageStackWindow {
9     id:mainWindow
10     initialPage: mainpageComponent
11     showStatusBar: false
12 //    fullscreen:true
13     property Component dialogComponent
14 // property alias m: mainPage
15
16     ToolBarLayout {
17             id: commonTools
18             visible: false
19             ToolItem { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop(); }
20         //    ToolItem { iconId: "icon-m-toolbar-home"; onClicked: pageStack.pop(); }
21             ToolItem { iconId: "icon-m-toolbar-view-menu"; onClicked: myMenu.open(); }
22
23         }
24
25
26   DroneControl {
27         id:drone
28   //      logSeq:initialPage.frameSeq
29     }
30   JoyStick {
31       id:js
32       onElevatorChanged:{if(drone.confUseJoyStick) drone.pitch=elevator;}
33       onAileronChanged: {if(drone.confUseJoyStick) drone.roll=-1.0*aileron;}
34       onThrotleChanged: {if(drone.confUseJoyStick) drone.vVelocity=throtle;}
35       onRudderChanged:  {if(drone.confUseJoyStick) drone.yaw=rudder;}
36
37   }
38   Keys.onPressed: {
39       console.debug("QML:Keys.onPressed",event.key)
40                 if (event.key == Qt.Key_TopMenu)
41                     console.debug("QML: opening menu!")
42                 else if (event.key == Qt.Key_Close) {
43                     console.debug("QML: closing! (maybe)")
44                     pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
45                 }
46             }
47
48   function backKey() {
49        console.debug("QML: backKey")
50       pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
51     }
52
53     Component {
54       id: mainpageComponent
55
56       Page {
57         id:mainPage
58         property int frameSeq:0
59         property bool connectingBoxVisible:true
60         //onEntered:(mainWindow.fullscreen=true)
61
62         state:"Landscape"
63         DroneVideo {
64             id:droneVideo
65             y:0
66             x:0
67            // anchors.horizontalCenter:parent.horizontalCenter
68             width:drone.confFullScreen? parent.width:640 ;height:480*width/640;
69
70         }
71         Binding {
72           target:drone
73           property:"logSeq"
74           value: droneVideo.frameSeq;
75         }
76         EfisPFD {
77             id:hudPDF
78             y:0
79             anchors.horizontalCenter: parent.horizontalCenter
80             visible:drone.confShowHorizon
81             roll:drone.droneRoll
82             pitch:drone.dronePitch
83             ias:drone.droneSpeed
84             alt:drone.droneAltitude
85             indicatorColor:"#00FF00"
86             skyColor:"#00000000"
87             groundColor:"#00000000"
88             width:500;height:400;
89         }
90
91
92         Text {
93             y:50
94  //           visible:drone.confUseAccel
95             visible:drone.confShowDebug
96             color: "#00FF00"
97             id: droneCtrlValues
98             font.pixelSize:25
99             text: "cmd:pitch=" + drone.pitch.toFixed(2) + " roll= " +  drone.roll.toFixed(2) + " yaw=" + drone.yaw.toFixed(2) + " vv= " + drone.vVelocity.toFixed(2)
100         }
101
102         Text {
103             y:70
104             visible:drone.confShowDebug
105             color: "#00FF00"
106             id: droneNavData
107             font.pixelSize:25
108             text: "pitch=" + drone.dronePitch.toFixed(2) + " roll= " +  drone.droneRoll.toFixed(2) + "yaw=" + drone.droneYaw.toFixed(2) + " alt= " +  drone.droneAltitude.toFixed(2)
109         }
110
111         Text {
112             y:100
113             visible:drone.confShowDebug
114             color: "#00FF00"
115             id: droneStatus
116             font.pixelSize:20
117             text: drone.decodedStatus
118         }
119         Button {
120             y:150;x:0
121             height: 50
122             width: 50
123             z:2 // This is visible even connecting to drone
124             iconSource: "gear32x32.png"
125             onClicked:{   //mainWindow.fullscreen = false ;
126                      pageStack.push(dialogComponent);
127             }
128         }
129
130         JoyStickIndicator {
131             x:200;y:350
132             visible:drone.confShowJSIndicators&js.haveJoyStick&drone.confUseJoyStick
133             border.width:1
134             color:"transparent"
135             width:100;height:100
136             xvalue:js.axis4
137             yvalue:js.axis3
138             Text {
139                 anchors.bottom: parent.bottom
140                 font.pixelSize: 10
141                 text:"       rudder"
142             }
143             Text {
144                 x:-10;y:50
145                 rotation:90
146                 font.pixelSize: 10
147                 text:"Throtle"
148             }
149         }
150
151
152         JoyStickIndicator {
153             x:500;y:350
154             visible:drone.confShowJSIndicators&js.haveJoyStick&drone.confUseJoyStick
155             border.width:1
156             color:"transparent"
157             width:100;height:100
158             xvalue:js.axis1
159             yvalue:js.axis2
160             Text {
161                 anchors.bottom: parent.bottom
162                 font.pixelSize: 10
163                 text:"      Aileron"
164             }
165             Text {
166                 x:-15;y:50
167                 rotation:90
168                 font.pixelSize: 10
169                 text:"Elevator"
170             }
171         }
172
173         JoyStickTouch {
174             id:lj
175             width:200;height:200;
176
177             visible: !drone.confUseAccel & !drone.confUseJoyStick
178             anchors.left:parent.left
179             anchors.bottom:parent.bottom
180             anchors.margins:10
181             joyBackground: ""
182             onYvChanged:{drone.vVelocity=-1*yv/200.0;}
183             onXvChanged:{drone.yaw=xv/200.0;}
184             onPressedChanged: { drone.ctrlActive=pressed;}
185         }
186
187         JoyStickTouch {
188              visible: !drone.confUseJoyStick
189             id:rj
190
191             joyBackground: ""
192             anchors.right:parent.right
193             anchors.bottom:parent.bottom
194             width:200;height:200;
195             anchors.margins:10
196             onYvChanged:{drone.pitch=yv/200.0;}
197             onXvChanged:{drone.roll=xv/200.0;}
198         }
199
200         Row {
201             spacing: 5
202             anchors.right:parent.right
203             anchors.rightMargin: 10
204             y:100
205             height:100
206         BarGauge {
207            val:drone.pwm_motor1;
208            max: 255
209            height:100
210         }
211         BarGauge {
212             val:drone.pwm_motor2;
213             max: 255
214             height:100
215         }
216         BarGauge {
217             val:drone.pwm_motor3;
218             max: 255
219             height:100
220         }
221         BarGauge {
222             val:drone.pwm_motor4;
223             max: 255
224             height:100
225         }
226         BarGauge {
227             val:drone.droneVBat
228             max: 100
229             height:100
230         }
231         }
232
233         Button {
234             x:300
235             width:80
236             id:flyButton
237             anchors.bottom:parent.bottom
238             anchors.margins:15
239             text:"Fly";
240             checkable:true
241             onClicked:{drone.fly=checked;
242             // mainWindow.fullsecreen=checked;
243             }
244         }
245         Button {
246             x:450
247             width:100
248             id:emergencyButton
249             anchors.bottom:parent.bottom
250
251             anchors.margins:15
252             text:"Emrg";
253             checkable:true
254             onClicked:{drone.emergency=checked;}
255         }
256         Button {
257             x:600;
258             width:100
259             id:recordButton
260             anchors.bottom:parent.bottom
261             anchors.margins:15
262             text:"Rec";
263             checkable:true
264             onClicked:{droneVideo.recVideo=checked; drone.logFileName=droneVideo.videoFileName; drone.recordLog=checked;}
265         }
266         Text {
267             y:700
268             anchors.bottom:parent.bottom
269        //     visible:droneVideo.recVideo
270             color: "#00FF00"
271             id: droneFrameSeq
272             font.pixelSize:25
273             text: droneVideo.videoFileName+ " "+droneVideo.frameSeq
274         }
275
276             Connections {
277                 target:drone
278                 onConnectedChanged:{
279                     console.log("Connected to drone");
280                     connectingDialog.accept();}
281             }
282             QueryDialog {
283                 id:connectingDialog
284                 message:"Connecting to Drone "+ drone.confDroneIp
285                 acceptButtonText:"OK"
286                 Component.onCompleted: {
287                     console.log("ConectionDialog Opened");
288                     if(!drone.connected) open(); }
289             }
290         } // Main page
291     }
292
293      Component.onCompleted: {
294          if (mainpageComponent.status != Component.Ready)
295                      console.log("Error loading component:", mainpageComponent.errorString());
296          dialogComponent = Qt.createComponent("ConfigDialog.qml");
297
298         }
299  }