×
Namespaces

Variants
Actions
(Difference between revisions)

QWiimote - Nintendo Wiimote interactions for Qt / Symbian applications

From Nokia Developer Wiki
Jump to: navigation, search
croozeus (Talk | contribs)
m (Croozeus - - Pairing devices)
croozeus (Talk | contribs)
m (Croozeus - - Pairing devices)
Line 90: Line 90:
 
* {{Icode|start}}:  Activates Bluetooth on your device if needed and shows the system's menu of near Bluetooth found devices.This is the first method to call in order to begin pairing operations.
 
* {{Icode|start}}:  Activates Bluetooth on your device if needed and shows the system's menu of near Bluetooth found devices.This is the first method to call in order to begin pairing operations.
  
=== Pairing devices ===
+
=== Pairing Wiimote with your device===
 
To pair your device with Wiimote you need to call the {{Icode|start}} slot. Press the Wiimote's {{Icode|1}}  and {{Icode|2}}  buttons together in order to make it discoverable.
 
To pair your device with Wiimote you need to call the {{Icode|start}} slot. Press the Wiimote's {{Icode|1}}  and {{Icode|2}}  buttons together in order to make it discoverable.
 
<gallery>
 
<gallery>

Revision as of 08:18, 29 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: croozeus (29 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 structure and code interfaces

Last but not least there is a poor support for mobile platforms where there is more focuses 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 information, 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
}
}

Signals

  • onPowerOn: Emitted when activating Bluetooth on your device
  • onDeviceSelected : Emitted when selected an item/device from the Bluetooth system menu list. Returns device address
  • onConnected: Emitted when connected to Wiimote
  • onDisconnected: Emitted when disconnected from Wiimote

Slots

  • start: Activates Bluetooth on your device if needed and shows the system's menu of near Bluetooth found devices.This is the first method to call in order to begin pairing operations.

Pairing Wiimote with your device

To pair your device with Wiimote you need to call the start slot. Press the Wiimote's 1 and 2 buttons together in order to make it discoverable.

Selected the Nintendo RVL-CNT-01 device the onDeviceSelected and onConnected signals are emitted.

Enabling actions

Once connected to device you can set which kind of informations you need.

  • setLed(WiimoteLed led)
 enum WiimoteLed {
Rumble = 0x01,
Led1 = 0x10,
Led2 = 0x20,
Led3 = 0x40,
Led4 = 0x80
};

Sets the preferred Wiimote led. Remeber such operation need to be made by hand once onConnected signal is emitted

  • enableCoreButtons()

Wiimote send just informations on pressed buttons

  • enableCoreButtonsAndAccelerometer()

Wiimote sends informations on pressed buttons and accelerometer

  • enableMotionPlus()

Enables the Motion Plus device

  • disableMotionPlus()

Disable the motion Plus device

  • enableCoreButtonsAccelerometerExtention()

Wiimote sends informations on pressed button, accelerometer and gyroscope inside Motion Plus device

By default once connected the Wiimote self sets to enableCoreButtons() action. If you need for example other informations like accelerometer notifications you need to call enableCoreButtonsAndAccelerometer() action.
To access to Motion Plus data ( the gyroscope ) you need to call enableCoreButtonsAccelerometerExtention() action, but be careful to call the enableMotionPlus() action before.

Note.pngNote: Don't enable actions you don't need in order to save battery as Wiimote data flow is very high

Overview

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();
}
}
}

Buttons

QWiimote provides a set of signal in order to manage buttons pressed on Wiimote.

Signals

  • buttonPressed(int button) Manages all buttons and useful for double pressing management as shown into overview
  • buttonLeft()
  • buttonRight()
  • buttonDown()
  • buttonUp()
  • buttonPlus()
  • buttonTwo()
  • buttonOne()
  • buttonB()
  • buttonA()
  • buttonMinus()
  • buttonHome()

When a button in pressed on Wiimote two signals are emitted, buttonPressed(int button) and the corresponding button's signal. For example if left button is pressed buttonPressed(int button) and buttonLeft() signal are emitted.

    enum WiimoteButton {
ButtonLeft = 0x0100,
ButtonRight = 0x0200,
ButtonDown = 0x0400,
ButtonUp = 0x0800,
ButtonPlus = 0x1000,
ButtonHome = 0x0080,
ButtonMinus = 0x0010,
ButtonTwo = 0x0001,
ButtonOne = 0x0002,
ButtonB = 0x0004,
ButtonA = 0x0008
};

overview

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");
}
}
}

Battery level

In order to retrieve battery informations, you can use the bettery property

import QtQuick 1.1
import com.nokia.symbian 1.1
import Wiimote 1.0
 
Page {
Wiimote {
id: wiimote
onConnected : {
wiimote.setLed(Wiimote.Led1)
console.log("Battery level"+wiimote.battery)
}
}
}

Further improvements

The project is still under development anyway features already available are almost freezed. More other function coming soon. Gyroscope ( Motion Plus ) raw data acquisition is already available but not yet for QML.

Next days release:

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