×
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 - - Buttons)
galazzo (Talk | contribs)
m (Galazzo - - Further improvements)
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Symbian]][[Category:Qt]][[Category:Symbian C++]][[Category:Multimedia]][[Category:Bluetooth]]
+
[[Category:Symbian]][[Category:Qt]][[Category:Symbian C++]][[Category:Bluetooth]][[Category:Sensor]][[Category:Symbian]][[Category:Qt]][[Category:Symbian C++]][[Category:Multimedia]][[Category:Bluetooth]]
 +
[[Category:Symbian]][[Category:Qt]][[Category:Symbian C++]][[Category:Bluetooth]][[Category:Sensor]]
 +
{{Abstract|This article explains how to interact with a Nintendo Wiimote on Symbian devices using QML.}}
 +
 
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [http://projects.developer.nokia.com/Wiimote/browser Wiimote] (Nokia Project)
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Nokia C7-00, Nokia N8
 
|devices= Nokia C7-00, Nokia N8
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
+
|sdk= Qt SDK 1.2.1
 
|platform= Symbian^3 and later
 
|platform= Symbian^3 and later
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
Line 24: Line 27:
  
 
== Introduction ==
 
== Introduction ==
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.
 
  
[[File:Wiimote.jpg]] <br>
+
The [http://en.wikipedia.org/wiki/Wii_Remote Wii Remote] (also known 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 on-screen items on screen using gestures and pointing.
''Nintendo Wiimote''
+
 
 +
The Wiimote is expandable through the use of attachments like the "Nunchuk", which complement the Wii Remote by providing functions similar to those in gamepad controllers. Another attachment is the Wii MotionPlus which allows the Wii 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).
  
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.<br />
+
[[File:Wiimote.jpg|frame|none|Nintendo Wiimote]]
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. {{Icode|QWiimote}} provide a QML bind and easy method to catch Nintendo's controller raw data and event.
+
Many tools have been developed to connect the Wiimote to other devices (instead of the Wii console).  Most are targeted towards desktop applications, and have complex structure and code interfaces. Little work has been done in the mobile space, and most of that has focused on substituting the device event management with the controller events.  
  
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 : [http://projects.developer.nokia.com/Wiimote/wiki/Wiimote_Hacking Wiimote Hacking]
+
The  [http://projects.developer.nokia.com/Wiimote Nintendo Wiiremote] project delivers a simple QML wrapper to connect to the Nintendo Wiimote on a Symbian device and to get its raw data and events. This article explains how to get and use the {{Icode|QWiimote }} API.
  
== QWiimote ==
+
== Adding the library to your projects ==
 +
=== Get the source===
  
* Download the project from [http://projects.developer.nokia.com/Wiimote/browser here]
+
Download the QWiimote source from [http://projects.developer.nokia.com/Wiimote/browser here]
  
=== .pro ===
+
=== .pro ===
 +
Add the following line to your application project (.pro) file to include QWiimote project files:
 
<code cpp-qt>
 
<code cpp-qt>
 
include(wiimote/wiimote.pri)
 
include(wiimote/wiimote.pri)
Line 46: Line 50:
  
 
=== main.cpp ===
 
=== main.cpp ===
 +
Includes and register {{Icode|QWiimote}} so that it can be used in your application QML:
 
<code cpp-qt>
 
<code cpp-qt>
 
#include <QtGui/QApplication>
 
#include <QtGui/QApplication>
Line 60: Line 65:
  
 
#ifdef QWIIMOTE
 
#ifdef QWIIMOTE
 +
    // The following registers the C++ QWiimote to be used in QML as Wiimote
 
     qmlRegisterType<QWiimote>("Wiimote", 1, 0, "Wiimote");
 
     qmlRegisterType<QWiimote>("Wiimote", 1, 0, "Wiimote");
 +
    qmlRegisterType<QWiimoteAccelerometerData>("Wiimote", 1, 0, "WiimoteAccelerometerData");
 +
    qmlRegisterType<QWiimoteMotionPlusData>("Wiimote", 1, 0, "WiimoteMotionPlusData");
 
#endif
 
#endif
  
Line 71: Line 79:
 
</code>
 
</code>
  
== QML ==
+
=== QML ===
 +
Declare the Wiimote QML element:
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 84: Line 93:
 
</code>
 
</code>
  
 +
== Connecting/ Device state management ==
 
=== Signals ===
 
=== Signals ===
* {{Icode|onPowerOn}}: Emitted when activating Bluetooth on your device
+
* {{Icode|onPowerOn}}  - Emitted when activating Bluetooth on your device
* {{Icode|onDeviceSelected }}Emitted when selected an item/device from the Bluetooth system menu list. Returns device address
+
* {{Icode|onDeviceSelected }} - Emitted when selected an item/device from the Bluetooth system menu list. Returns device address
* {{Icode|onConnected}}Emitted when connected to Wiimote
+
* {{Icode|onConnected}} - Emitted when connected to Wiimote
* {{Icode|onDisconnected}}Emitted when disconnected from Wiimote
+
* {{Icode|onDisconnected}} - Emitted when disconnected from Wiimote
  
 
=== Slots ===
 
=== Slots ===
* {{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()}} - Activate Bluetooth on your device if needed and shows Bluetooth devices detected nearby. Is the first method to call in order to begin pairing operations.
  
=== Pairing Wiimote with your device===
+
=== Code snippet ===
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>
+
File:Wiimote-Start-Slot.png|System's menu for discovered Bluetooth devices
+
File:Wiimote-Pairing-buttons.png|Wiimote pairing buttons
+
</gallery>
+
Selected the ''Nintendo RVL-CNT-01'' device the {{Icode|onDeviceSelected}} and {{Icode|onConnected}} signals are emitted.
+
 
+
=== Enabling actions ===
+
Once connected to device you can set which kind of informations you need. 
+
* {{Icode|setLed(WiimoteLed led)}}
+
<code cpp>
+
enum WiimoteLed {
+
        Rumble = 0x01,
+
        Led1  = 0x10,
+
        Led2  = 0x20,
+
        Led3  = 0x40,
+
        Led4  = 0x80
+
};
+
</code>
+
 
+
Sets the preferred Wiimote led. Remeber such operation need to be made by hand once {{Icode|onConnected}} signal is emitted
+
* {{Icode|enableCoreButtons()}}
+
Wiimote send just informations on pressed buttons
+
* {{Icode|enableCoreButtonsAndAccelerometer()}}
+
Wiimote sends informations on pressed buttons and accelerometer
+
* {{Icode|enableMotionPlus()}}
+
Enables the Motion Plus device
+
* {{Icode|disableMotionPlus()}}
+
Disable the motion Plus device
+
* {{Icode|enableCoreButtonsAccelerometerExtention()}}
+
Wiimote sends informations on pressed button, accelerometer and gyroscope inside Motion Plus device
+
 
+
By default once connected the Wiimote self sets to {{Icode|enableCoreButtons()}} ''action''. If you need, for example, other information like accelerometer notifications you need to call {{Icode|enableCoreButtonsAndAccelerometer()}} ''action''.<br />
+
To access to Motion Plus data ( the gyroscope ) you need to call {{Icode|enableCoreButtonsAccelerometerExtention()}} ''action'', but be careful to call the {{Icode|enableMotionPlus()}} ''action'' before.
+
 
+
{{Note|Don't enable ''actions'' you don't need in order to save battery as Wiimote data flow is very high.}}
+
  
==== Overview ====
 
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 174: Line 147:
 
</code>
 
</code>
  
=== Buttons ===
+
== Pairing devices ==
 +
 
 +
To pair your device with Wiimote you need to call the {{Icode|start()}} slot. Press together the Wiimote's {{Icode|1}}  and {{Icode|2}}  buttons in order to make it discoverable.
 +
 
 +
<gallery widths="300px" heights="400px">
 +
File:Wiimote-Start-Slot.png|System's menu for discovered Bluetooth devices
 +
File:Wiimote-Pairing-buttons.png|Wiimote pairing buttons
 +
</gallery>
 +
 
 +
Selected the ''Nintendo RVL-CNT-01'' device the {{Icode|onDeviceSelected()}} and {{Icode|onConnected()}} signals are emitted.
 +
 
 +
== Enabling actions ==
 +
Once connected to device you can specify which kind of information you need. 
 +
* {{Icode|setLed(WiimoteLed led)}} - Sets the preferred Wiimote LED. Remember this operation needs to be made once the {{Icode|onConnected()}} signal is emitted
 +
*: <code cpp>
 +
enum WiimoteLed {
 +
        Rumble = 0x01,
 +
        Led1  = 0x10,
 +
        Led2  = 0x20,
 +
        Led3  = 0x40,
 +
        Led4  = 0x80
 +
};
 +
</code>
 +
* {{Icode|enableCoreButtons()}} - Wiimote send just information on pressed buttons
 +
* {{Icode|enableCoreButtonsAndAccelerometer()}} - Wiimote sends information on pressed buttons and accelerometer
 +
* {{Icode|enableMotionPlus()}} - Enables the Motion Plus device
 +
* {{Icode|disableMotionPlus()}} - Disable the motion Plus device
 +
* {{Icode|enableCoreButtonsAccelerometerExtention()}} - Wiimote sends information on pressed button, accelerometer and gyroscope inside Motion Plus device
 +
 
 +
Once connected the Wiimote sets the {{Icode|enableCoreButtons()}} ''action'' automatically. If you need other information like accelerometer notifications you need to call {{Icode|enableCoreButtonsAndAccelerometer()}} ''action''.
 +
 
 +
To access to Motion Plus data ( the gyroscope ) you need to call {{Icode|enableCoreButtonsAccelerometerExtention()}} ''action'', but be careful to call the {{Icode|enableMotionPlus()}} ''action'' first.
 +
 
 +
{{Tip|Don't enable ''actions'' you don't need in order to save battery as Wiimote data flow is very high}}
 +
 
 +
== Buttons ==
 
{{Icode|QWiimote}} provides a set of signals in order to manage buttons pressed on Wiimote.
 
{{Icode|QWiimote}} provides a set of signals in order to manage buttons pressed on Wiimote.
  
'''Signals'''
+
=== Signals ===
* {{Icode|buttonPressed(int button)}}  Manages all buttons and useful for double pressing management as shown into overview
+
* {{Icode|buttonPressed(int button)}}  - Manages all buttons and useful for double pressing management as shown into overview
 
* {{Icode|buttonLeft()}}
 
* {{Icode|buttonLeft()}}
 
* {{Icode|buttonRight()}}
 
* {{Icode|buttonRight()}}
Line 194: Line 202:
  
 
<code cpp>
 
<code cpp>
    enum WiimoteButton {
+
enum WiimoteButton {
            ButtonLeft  = 0x0100,
+
  ButtonLeft  = 0x0100,
            ButtonRight = 0x0200,
+
  ButtonRight = 0x0200,
            ButtonDown  = 0x0400,
+
  ButtonDown  = 0x0400,
            ButtonUp    = 0x0800,
+
  ButtonUp    = 0x0800,
            ButtonPlus  = 0x1000,
+
  ButtonPlus  = 0x1000,
            ButtonHome  = 0x0080,
+
  ButtonHome  = 0x0080,
            ButtonMinus = 0x0010,
+
  ButtonMinus = 0x0010,
            ButtonTwo  = 0x0001,
+
  ButtonTwo  = 0x0001,
            ButtonOne  = 0x0002,
+
  ButtonOne  = 0x0002,
            ButtonB    = 0x0004,
+
  ButtonB    = 0x0004,
            ButtonA    = 0x0008
+
  ButtonA    = 0x0008
        };
+
};
 
</code>
 
</code>
  
'''Overview'''
+
=== Code snippet ===
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 270: Line 278:
 
</code>
 
</code>
  
=== Acceletometer ===  
+
== Smooting raw data ==
 +
Device sensor doesn't provide stable continuos data when device is still. This is because sensor are electrical devices bases on micro voltage changes that can be affected also by external conditions.<br />
 +
Is it possible to make up raw data using inner thresholds. If the new data has a value less then the fixed threshold then will not be updated. <br />
 +
That solution allows you to have stable data, but higher the threshold lower s the precision. If you don't feel with thresholds precalculated inside the project you can build your own data stabilizer using raw data.<br />
 +
To enable smooth data acquisition you have to use the {{Icode|smooth}} variable.<br />
 +
 
 +
=== Code snippet ===
 +
<code javascript>
 +
import QtQuick 1.1
 +
import com.nokia.symbian 1.1
 +
import Wiimote 1.0
 +
 
 +
Page {
 +
    id: mainPage
 +
 
 +
    Wiimote {
 +
        id: wiimote
 +
        smooth:true 
 +
    }
 +
 
 +
}
 +
</code>
 +
 
 +
== Accelerometer ==
 +
To use the accelerometer first call {{Icode|enableCoreButtonsAndAccelerometer()}} and then implement the {{Icode|accelerometerChanged()}} handler ({{Icode|onAccelerometerChanged()}}) to process the raw data from the Wiimote.<br />
 +
{{Icode|accelerometerChanged()}} returns a {{Icode|QWiimoteAccelerometerData}} object having the following member fields:<br />
 +
* {{Icode|x}}  value of x-axis gravity
 +
* {{Icode|y}}  value of y-axis gravity
 +
* {{Icode|z}}  value of z-axis gravity
 +
 
 +
=== Code snippet ===
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 293: Line 331:
 
     Wiimote {
 
     Wiimote {
 
         id: wiimote
 
         id: wiimote
 
+
        smooth: true
 
         onAccelerometerChanged: {
 
         onAccelerometerChanged: {
 
             console.log(accelerometer.x)
 
             console.log(accelerometer.x)
Line 303: Line 341:
 
</code>
 
</code>
  
=== Motion Plus ===
+
== Motion Plus ==
 +
To use the gyroscope inside MotionPlus follow the following flow:<br />
 +
# {{Icode|enableMotionPlus()}} 
 +
# {{Icode|enableCoreButtonsAccelerometerExtention()}}
 +
# implement the {{Icode|motionPlusChanged()}} handler ({{Icode|onMotionPlusChanged()}}) to process the raw data from the Wiimote.<br />
 +
 
 +
{{Icode|motionPlusChanged()}} returns a {{Icode|QWiimoteMotionPlusData}} object having the following member fields:<br />
 +
* {{Icode|yaw}}  the yaw value
 +
* {{Icode|roll}}  the roll value
 +
* {{Icode|pitch}}  the pitch value
 +
* {{Icode|magnitude}}  the vector module of three axis. Useful when you need to catch the strength of the movement independent of direction
 +
* {{Icode|yawSlowMode}} true if yaw movement is slow, false if very fast
 +
* {{Icode|rollSlowMode}} true if roll movement is slow, false if very fast
 +
* {{Icode|pitchSlowMode}} true if pitch movement is slow, false if very fast
 +
* {{Icode|extentionConnected}} true if there is an extention controller connected to Motion Plus
 +
 
 +
=== Code snippet ===
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 332: Line 386:
 
         Wiimote {
 
         Wiimote {
 
               id: wiimote
 
               id: wiimote
 +
            smooth: true
  
              onExtentionControllerPlugged: {
+
            onMotionPlusChanged: {
                   console.log("ExtentionControllerPlugged");
+
                   console.log(gyroscope.yaw)
              }      
+
                  console.log(gyroscope.roll)
 +
                  console.log(gyroscope.pitch)
 +
                  console.log(gyroscope.magnitude)
 +
                  console.log(gyroscope.yawSlowMode)
 +
                  console.log(gyroscope.rollSlowMode)
 +
                  console.log(gyroscope.pitchSlowMode)
 +
            }
 
         }     
 
         }     
 
}
 
}
Line 341: Line 402:
  
 
== Battery level ==
 
== Battery level ==
In order to retrieve battery informations, you can use the {{Icode|bettery}} property  
+
In order to retrieve battery information, you can use the {{Icode|battery}} property  
 
<code javascript>
 
<code javascript>
 
import QtQuick 1.1
 
import QtQuick 1.1
Line 359: Line 420:
  
 
== Further improvements ==
 
== Further improvements ==
The project is still under development anyway features already available are almost freezed. More new function are coming soon. Gyroscope ( Motion Plus ) raw data acquisition is already available but not yet for QML.
+
The project is still under development so while some features are already available (and almost frozen) others function are still coming.  
  
Next release contains:<br />
+
In the near future I plan to  release:
# Motion Plus bind to QML
+
# Accelerometer and Gyroscope smooth data
+
 
# IR-Camera support
 
# IR-Camera support
 +
 +
== Summary ==
 +
 +
This article describes how to interact with Wiimote. For more information on hacking the remote, please refer to dedicated project's section : [http://projects.developer.nokia.com/Wiimote/wiki/Wiimote_Hacking Wiimote Hacking]

Revision as of 13:18, 12 November 2012

This article explains how to interact with a Nintendo Wiimote on Symbian devices using QML.

Article Metadata
Code Example
Source file: Wiimote (Nokia Project)
Tested with
SDK: Qt SDK 1.2.1
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 (12 Nov 2012)

Contents

Introduction

The Wii Remote (also known 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 on-screen items on screen using gestures and pointing.

The Wiimote is expandable through the use of attachments like the "Nunchuk", which complement the Wii Remote by providing functions similar to those in gamepad controllers. Another attachment is the Wii MotionPlus which allows the Wii 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).

Nintendo Wiimote

Many tools have been developed to connect the Wiimote to other devices (instead of the Wii console). Most are targeted towards desktop applications, and have complex structure and code interfaces. Little work has been done in the mobile space, and most of that has focused on substituting the device event management with the controller events.

The Nintendo Wiiremote project delivers a simple QML wrapper to connect to the Nintendo Wiimote on a Symbian device and to get its raw data and events. This article explains how to get and use the QWiimote API.

Adding the library to your projects

Get the source

Download the QWiimote source from here

.pro

Add the following line to your application project (.pro) file to include QWiimote project files:

include(wiimote/wiimote.pri)

main.cpp

Includes and register QWiimote so that it can be used in your application QML:

#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
// The following registers the C++ QWiimote to be used in QML as Wiimote
qmlRegisterType<QWiimote>("Wiimote", 1, 0, "Wiimote");
qmlRegisterType<QWiimoteAccelerometerData>("Wiimote", 1, 0, "WiimoteAccelerometerData");
qmlRegisterType<QWiimoteMotionPlusData>("Wiimote", 1, 0, "WiimoteMotionPlusData");
#endif
 
QmlApplicationViewer viewer;
viewer.setMainQmlFile(QLatin1String("qml/WiimoteDemo/main.qml"));
viewer.showExpanded();
 
return app->exec();
}

QML

Declare the Wiimote QML element:

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

Connecting/ Device state management

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() - Activate Bluetooth on your device if needed and shows Bluetooth devices detected nearby. Is the first method to call in order to begin pairing operations.

Code snippet

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

Pairing devices

To pair your device with Wiimote you need to call the start() slot. Press together the Wiimote's 1 and 2 buttons 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 specify which kind of information you need.

  • setLed(WiimoteLed led) - Sets the preferred Wiimote LED. Remember this operation needs to be made once the onConnected() signal is emitted
     enum WiimoteLed {
    Rumble = 0x01,
    Led1 = 0x10,
    Led2 = 0x20,
    Led3 = 0x40,
    Led4 = 0x80
    };
  • enableCoreButtons() - Wiimote send just information on pressed buttons
  • enableCoreButtonsAndAccelerometer() - Wiimote sends information on pressed buttons and accelerometer
  • enableMotionPlus() - Enables the Motion Plus device
  • disableMotionPlus() - Disable the motion Plus device
  • enableCoreButtonsAccelerometerExtention() - Wiimote sends information on pressed button, accelerometer and gyroscope inside Motion Plus device

Once connected the Wiimote sets the enableCoreButtons() action automatically. If you need other information 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 first.

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

Buttons

QWiimote provides a set of signals 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
};

Code snippet

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

Smooting raw data

Device sensor doesn't provide stable continuos data when device is still. This is because sensor are electrical devices bases on micro voltage changes that can be affected also by external conditions.
Is it possible to make up raw data using inner thresholds. If the new data has a value less then the fixed threshold then will not be updated.
That solution allows you to have stable data, but higher the threshold lower s the precision. If you don't feel with thresholds precalculated inside the project you can build your own data stabilizer using raw data.
To enable smooth data acquisition you have to use the smooth variable.

Code snippet

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

Accelerometer

To use the accelerometer first call enableCoreButtonsAndAccelerometer() and then implement the accelerometerChanged() handler (onAccelerometerChanged()) to process the raw data from the Wiimote.
accelerometerChanged() returns a QWiimoteAccelerometerData object having the following member fields:

  • x value of x-axis gravity
  • y value of y-axis gravity
  • z value of z-axis gravity

Code snippet

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
smooth: true
onAccelerometerChanged: {
console.log(accelerometer.x)
console.log(accelerometer.y)
console.log(accelerometer.z)
}
}
}

Motion Plus

To use the gyroscope inside MotionPlus follow the following flow:

  1. enableMotionPlus()
  2. enableCoreButtonsAccelerometerExtention()
  3. implement the motionPlusChanged() handler (onMotionPlusChanged()) to process the raw data from the Wiimote.

motionPlusChanged() returns a QWiimoteMotionPlusData object having the following member fields:

  • yaw the yaw value
  • roll the roll value
  • pitch the pitch value
  • magnitude the vector module of three axis. Useful when you need to catch the strength of the movement independent of direction
  • yawSlowMode true if yaw movement is slow, false if very fast
  • rollSlowMode true if roll movement is slow, false if very fast
  • pitchSlowMode true if pitch movement is slow, false if very fast
  • extentionConnected true if there is an extention controller connected to Motion Plus

Code snippet

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
smooth: true
 
onMotionPlusChanged: {
console.log(gyroscope.yaw)
console.log(gyroscope.roll)
console.log(gyroscope.pitch)
console.log(gyroscope.magnitude)
console.log(gyroscope.yawSlowMode)
console.log(gyroscope.rollSlowMode)
console.log(gyroscope.pitchSlowMode)
}
}
}

Battery level

In order to retrieve battery information, you can use the battery 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 so while some features are already available (and almost frozen) others function are still coming.

In the near future I plan to release:

  1. IR-Camera support

Summary

This article describes how to interact with Wiimote. For more information on hacking the remote, please refer to dedicated project's section : Wiimote Hacking

254 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×