Sha256: a3850e2b397e7a3580c41a878e6b3f083ee899dbfc83f13be9c20baffe000dea

Contents?: true

Size: 1.73 KB

Versions: 11

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/env ruby

require 'cwiid'
require 'drb/drb'

require "rabbit/console"

def parse(args=ARGV, logger=nil)
  Rabbit::Console.parse!(args, logger) do |opts, options|
    options.rabbit_uri = "druby://localhost:10101"

    opts.separator ""

    opts.on("--rabbit-uri=URI",
            "Rabbit's dRuby URI",
            "(#{options.rabbit_uri})") do |uri|
      options.rabbit_uri = uri
    end
  end
end

def accept_wiimote(wiimote, rabbit, logger)
  leds = [WiiMote::LED1_ON, WiiMote::LED2_ON, WiiMote::LED3_ON, WiiMote::LED4_ON,
          WiiMote::LED3_ON, WiiMote::LED2_ON]
  led_count = 0
  n_looped = 0

  buttons_prev = 0
  loop do
    buttons_prev = wiimote.buttons
    wiimote.get_state
    buttons_state = wiimote.buttons - (wiimote.buttons & buttons_prev)

    n_looped = (n_looped + 1) % 20
    if n_looped.zero?
      led_count = (led_count + 1) % leds.size
      wiimote.led = leds[led_count]
    end

    case buttons_state
    when WiiMote::BTN_A
      rabbit.move_to_next_if_can
    when WiiMote::BTN_B
      rabbit.move_to_previous_if_can
    when WiiMote::BTN_RIGHT
      rabbit.move_to_next_slide_if_can
    when WiiMote::BTN_LEFT
      rabbit.move_to_previous_slide_if_can
    when WiiMote::BTN_UP
      rabbit.move_to_first
    when WiiMote::BTN_DOWN
      rabbit.move_to_last
    when WiiMote::BTN_HOME
      rabbit.toggle_fullscreen
    when WiiMote::BTN_PLUS
      rabbit.toggle_index_mode
    when WiiMote::BTN_MINUS
      rabbit.toggle_whiteout
    end

    sleep 0.1
  end
end

def main
  options, logger = parse

  wiimote = WiiMote.new
  wiimote.rpt_mode = WiiMote::RPT_BTN
  wiimote.led = WiiMote::LED1_ON | WiiMote::LED4_ON

  rabbit = DRbObject.new_with_uri(options.rabbit_uri)

  accept_wiimote(wiimote, rabbit, logger)
end

main

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rabbit-1.0.9 bin/rabwii
rabbit-1.0.8 bin/rabwii
rabbit-1.0.7 bin/rabwii
rabbit-1.0.6 bin/rabwii
rabbit-1.0.5 bin/rabwii
rabbit-1.0.4 bin/rabwii
rabbit-1.0.3 bin/rabwii
rabbit-1.0.2 bin/rabwii
rabbit-1.0.1 bin/rabwii
rabbit-1.0.0 bin/rabwii
rabbit-0.9.3 bin/rabwii