You are not logged in.

#1 2011-07-01 02:12:05

bmentink
Member
From: New Zealand
Registered: 2009-08-23
Posts: 442

script to get a Wii remote power button working.

Hi All,

I have a Wii remote which I have setup and used with my media box (Arch Linux of course) running XBMC.

The remote works fine, but I want the power button to turn the screen on/off and the remote on/off as it is hungry on power being a bluetooth device.
I envisage it working like this using "wminput -w" and parsing the messages from stdout as you get a "Ready" when paired, and a "Exiting" when un-paired.

in psuedocode:
loop {

    wminput -w  // wait for remote to pair
   when "Ready" output is detected
       .. turn on display .. remote is working
   when "Exiting" output detected
       .. turn off display .. remote bluetooth is off when un-paired
}|

I imagine this can be done with a bash or ruby script quite easily ... any help much appreciated.

Cheers,
Bernie

Offline

#2 2011-07-01 04:57:03

bmentink
Member
From: New Zealand
Registered: 2009-08-23
Posts: 442

Re: script to get a Wii remote power button working.

Ok, I have found an answer to this by creating the following ruby script which works a treat.
To turn on the remote + screen, press the "1" and "2" buttons (which does the bluetooth pairing) ....
To turn off the remote + screen, press and hold the power button.
Hope this helps someone else with a wii remote ..

#!/usr/bin/ruby

require 'pty'

`killall wminput`       # Just in case!
loop {  # Loop forever.
cmd = "wminput -w"
begin
  PTY.spawn( cmd ) do |stdin, stdout, pid|
    begin
      # Do stuff with the output here.
      stdin.each { |line|
        if line.include? "Ready" then  # Remote has paired.
          # Enable the display
          `xset dpms force on` #.each_line {|debug| puts debug}
          `xset -dpms`

        end
        if line.include? "Exiting" then # Remote has un-paired
          # Turn the display off
          `xset dpms force off`
        end
      }
    rescue Errno::EIO
      # puts "Enter's here when wminput finishes"
    end
  end
rescue PTY::ChildExited
  # puts "The child process exited!"
end
}

Offline

Board footer

Powered by FluxBB