2 * Copyright 2012 Ruediger Gad
4 * This file is part of QZeeControl.
6 * QZeeControl is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * QZeeControl is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with QZeeControl. If not, see <http://www.gnu.org/licenses/>.
21 import com.nokia.meego 1.0
22 import QtMobility.connectivity 1.2
23 import "settingsstorage.js" as SettingsStorage
24 import qzeecontrol 1.0
29 orientationLock: PageOrientation.LockPortrait
31 Component.onCompleted: {
32 SettingsStorage.initialize();
34 var address = SettingsStorage.getSetting("address");
35 var port = SettingsStorage.getSetting("port");
36 if(address !== "Unknown" && port !== "Unknown"){
37 console.log("Loaded address " + address + " and port " + port + " from DB.")
38 addressField.text = address
47 target: cursorRectangle
48 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
49 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
53 color: btConn.a ? "red" : "blue"
57 color: btConn.b ? "red" : "blue"
61 color: btConn.c ? "red" : "blue"
65 color: btConn.d ? "red" : "blue"
71 target: cursorRectangle
72 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
73 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
96 target: platformWindow
99 if(platformWindow.active){
113 source: "image://theme/color8-meegotouch-view-header-fixed"
114 anchors.left: parent.left
115 anchors.top: parent.top
116 anchors.right: parent.right
121 font.family: "Nokia Pure Text Light"
123 anchors.left: parent.left
124 anchors.leftMargin: 20
125 anchors.verticalCenter: parent.verticalCenter
131 anchors{bottom: addressRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
137 btDiscovery.discovery = true
144 anchors{bottom: infoText.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
148 text: "No device found yet."
151 if(text === "No device found yet.")
154 connectButton.enabled = true
155 infoText.text = "Press \"Connect\" to connect to the device."
156 console.log("Storing address in DB: " + text)
157 SettingsStorage.setSetting("address", text)
164 validator: IntValidator{}
170 console.log("Storing port in DB: " + text)
171 SettingsStorage.setSetting("port", text)
178 anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
181 text: "Please scan for a device first."
182 horizontalAlignment: Text.AlignHCenter
183 wrapMode: Text.WordWrap
188 anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
195 btConn.connect(addressField.text, parseInt(portField.text))
201 anchors.centerIn: parent
213 anchors{top: disconnectButton.bottom; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
220 color: btConn.a ? "red" : "blue"
225 color: btConn.b ? "red" : "blue"
230 color: btConn.c ? "red" : "blue"
235 color: btConn.d ? "red" : "blue"
241 anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
254 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
255 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
259 BluetoothDiscoveryModel{
263 minimalDiscovery: true
265 onDiscoveryChanged: {
267 infoText.text = "Scanning for a device..."
268 scanButton.enabled = false
269 connectButton.enabled = false
270 disconnectButton.enabled = false
272 scanButton.enabled = true
273 disconnectButton.enabled = false
275 if(addressField.text !== "No device found yet." && portField.text !== "na")
276 connectButton.enabled = true
280 onNewServiceDiscovered: {
281 console.log("Service " + service.serviceName + " found on "
282 + service.deviceName + " at address " + service.deviceAddress
283 + " on port " + service.servicePort + ".")
284 if(service.serviceName === "Zeemote"){
285 addressField.text = service.deviceAddress
286 portField.text = service.servicePort
294 property int joystickThreshold: 50
297 disconnectButton.enabled = true
298 infoText.text = "Connected. Have fun."
302 connectButton.enabled = true
303 disconnectButton.enabled = false
304 infoText.text = "Press \"Connect\" to connect to the device."
308 // console.log("Stick moved. x: " + x + " y: " + y)
311 // onButtonsChanged: {
312 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
316 // console.log("A changed to: " + val)
317 xtstAdapter.sendKey("a", val);
320 // console.log("B changed to: " + val)
321 xtstAdapter.sendKey("b", val);
324 // console.log("C changed to: " + val)
325 xtstAdapter.sendKey("c", val);
328 // console.log("D changed to: " + val)
329 xtstAdapter.sendKey("d", val);
333 if(val > joystickThreshold){
334 xtstAdapter.sendKey("Right", true);
335 }else if(val < -joystickThreshold){
336 xtstAdapter.sendKey("Left", true);
338 xtstAdapter.sendKey("Right", false);
339 xtstAdapter.sendKey("Left", false);
344 if(val > joystickThreshold){
345 xtstAdapter.sendKey("Down", true);
346 }else if(val < -joystickThreshold){
347 xtstAdapter.sendKey("Up", true);
349 xtstAdapter.sendKey("Down", false);
350 xtstAdapter.sendKey("Up", false);