• 1
  • 2
  • 3(current)
  • 4
  • 5
  • 56
[LINUX] Sony PlayStation 3 Blu-ray Disc Remote (PS3 BD) + LIRC + XBMC = SUCCESS
#31
erhnam Wrote:I wrote a howto. It's only in Dutch but most of the commands are there. Here's the link:

http://www.strengholt-online.nl/playstat...-xbmc/221/
Any chance that u translate it to english?
Reply
#32
Asure Wrote:I started out from your blog post (i'm dutch) before i came to the XBMC forums Smile

Can you tell me your distro ? It's not mentioned in the posting.
Also, why use cakemote in the end of the blog post ?

The 'old bdremote' part is to run only bdremote with a paired remote, and lirc to connect to it. For me, paired or not, bdremote will never pick up the remote, and send nothing to lirc.. (ubuntu 9.04) so that's why it's important to know your distro Smile

I used XBMC Live 9.04, so in fact Ubuntu 9.04. It has been a while ago since I wrote the blogpost. Maybe it's better to start all over again, using the latest bits and bytes and write a better howto.
Reply
#33
I ran some test today. I can't sleep with unanswered questions running around in my mind Smile

We've pretty much confirmed
- ps3d.py not working on 9.04.
- bdremoted not working on 9.04 (full, in my case)


So i went for Hardy 8.04 release. Installed libbluetooth, compiled bdremote.
Code:
/etc/init.d/bluetooth stop
./bdremoted -p 8888 -t 30 -a 00:21:4F:B2:3E:13 -r 10 -d200 -n -t 1
It worked on the first try.
Code:
[code]det=0, port=8888, tmout=1, rep=10, deb=200, addr=00:21:4F:B2:3E:13
BTBD remote connected.
54 , 01 , 00000010
single
processing!
processing1!
done!
E:54 , 01 , 00000010
FF , 01 , 00000030
multiple, 00000010, 00000030, 00000020
-snip, 1 minute later, timeout kicks in
BTBD receiver exited with: -1
BTBD try to reconnect.

So i'm pretty sure ps3d.py would also work on Hardy. But now i've got another problem. Apparently the ppa's for hardy have no VPDAU. So that's not doing my ION any good..!

ps3d.py:
Code:
cd /usr/share/python-support/xbmc-eventclients-common/xbmc/
wget [url]http://www.xbmc.org/trac/export/22189/branches/linuxport/XBMC/tools/EventClients/Clients/PS3%20Sixaxis%20Controller/ps3d.py[/url]
edit ps3_remote.py to use correct bluetooth.png
/usr/share/pixmaps/xbmc/bluetooth.png
pair it
Code:
./ps3_remote.py localhost
Searching for BD Remote Control
(Hold Start + Enter on remote to make it discoverable)
BD Remote Control (00:21:4F:B2:3E:13) in range
Found BD Remote Control with address 00:21:4F:B2:3E:13
Attempting to pair with remote
Remote Paired.
ctrl-c
modprobe hidp
./ps3d.py 00:21:4F:B2:3E:13 127.0.0.1
Zeroconf support disabled. To enable, install the following Python modules:
    dbus, gobject, avahi
Connecting to Bluetooth device: 00:21:4F:B2:3E:13
Connecting to : 127.0.0.1
Starting HID daemon
then wait. wait etc.. nothing connects on pairing, or button presses.
It still hangs on "client, addr = self._sock.accept ()" loop. Sad

After all these actions, simply running bdremoted as before still works. Remote is detected again, and can be used w/o problems.

Next tests: Try xbmc live 9.04 and see what happens..
Reply
#34
Update:

Live 9.04.1 cd-rom did not work with the steps above.
I followed the howto below, to use the older bluetooth 3.x stuff from hardy:
http://jackflapb.wordpress.com/2009/03/2...to-hardys/
Basically the steps are:
1. Remove all bluetooth stuff
2. Replace jaunty with hardy in your apt sources..
3. Install bluetooth and libbluetooth-dev from hardy.
4. Re-compile bdremoted using libbluetooth-dev from hardy.
5. Start bluetooth and stop it, run bdremoted as before, notice it detects keypresses

Installing bluetooth from Hardy will break lots of stuff it seems.. so be carefull Smile

I'm looking into going back to Jaunty apt sources and fix the breakage somehow.
Reply
#35
"So i'm pretty sure ps3d.py would also work on Hardy. But now i've got another problem. Apparently the ppa's for hardy have no VPDAU. So that's not doing my ION any good..!"

Compile from SVN instead.
Reply
#36
I didn't have any accelleration in desktop, so i was assuming i'd need to figure out another way to get it to work. Even though the glx shows up in X logs. Guess desktop wasn't using it ?

Trex6662k5: Are you running 9.04 with working bdremoted/lirc ? Or another flavor of linux ?

Edit: Guess i needed to switch on 'use restricted drivers' if google is correct:
https://help.ubuntu.com/community/Binary...wto/Nvidia
Reply
#37
Having been trying lot of variants on my ubuntu jaunty.
Neither of them satisfied me.
The problems:
Lirc works fine until you turned off the remote. Then, bluetoothd is not removing old device record, and new registration confuses Lirc - it just using correct event descriptor.
This is half of the story. I've written simple script which monitors number of PS3 records in bus/input/devices, and if more then 1 - restarts bluetoothd.
However, this produces a new HAL event, and XBMC captures new keyboard device (ps3 remote) directly from HAL, ignoring Lirc.
Then tried lot of custom scripts, written own python script to handle events, tried to bypass this with Lirc as event client - no go, still, XBMC doesn't care about any input device as soon as it sees new keyboard.
However, this new keyboard (ps3remote) is capable of sending cursor movement keys, play/stop, escape and numbers. Not a big list of options to choose.
As such, I've modified bluez's ps3remote driver to:
1) Correctly detect remote turning off and clean up device handler
2) Correctly handle holding of PS button, to allow remote to be turned off without generating ps button event.
3) remap keys on remote to send normal keyboard keys, which are predefined in system/Keymaps.xml
Here is the patch:
Code:
--- bluez-4.47/input/fakehid.c  2009-04-23 03:40:04.000000000 +0200
+++ bluez-4.47-my/input/fakehid.c       2009-08-16 13:23:09.000000000 +0200
@@ -94,11 +94,11 @@

static unsigned int ps3remote_keymap[] = {
        [0x16] = KEY_EJECTCD,
-       [0x64] = KEY_AUDIO,
-       [0x65] = KEY_ANGLE,
-       [0x63] = KEY_SUBTITLE,
-       [0x0f] = KEY_CLEAR,
-       [0x28] = KEY_TIME,
+       [0x64] = KEY_A,                 /* audio */
+       [0x65] = KEY_Z,                 /* angle */
+       [0x63] = KEY_T,                 /* subtitle */
+       [0x0f] = KEY_DELETE,            /* clear */
+       [0x28] = KEY_END,               /* timer */
        [0x00] = KEY_1,
        [0x01] = KEY_2,
        [0x02] = KEY_3,
@@ -109,41 +109,41 @@
        [0x07] = KEY_8,
        [0x08] = KEY_9,
        [0x09] = KEY_0,
-       [0x81] = KEY_RED,
-       [0x82] = KEY_GREEN,
-       [0x80] = KEY_BLUE,
-       [0x83] = KEY_YELLOW,
-       [0x70] = KEY_INFO,              /* display */
+       [0x81] = KEY_F7,                /* red */
+       [0x82] = KEY_F8,                /* green */
+       [0x83] = KEY_F9,                /* yellow */
+       [0x80] = KEY_F10,               /* blue */
+       [0x70] = KEY_D,                 /* display */
        [0x1a] = KEY_MENU,              /* top menu */
-       [0x40] = KEY_CONTEXT_MENU,      /* pop up/menu */
+       [0x40] = KEY_F11,               /* pop up/menu */
        [0x0e] = KEY_ESC,               /* return */
-       [0x5c] = KEY_OPTION,            /* options/triangle */
+       [0x5c] = KEY_F12,               /* options/triangle */
        [0x5d] = KEY_BACK,              /* back/circle */
-       [0x5f] = KEY_SCREEN,            /* view/square */
-       [0x5e] = BTN_0,                 /* cross */
+       [0x5f] = KEY_V,                 /* view/square */
+       [0x5e] = KEY_X,                 /* cross */
        [0x54] = KEY_UP,
        [0x56] = KEY_DOWN,
        [0x57] = KEY_LEFT,
        [0x55] = KEY_RIGHT,
        [0x0b] = KEY_ENTER,
-       [0x5a] = BTN_TL,                /* L1 */
-       [0x58] = BTN_TL2,               /* L2 */
-       [0x51] = BTN_THUMBL,            /* L3 */
-       [0x5b] = BTN_TR,                /* R1 */
-       [0x59] = BTN_TR2,               /* R2 */
-       [0x52] = BTN_THUMBR,            /* R3 */
+       [0x5a] = KEY_F1,                /* L1 */
+       [0x58] = KEY_F2,                /* L2 */
+       [0x51] = KEY_F3,                /* L3 */
+       [0x5b] = KEY_F4,                /* R1 */
+       [0x59] = KEY_F5,                /* R2 */
+       [0x52] = KEY_F6,                /* R3 */
        [0x43] = KEY_HOMEPAGE,          /* PS button */
-       [0x50] = KEY_SELECT,
-       [0x53] = BTN_START,
-       [0x33] = KEY_REWIND,            /* scan back */
+       [0x50] = KEY_INSERT,            /* select */
+       [0x53] = KEY_HOME,              /* start */
+       [0x33] = KEY_R,                 /* scan back */
        [0x32] = KEY_PLAY,
-       [0x34] = KEY_FORWARD,           /* scan forward */
-       [0x30] = KEY_PREVIOUS,
-       [0x38] = KEY_STOP,
-       [0x31] = KEY_NEXT,
-       [0x60] = KEY_FRAMEBACK,         /* slow/step back */
-       [0x39] = KEY_PAUSE,
-       [0x61] = KEY_FRAMEFORWARD,      /* slow/step forward */
+       [0x34] = KEY_F,                 /* scan forward */
+       [0x30] = KEY_PAGEDOWN,          /* next */
+       [0x38] = KEY_STOP,              /* stop */
+       [0x31] = KEY_PAGEUP,            /* previous */
+       [0x60] = KEY_COMMA,             /* slow/step back */
+       [0x39] = KEY_PLAYPAUSE,         /* pause */
+       [0x61] = KEY_DOT,               /* slow/step forward */
        [0xff] = KEY_MAX,
};

@@ -208,18 +208,49 @@
                                                lastmask & 0xff, lastkey);
        return -1;
}
+static gboolean ps3remote_sendkey(int uinput, unsigned int key,
+                                 unsigned int value)
+{
+       struct uinput_event event;
+       memset(&event, 0, sizeof(event));
+       gettimeofday(&event.time, NULL);
+       event.type = EV_KEY;
+       event.code = key;
+       event.value = value;
+       if (write(uinput, &event, sizeof(event)) != sizeof(event)) {
+               error("Error writing to uinput device");
+               return FALSE;
+       }

+       memset(&event, 0, sizeof(event));
+       gettimeofday(&event.time, NULL);
+       event.type = EV_SYN;
+       event.code = SYN_REPORT;
+       if (write(uinput, &event, sizeof(event)) != sizeof(event)) {
+               error("Error writing to uinput device");
+               return FALSE;
+       }
+       return TRUE;
+}
static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
                                gpointer data)
{
+       static unsigned int lastkey = 0;
+       static unsigned int lastval = 0;
        struct fake_input *fake = data;
-       struct uinput_event event;
        unsigned int key, value = 0;
        gsize size;
        char buff[50];

-       if (cond & G_IO_NVAL)
-               return FALSE;
+       if (cond & G_IO_NVAL) {
+               if(lastkey == KEY_HOMEPAGE && lastval == 1) {
+                       DBG("ps3remote_event: Remote turned off");
+                       goto failed;
+               } else {
+                       DBG("ps3remote_event: Remote unpaired [%u:%u]", lastkey, lastval);
+                       goto failed;
+               }
+       }

        if (cond & (G_IO_HUP | G_IO_ERR)) {
                error("Hangup or error on rfcomm server socket");
@@ -240,26 +271,18 @@
                goto failed;
        } else if (key == KEY_MAX)
                return TRUE;
-
-       memset(&event, 0, sizeof(event));
-       gettimeofday(&event.time, NULL);
-       event.type = EV_KEY;
-       event.code = key;
-       event.value = value;
-       if (write(fake->uinput, &event, sizeof(event)) != sizeof(event)) {
-               error("Error writing to uinput device");
+       /* Delaying key till release, assuming possible turn-off */
+       if(key == KEY_HOMEPAGE) {
+               if(value == 0 && lastkey == KEY_HOMEPAGE && lastval == 1) {
+                       ps3remote_sendkey(fake->uinput, key, 1);
+                       ps3remote_sendkey(fake->uinput, key, 0);
+               } else
+                       DBG("ps3remote_event: Delayed: %u:%u (%u:%u)", key, value, lastkey, lastval);
+       } else if(!ps3remote_sendkey(fake->uinput, key, value))
                goto failed;
-       }
-
-       memset(&event, 0, sizeof(event));
-       gettimeofday(&event.time, NULL);
-       event.type = EV_SYN;
-       event.code = SYN_REPORT;
-       if (write(fake->uinput, &event, sizeof(event)) != sizeof(event)) {
-               error("Error writing to uinput device");
-               goto failed;
-       }
-
+       lastkey = key;
+       lastval = value;
+       DBG("ps3remote_event: %u:%u", key, value);
        return TRUE;

failed:
@@ -267,7 +290,7 @@
        close(fake->uinput);
        fake->uinput = -1;
        g_io_channel_unref(fake->io);
-
+       DBG("ps3remote_event: !!!!");
        return FALSE;
}

Here is little customization i'm using in my userdata/Keymaps.xml
Code:
<keymap>
<global>
  <keyboard>
        <insert>Queue</insert>
        <a>AudioNextLanguage</a>
        <x>Close</x>
        <f1>VolumeDown</f1>
        <f4>VolumeUp</f4>
        <f2>SetVolume(50)</f2>
        <f3>SetVolume(75)</f3>
        <d>FullScreen</d>
        <t>ActivateWindow(Favourites)</t>
        <f7>XBMC.ActivateWindow(MyMusic)</f7>
        <f8>XBMC.ActivateWindow(MyVideos)</f8>
        <f9>XBMC.ActivateWindow(MyPictures)</f9>
        <f10>XBMC.ActivateWindow(Weather)</f10>
        <f11>ContextMenu</f11>
        <end>XBMC.ActivateWindow(ShutdownMenu)</end>
  </keyboard>
   </global>
<FullscreenVideo>
    <keyboard>
        <f12>NextSubtitle</f12>
        <menu>ShowVideoMenu</menu>
    </keyboard>
</FullscreenVideo>
</keymap>
Thus, you don't need Lirc for this, remote is seen as simple keyboard and is sending generic keyboard's scancodes, which could be easily customized in Keymaps.xml
Ability to turn off the remote controller (holding PS button for 7 secs) allows to save batteries.
Reply
#38
Asure Wrote:I didn't have any accelleration in desktop, so i was assuming i'd need to figure out another way to get it to work. Even though the glx shows up in X logs. Guess desktop wasn't using it ?

Trex6662k5: Are you running 9.04 with working bdremoted/lirc ? Or another flavor of linux ?

Edit: Guess i needed to switch on 'use restricted drivers' if google is correct:
https://help.ubuntu.com/community/Binary...wto/Nvidia

Running a minimal Hardy Ubuntu installation on an ION machine with BDRemoted.

You need to update to the latest nvidia driver but that will conflict with an exsisting nvidia driver that arrives with ubuntu. You can blacklist the driver or remove the restricted package in order to load the latest nvidia driver. Then you need to compile xbmc from svn to get vdpau working. IIRC Hardy builds don't have vdpau enabled.
Reply
#39
I've given up. I went to back to the drawing board, minimal hardy, removed the nvidia stuff, dropped in glx-190 and compiled from svn after manually adding vpdau devel stuff. That worked great, with vdpau working. Except, bluetooth fails to work for me for some reason i don't understand. No errors in any logs. Tried 3 dongles, all blink, rebooted several times etc..

It still works fine with ps3_remote.py.. which i don't get..

I guess i'm off to the store on monday for a MCE reciever or something. The BD remote would be used for my ps3 for now Smile

There is a way out though. If someone good at python would use the 'stopablethread' stuff inside ps3d.py to create a version of ps3_remote.py that can time-out, i would be sorted. I'm no good at python though Sad (Otherwise i do that myself.)
Reply
#40
Using the latest BlueZ 4.47 we can use the remote as a standard keyboard thanks to fakehid. This works almost out of the box, except for the keys that have a keycode above 255 since X can't handle those. Take a look at the post above by Ruff, for the fakehid patch. A different approach is to use evrouter to map the keys. I'm also looking into Gizmod but both seem to struggle with XBMC running as a standalone X session.
Reply
#41
Let me be the first to say: Great first post Ruff !

I took your 'power off' as inspiration and hackup up ps3_remote.py a bit :
Code:
if xbmc.previous_key == "43":
        remote.close()
        xbmc.send_notification("Notice", "Disconnecting Remote")
It triggers after a few presses of the PS button and generates an exception Smile
Then ps3_remote.py drops back to the terminal.. to keep it going i made a 'remote.sh' and dropped a call to it into rc.local :
Code:
#!/bin/bash
while [ 1 ]
do
  /usr/share/python-support/xbmc-eventclients-common/xbmc/ps3_remote.py localhost
done
When ps3_remote.py drops back to bash after pressing PS button, it will disconnect first, then get restarted.

Sidenote: I fixed up the notifications since eventserver is somewhat broken, and it now only sends a notification on connect and exit. (otherwise it beeps all the time on each eventserver-notification message)

Still, a version that times out would be cleaner.. need to brush up my python-skillz..
Reply
#42
Asure Wrote:Let me be the first to say: Great first post Ruff !
Thanks %)
Asure Wrote:Sidenote: I fixed up the notifications since eventserver is somewhat broken, and it now only sends a notification on connect and exit. (otherwise it beeps all the time on each eventserver-notification message)

Still, a version that times out would be cleaner.. need to brush up my python-skillz..
I also noticed that it is somewhat broken, that's why I became determined to hack bluez. That is - when xbmc sees new input device - all events sent by eventclient are ignored by event server. It only detects Hello/bye packets, and all key events are lost in vain (timed out).
Bluez, on the other hand, is lowlevel, it correctly handles pairing, it sends all necessary hal/dbus notifications... just incorrectly handles unpairing and sends keyevents, xbmc is not aware of %) Also this stickiness of xbmc to new input device allows to forget about all other devices. Even if you plugged usb keyboard to htpc for some reason, just hold ps to unpair and hit it once again to pair - and voilà
Of course, I'd rather prefer ps3bd to be detected as remote controller to use more explicit mappings of <remote> sections in Keymaps.xml. On the other hand, this keyboard driver allows me to launch xbmc from desktop using gnome's keybindings, as I'm turning off xbmc while going to work, to make cpu idle and save the power %)
Reply
#43
Asure Wrote:I've given up. I went to back to the drawing board, minimal hardy, removed the nvidia stuff, dropped in glx-190 and compiled from svn after manually adding vpdau devel stuff. That worked great, with vdpau working. Except, bluetooth fails to work for me for some reason i don't understand. No errors in any logs. Tried 3 dongles, all blink, rebooted several times etc..

Pair the remote first. Then stop bluetooth, launch sudo bdremoted, launch sudo lircd then restart bluetooth, then check irw.
Reply
#44
What exactly is the advantage of using XBMC's EventClient support? As far as I know it sends events to XBMC and show notifications on screen when something happens to the input device?

As far as I know i'm not using EventClient (does XBMC load it under the hood?). The remote is working fine as a keyboard, using Bluez and uinput. I don't get any notifications in XBMC about the remote, but do I need any?. It is connected at boot and works for as long as the machine is running so there's nothing to notify me about.

I've hooked up a multimeter to the remote to check power usage. Compared to the PS3, it does use more power overall. I guess the wireless connection with a PS3 is more finetuned than the connection with a generic USB bluetooth dongle. After about 30 mins the remote seems to enter a low-power state all by itself.

The only minor issue I'm having is with the keys on the remote with keycodes >255. The fakehid driver is the culprit here, as Ruff pointed out. In my opinion all problematic keys should be mapped to some normal keyboard letter instead of being ignored. That way anyone who isn't satisfied with the mapping can use gizmod, evrouter, keymap.xml etc. to change it to their liking, without having to recompile fakehid.c.
Reply
#45
Well, my initial intention to modify fakehid was to fix unpairing and manual remote turn-off with ps key. And at the same time I remapped the keys to avoid additional daemons and configurations %)
Reply
  • 1
  • 2
  • 3(current)
  • 4
  • 5
  • 56

Logout Mark Read Team Forum Stats Members Help
[LINUX] Sony PlayStation 3 Blu-ray Disc Remote (PS3 BD) + LIRC + XBMC = SUCCESS6