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 a device..."
242 scanButton.enabled = false
243 connectButton.enabled = false
244 disconnectButton.enabled = false
246 scanButton.enabled = true
247 disconnectButton.enabled = false
249 if(addressField.text !== "No device found yet." && portField.text !== "na")
250 connectButton.enabled = true
254 onNewServiceDiscovered: {
255 console.log("Service " + service.serviceName + " found on "
256 + service.deviceName + " at address " + service.deviceAddress
257 + " on port " + service.servicePort + ".")
258 if(service.serviceName === "Zeemote"){
259 addressField.text = service.deviceAddress
260 portField.text = service.servicePort
268 property int joystickThreshold: 50
271 disconnectButton.enabled = true
272 infoText.text = "Connected. Have fun."
276 connectButton.enabled = true
277 disconnectButton.enabled = false
278 infoText.text = "Press \"Connect\" to connect to the device."
282 // console.log("Stick moved. x: " + x + " y: " + y)
285 // onButtonsChanged: {
286 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
290 // console.log("A changed to: " + val)
291 xtstAdapter.sendKey("a", val);
294 // console.log("B changed to: " + val)
295 xtstAdapter.sendKey("b", val);
298 // console.log("C changed to: " + val)
299 xtstAdapter.sendKey("c", val);
302 // console.log("D changed to: " + val)
303 xtstAdapter.sendKey("d", val);
307 if(val > joystickThreshold){
308 xtstAdapter.sendKey("Right", true);
309 }else if(val < -joystickThreshold){
310 xtstAdapter.sendKey("Left", true);
312 xtstAdapter.sendKey("Right", false);
313 xtstAdapter.sendKey("Left", false);
318 if(val > joystickThreshold){
319 xtstAdapter.sendKey("Down", true);
320 }else if(val < -joystickThreshold){
321 xtstAdapter.sendKey("Up", true);
323 xtstAdapter.sendKey("Down", false);
324 xtstAdapter.sendKey("Up", false);