×
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)
(Galazzo - - Pairing devices)
galazzo (Talk | contribs)
(Galazzo - - Enabling actions)
Line 98: Line 98:
 
Once connected to device you can set which kind of informations you need.   
 
Once connected to device you can set which kind of informations you need.   
 
* {{Icode|setLed(WiimoteLed led)}}  
 
* {{Icode|setLed(WiimoteLed led)}}  
  Sets the preferred Wiimote led. Remeber such operation need to be made by hand once {{Icode|onConnected}} signal is emitted
+
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 {{Icode|onConnected}} signal is emitted
 
* {{Icode|enableCoreButtons()}}
 
* {{Icode|enableCoreButtons()}}
  Wiimote send just informations on pressed buttons
+
Wiimote send just informations on pressed buttons
 
* {{Icode|enableCoreButtonsAndAccelerometer()}}
 
* {{Icode|enableCoreButtonsAndAccelerometer()}}
  Wiimote sends informations on pressed buttons and accelerometer
+
Wiimote sends informations on pressed buttons and accelerometer
 
* {{Icode|enableMotionPlus()}}
 
* {{Icode|enableMotionPlus()}}
  Enables the Motion Plus device  
+
Enables the Motion Plus device  
 
* {{Icode|disableMotionPlus()}}
 
* {{Icode|disableMotionPlus()}}
  Disable the motion Plus device
+
Disable the motion Plus device
 
* {{Icode|enableCoreButtonsAccelerometerExtention()}}
 
* {{Icode|enableCoreButtonsAccelerometerExtention()}}
  Wiimote sends informations on pressed button, accelerometer and gyroscope inside Motion Plus device
+
Wiimote sends informations on pressed button, accelerometer and gyroscope inside Motion Plus device
  
 
By default once connected the Wiimote self sets to {{Icode|enableCoreButtons()}} condition. If you need for example other informations like accelerometer notifications you need to call {{Icode|enableCoreButtonsAndAccelerometer()}} ''action''.<br />
 
By default once connected the Wiimote self sets to {{Icode|enableCoreButtons()}} condition. If you need for example other informations like accelerometer notifications you need to call {{Icode|enableCoreButtonsAndAccelerometer()}} ''action''.<br />

Revision as of 22:01, 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
}
}

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 Blotooth on your device if needed and shows the system's menu of near Bluetooth found devices. Is the first method to call in order to begin pairing operations.

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 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() condition. 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.

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

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
218 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.

×