PDA

View Full Version : [PATCH]: Wiimote Connection/Disconnection Notices; Battery Information


micolous
2008-02-27, 20:13
Hello,

This patch add extra functionality to the existing Wiimote support in XBMC. It adds the following:

- Changes "WiiRemote" in strings to "Wiimote" (the correct name for the device)
- Adds popup notification on successful Wiimote connection, including current battery level in the Wiimote {1}
- Adds popup notification on Wiimote disconnection
- Adds popup notification when the CWiiRemote class cannot find the Bluetooth radio, after trying to enable Wiimote support
- Enables LEDs 1 and 4 on connection, rather than just LED 1. This allows you to identify quickly whether you are connected to XBMC or a Wii, as this LED combination never occurs on the Wii.

As a result there are some extra strings in strings.xml, #21887 - #21891. I've only included English strings.

This applies to current HEAD, at the time of writing this was r11827.

Screenshot
{1}: http://img217.imageshack.us/img217/4985/wiibatteryvr9.th.jpg (http://img217.imageshack.us/my.php?image=wiibatteryvr9.jpg)

Patch
Index: guilib/common/WiiRemote.cpp
================================================== =================
--- guilib/common/WiiRemote.cpp (revision 11827)
+++ guilib/common/WiiRemote.cpp (working copy)
@@ -19,6 +19,10 @@
************************************************** *************************/
#ifdef HAS_CWIID
#include "WiiRemote.h"
+
+// To avoid recursive include issues, we need to include these here. I know it's naughty... --micolous (2008-02-28)
+#include "../../xbmc/Application.h"
+#include "../LocalizeStrings.h"

CWiiRemote g_WiiRemote;
CCriticalSection CWiiRemote::m_lock;
@@ -174,7 +178,7 @@

//Have the first LED on the Wiiremote shine when connected
ToggleBit(m_ledState, CWIID_LED1_ON);
-
+ ToggleBit(m_ledState, CWIID_LED4_ON);
CSingleLock lock (m_lock);

CLog::Log(LOGNOTICE, "Sucessfully initialized the Wiiremote Lib");
@@ -409,6 +413,9 @@
if (hci_get_route(NULL) < 0)
{
m_enabled = false;
+ CStdString strMsgTitle = g_localizeStrings.Get(21889);
+ CStdString strMsgText = g_localizeStrings.Get(21886);
+ g_application.m_guiDialogKaiToast.QueueNotificatio n(strMsgTitle,strMsgText);
CLog::Log(LOGERROR, "Cannot enable Wiiremote support because no bluetooth device was found");
}
else
@@ -464,6 +471,20 @@
{
EnterCriticalSection(m_lock);
SetupWiiRemote();
+ // get battery state etc.
+ cwiid_state wiimote_state;
+ int err = cwiid_get_state(m_wiiremoteHandle, &wiimote_state);
+ if (!err) {
+ CStdString strMsgTitle = g_localizeStrings.Get(21887);
+ CStdString strMsgTextRaw = g_localizeStrings.Get(21888);
+ CStdString strMsgText;
+
+ strMsgText.Format(strMsgTextRaw.c_str(),static_cas t<int>(((float)(wiimote_state.battery)/CWIID_BATTERY_MAX)*100.0));
+ g_application.m_guiDialogKaiToast.QueueNotificatio n(strMsgTitle,strMsgText);
+ } else {
+ CLog::Log(LOGERROR, "Problem probing for status of wiimote; cwiid_get_state returned non-zero");
+ }
+
#ifdef CWIID_OLD
/* CheckIn to say that this is the last msg, If this isn't called it could give issues if we Connects -> Disconnect and then try to connect again
the CWIID_OLD hack would automaticly disconnect the wiiremote as the lastmsg is too old. */
@@ -471,6 +492,7 @@
#endif
m_connected = true;
LeaveCriticalSection(m_lock);
+
CLog::Log(LOGNOTICE, "Sucessfully connected a Wiiremote");
return true;
}
@@ -498,6 +520,9 @@
if (m_connected) //It shouldn't be enabled at the same time as it is connected
{
cwiid_disconnect(m_wiiremoteHandle);
+ CStdString strMsgTitle = g_localizeStrings.Get(21890);
+ CStdString strMsgText = g_localizeStrings.Get(21891);
+ g_application.m_guiDialogKaiToast.QueueNotificatio n(strMsgTitle,strMsgText);
CLog::Log(LOGNOTICE, "Sucessfully disconnected a Wiiremote");
}
m_connected = false;
Index: language/English/strings.xml
================================================== =================
--- language/English/strings.xml (revision 11827)
+++ language/English/strings.xml (working copy)
@@ -1873,8 +1873,16 @@
<string id="21881">Enable UPnP Renderer</string>
<string id="21882">Attempt to skip introduction before DVD Menu</string>
<string id="21883">Ripped Audio CDs</string>
- <string id="21884">WiiRemote</string>
+
+ <!-- WiiRemote/Wiimote Input Device -->
+ <string id="21884">Wiimote</string>
<string id="21885">Enable mouse emulation</string>
+ <string id="21886">No Bluetooth radio found</string>
+ <string id="21887">Wiimote connected</string>
+ <string id="21888">%i%% battery remaining</string>
+ <string id="21889">Wiimote unavailable</string>
+ <string id="21890">Wiimote disconnected</string>
+ <string id="21891">Press 1 and 2 to reconnect</string>
<!-- strings 21900 thru 21999 reserved for slideshow info -->

<string id="22000">Update library on startup</string>

d4rk
2008-02-27, 21:48
Nice work, I like the idea of having 2 LEDs on to differentiate it from other wii remotes. I'm sure topfs2 will take a look as he maintains the wii remote code.

topfs2
2008-02-27, 21:59
Seems nice, I'll look at it more closely when I get home. I like the idea of notification with battery and the 1+2.

On a side note. It is NOT named Wiimote :) That is a nick. Nintendo have it under Wii Remote.
http://www.nintendo.com/
http://en.wikipedia.org/wiki/Wiimote

So that won't change ;)

micolous
2008-02-28, 00:10
Seems nice, I'll look at it more closely when I get home. I like the idea of notification with battery and the 1+2.

On a side note. It is NOT named Wiimote :) That is a nick. Nintendo have it under Wii Remote.
http://www.nintendo.com/
http://en.wikipedia.org/wiki/Wiimote

So that won't change ;)

Very well... everyone calls it a Wiimote... Probably because it sounds more Japanese that way.

But more practically, there is a very small limit to the size of notifications. On my system at 1280x1024 it goes past that limit for "Wii Remote Disconnected", and is very close for "Wii Remote Unavailable". Having that text scroll looks ugly, particularly for the title.

I had this issue when I was choosing notification strings; I had to be very concise about what I was writing.

topfs2
2008-02-28, 01:20
Commited, I did some minor cosmetic changed. Thanks!

Very well... everyone calls it a Wiimote... Probably because it sounds more Japanese that way.

But more practically, there is a very small limit to the size of notifications. On my system at 1280x1024 it goes past that limit for "Wii Remote Disconnected", and is very close for "Wii Remote Unavailable". Having that text scroll looks ugly, particularly for the title.

I had this issue when I was choosing notification strings; I had to be very concise about what I was writing.