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