sync repo
[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             color: "#00FF00"
75             id: droneCtrlValues
76             font.pixelSize:25
77             text: "cmd:pitch=" + drone.pitch.toFixed(2) + " roll= " +  drone.roll.toFixed(2) + " yaw=" + drone.yaw.toFixed(2) + " vv= " + drone.vVelocity.toFixed(2)
78         }
79
80         Text {
81             y:70
82             visible:drone.confShowDebug
83             color: "#00FF00"
84             id: droneNavData
85             font.pixelSize:25
86             text: "pitch=" + drone.dronePitch.toFixed(2) + " roll= " +  drone.droneRoll.toFixed(2) + "yaw=" + drone.droneYaw.toFixed(2) + " alt= " +  drone.droneAltitude.toFixed(2)
87         }
88
89         Text {
90             y:100
91             visible:drone.confShowDebug
92             color: "#00FF00"
93             id: droneStatus
94             font.pixelSize:20
95             text: drone.decodedStatus
96         }
97         Button {
98             y:150;x:0
99             height: 50
100             width: 50
101             z:2 // This is visible even connecting to drone
102             iconSource: "gear32x32.png"
103             onClicked:{   //mainWindow.fullscreen = false ;
104                      pageStack.push(dialogComponent);
105             }
106         }
107
108         JoyStickIndicator {
109             x:200;y:350
110             visible:drone.confShowJSIndicators&js.haveJoyStick&drone.confUseJoyStick
111             border.width:1
112             color:"transparent"
113             width:100;height:100
114             xvalue:js.axis4
115             yvalue:js.axis3
116             Text {
117                 anchors.bottom: parent.bottom
118                 font.pixelSize: 10
119                 text:"       rudder"
120             }
121             Text {
122                 x:-10;y:50
123                 rotation:90
124                 font.pixelSize: 10
125                 text:"Throtle"
126             }
127         }
128
129
130         JoyStickIndicator {
131             x:500;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.axis1
137             yvalue:js.axis2
138             Text {
139                 anchors.bottom: parent.bottom
140                 font.pixelSize: 10
141                 text:"      Aileron"
142             }
143             Text {
144                 x:-15;y:50
145                 rotation:90
146                 font.pixelSize: 10
147                 text:"Elevator"
148             }
149         }
150
151         JoyStickTouch {
152             id:lj
153             width:200;height:200;
154
155             visible: !drone.confUseAccel & !drone.confUseJoyStick
156             anchors.left:parent.left
157             anchors.bottom:parent.bottom
158             anchors.margins:10
159   //          joyBackground: ""
160             onYvChanged:{drone.vVelocity=-1*yv/200.0;}
161             onXvChanged:{drone.yaw=xv/200.0;}
162             onPressedChanged: { drone.ctrlActive=pressed;}
163         }
164
165         JoyStickTouch {
166              visible: !drone.confUseJoyStick
167             id:rj
168
169       //      joyBackground: ""
170             anchors.right:parent.right
171             anchors.bottom:parent.bottom
172             width:200;height:200;
173             anchors.margins:10
174             onYvChanged:{drone.pitch=yv/200.0;}
175             onXvChanged:{drone.roll=xv/200.0;}
176         }
177
178         Row {
179             spacing: 5
180             anchors.right:parent.right
181             anchors.rightMargin: 10
182             y:100
183             height:100
184         BarGauge {
185            val:drone.pwm_motor1;
186            max: 255
187            height:100
188         }
189         BarGauge {
190             val:drone.pwm_motor2;
191             max: 255
192             height:100
193         }
194         BarGauge {
195             val:drone.pwm_motor3;
196             max: 255
197             height:100
198         }
199         BarGauge {
200             val:drone.pwm_motor4;
201             max: 255
202             height:100
203         }
204         BarGauge {
205             val:drone.droneVBat
206             max: 100
207             height:100
208         }
209         }
210
211         Button {
212             x:400
213             width:60
214             id:flyButton
215             anchors.bottom:parent.bottom
216             anchors.margins:15
217             text:"Fly";
218             checkable:true
219             onClicked:{drone.fly=checked;
220             // mainWindow.fullsecreen=checked;
221             }
222         }
223         Button {
224             x:500
225             width:140
226             id:emergencyButton
227             anchors.bottom:parent.bottom
228
229             anchors.margins:15
230             text:"Energency";
231             checkable:true
232             onClicked:{drone.emergency=checked;}
233         }
234
235
236             Connections {
237                 target:drone
238                 onConnectedChanged:{
239                     console.log("Connected to drone");
240                     connectingDialog.accept();}
241             }
242             QueryDialog {
243                 id:connectingDialog
244                 message:"Connecting to Drone "+ drone.confDroneIp
245                 acceptButtonText:"OK"
246                 Component.onCompleted: {
247                     console.log("ConectionDialog Opened");
248                     if(!drone.connected) open(); }
249             }
250         } // Main page
251     }
252
253      Component.onCompleted: {
254          if (mainpageComponent.status != Component.Ready)
255                      console.log("Error loading component:", mainpageComponent.errorString());
256          dialogComponent = Qt.createComponent("ConfigDialog.qml");
257
258         }
259  }