×
Namespaces

Variants
Actions
(Difference between revisions)

QWiimote - Nintendo Wiimote interactions for Qt / Symbian applications

From Nokia Developer Wiki
Jump to: navigation, search
galazzo (Talk | contribs)
m (Galazzo - - Buttons)
galazzo (Talk | contribs)
m (Galazzo - - QML)
Line 72: Line 72:
  
 
Page {
 
Page {
 
+
    Wiimote {
        Wiimote {
+
        id: wiimote
              id: wiimote
+
    }
        }
+
 
}
 
}
 
</code>
 
</code>

Revision as of 20:33, 28 October 2012

Article Metadata
Tested with
Devices(s): Nokia C7-00, Nokia N8
Compatibility
Platform(s): Symbian^3 and later
Platform Security
Signing Required: DevCert
Capabilities: WriteDeviceData NetworkServices LocalServices
Article
Keywords: Nintendo, Wiimote, Bluetooth, HID
Created: galazzo (20 Oct 2012)
Last edited: galazzo (28 Oct 2012)

Contents

Introduction

Nintendo Wiimote
The Wii Remote, also known colloquially as the Wiimote, is the primary controller for Nintendo's Wii console. A main feature of the Wii Remote is its motion sensing capability, which allows the user to interact with and manipulate items on screen via gesture recognition and pointing through the use of accelerometer and optical sensor technology. Another feature is its expandability through the use of attachments. The attachment bundled with the Wii console is the Nunchuk, which complements the Wii Remote by providing functions similar to those in gamepad controllers.

The Wii MotionPlus is an expansion device for the Wii Remote video game controller for the Wii that allows it to more accurately capture complex motion. According to Nintendo, the sensor in the device supplements the accelerometer and Sensor Bar capabilities of the Wii Remote to enable actions to be rendered identically on the screen in real time.
Since 2006, launch date for Nintendo Wii, have been developed projects and tools to connect the Wiimote to devices different form the mother console. Anyway almost all are focused on Desktop application with very complex structurre and code interfaces.
Last but not least there is a poor support for mobile platforms where there is more focues on to substitute the device event management with the controller one. QWiimote provide a QML bind and easy method to catch Nintendo's controller raw data and event.
This article will cover just the API to interact with Wiimote. For who's interested on hack informations, please refer to dedicated project's section : Wiimote Hacking

QWiimote

  • Download the project from here

.pro

include(wiimote/wiimote.pri)

main.cpp

#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
 
#ifdef QWIIMOTE
#include <QtDeclarative>
#include "wiimote/qwiimote.h"
#endif
 
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
 
#ifdef QWIIMOTE
qmlRegisterType<QWiimote>("Wiimote", 1, 0, "Wiimote");
#endif
 
QmlApplicationViewer viewer;
viewer.setMainQmlFile(QLatin1String("qml/WiimoteDemo/main.qml"));
viewer.showExpanded();
 
return app->exec();
}

QML

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
Wiimote {
id: wiimote
}
}

Start Wiimote

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
id: mainPage
 
Button {
text: "Start!"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.start();
}
 
Wiimote {
id: wiimote
 
onError : {
console.log("Error code:"+error)
}
 
onPowerOn : {
console.log("Bluetooth power error:"+error)
}
 
onDeviceSelected : {
console.log("Selected device :"+address)
}
 
onConnected : {
console.log("Connected to device")
wiimote.setLed(Wiimote.Led1)
}
 
onDisconnected : {
console.log("Disconnected from device")
Qt.quit();
}
 
onSendCompleted : {
console.log("Sent data to device")
}
}
}

Buttons

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
id: mainPage
 
Button {
text: "Start!"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.start();
}
 
Button {
text: "Activate Buttons"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.enableCoreButtons()
}
 
Wiimote {
id: wiimote
 
onButtonPressed : {
console.log("pressed button: "+ button);
if( button === (Wiimote.ButtonA|Wiimote.ButtonB))
console.log("A + B pressed")
}
 
onButtonLeft : {
console.log("pressed left button");
}
 
onButtonRight : {
console.log("pressed right button");
}
 
onButtonUp : {
console.log("pressed up button");
}
 
onButtonDown : {
console.log("pressed down button");
}
 
onButtonHome : {
console.log("pressed home button");
}
 
onButtonA : {
console.log("pressed A button");
}
 
onButtonMinus : {
console.log("pressed Minus button");
}
 
}

Acceletometer

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
id: mainPage
 
Button {
text: "Start!"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.start();
}
 
Button {
text: "Activate Buttons and Accelerometer"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.enableCoreButtonsAndAccelerometer()
}
 
Wiimote {
id: wiimote
 
onAccelerometerChanged: {
console.log(accelerometer.x)
console.log(accelerometer.y)
console.log(accelerometer.z)
}
}
}

Motion Plus

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
id: mainPage
 
Button {
text: "Start!"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.start();
}
 
Button {
text: "Motion Plus"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.enableMotionPlus()
}
 
Button {
text: "Acceleration + Extension report"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: wiimote.enableCoreButtonsAccelerometerExtention()
}
 
Wiimote {
id: wiimote
 
onExtentionControllerPlugged: {
console.log("ExtentionControllerPlugged");
}
}
}

Signals

  • connected()

Emitted when the controller is connected to your device

  • disconnected()

Emitted when the controller disconnect from your device

  • deviceSelected(QString address)

Emitted when select the coontroller from the list of availables Bluetooth devices

  • powerOn(bool error)

Emitted when the Bluetooth is powerd-on on your device

  • extentionControllerPlugged()

Emitted when an extention controller ( like Nunchuck ) is plugged to Wiimote

  • buttonPressed(int button)

Emitted when a button is pressed. button provide the code of button pressed on controller.

  • buttonLeft()

Emitted when the left button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonRight()

Emitted when the right button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonDown()

Emitted when the down button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonUp()

Emitted when the up button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonPlus()

Emitted when the + button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonTwo()

Emitted when the 2 button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonOne()

Emitted when the 1 button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonB()

Emitted when the B button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonA()

Emitted when the A button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonMinus()

Emitted when the - button is pressed. Also a buttonPressed(int button) signal is emitted.

  • buttonHome()

Emitted when the Home button is pressed. Also a buttonPressed(int button) signal is emitted.

  • error(int error)

Emitted when an error occurs.

Slots / Invokable Methods

  • setLed(WiimoteLed led)
  • enableCoreButtons()
  • enableCoreButtonsAndAccelerometer()
  • enableCoreButtonsAccelerometerExtention()
  • enableMotionPlus()
  • disableMotionPlus()
  • requestCalibrationData()

Further improvements

The project is still under development anyway features already available are almost freezed. More other function incoming soon. Accelerometer and Gyroscope ( Motion Plus ) raw data acquisition are already available but not yet for QML as for battery level notification.

Next days release:

  1. Accelerometer and Motion Plus bind to QML
  2. Accelerometer and Gyroscope smooth data
  3. IR-Camera support
338 page views in the last 30 days.
×