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 Component.onCompleted: {
30 SettingsStorage.initialize();
32 var address = SettingsStorage.getSetting("address");
33 var port = SettingsStorage.getSetting("port");
34 if(address !== "Unknown" && port !== "Unknown"){
35 console.log("Loaded address " + address + " and port " + port + " from DB.")
36 addressField.text = address
45 target: cursorRectangle
46 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
47 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
51 color: btConn.a ? "red" : "blue"
55 color: btConn.b ? "red" : "blue"
59 color: btConn.c ? "red" : "blue"
63 color: btConn.d ? "red" : "blue"
69 target: cursorRectangle
70 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
71 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
94 target: platformWindow
97 if(platformWindow.active){
107 anchors{bottom: addressRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
113 btDiscovery.discovery = true
120 anchors{bottom: infoText.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
124 text: "No device found yet."
127 if(text === "No device found yet.")
130 connectButton.enabled = true
131 infoText.text = "Press \"Connect\" to connect to the device."
132 console.log("Storing address in DB: " + text)
133 SettingsStorage.setSetting("address", text)
140 validator: IntValidator{}
146 console.log("Storing port in DB: " + text)
147 SettingsStorage.setSetting("port", text)
154 anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
157 text: "Please scan for a device first."
158 horizontalAlignment: Text.AlignHCenter
159 wrapMode: Text.WordWrap
164 anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
171 btConn.connect(addressField.text, parseInt(portField.text))
177 anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
189 anchors.centerIn: parent
195 color: btConn.a ? "red" : "blue"
200 color: btConn.b ? "red" : "blue"
205 color: btConn.c ? "red" : "blue"
210 color: btConn.d ? "red" : "blue"
216 anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
229 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
230 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
233 BluetoothDiscoveryModel{
237 minimalDiscovery: true
239 onDiscoveryChanged: {
241 infoText.text = "Scanning for devices..."
242 scanButton.enabled = false
243 connectButton.enabled = false
244 disconnectButton.enabled = false
246 scanButton.enabled = true
247 disconnectButton.enabled = false
251 onNewServiceDiscovered: {
252 console.log("Service " + service.serviceName + " found on "
253 + service.deviceName + " at address " + service.deviceAddress
254 + " on port " + service.servicePort + ".")
255 if(service.serviceName === "Zeemote"){
256 addressField.text = service.deviceAddress
257 portField.text = service.servicePort
265 property int joystickThreshold: 50
268 disconnectButton.enabled = true
269 infoText.text = "Connected. Have fun."
273 connectButton.enabled = true
274 disconnectButton.enabled = false
275 infoText.text = "Press \"Connect\" to connect to the device."
279 // console.log("Stick moved. x: " + x + " y: " + y)
282 // onButtonsChanged: {
283 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
287 // console.log("A changed to: " + val)
288 xtstAdapter.sendKey("a", val);
291 // console.log("B changed to: " + val)
292 xtstAdapter.sendKey("b", val);
295 // console.log("C changed to: " + val)
296 xtstAdapter.sendKey("c", val);
299 // console.log("D changed to: " + val)
300 xtstAdapter.sendKey("d", val);
304 if(val > joystickThreshold){
305 xtstAdapter.sendKey("Right", true);
306 }else if(val < -joystickThreshold){
307 xtstAdapter.sendKey("Left", true);
309 xtstAdapter.sendKey("Right", false);
310 xtstAdapter.sendKey("Left", false);
315 if(val > joystickThreshold){
316 xtstAdapter.sendKey("Down", true);
317 }else if(val < -joystickThreshold){
318 xtstAdapter.sendKey("Up", true);
320 xtstAdapter.sendKey("Down", false);
321 xtstAdapter.sendKey("Up", false);