wiiリモコンのモジュール

wiiリモコンのモジュールを載せてなかったですね。
説明するのが、面倒だから、後回しにしてました。
前に作ったから、使い方も忘れちゃいました。
でも、せっかく作ったから、説明ないけど載せときます。
多分、テストしたと思うけど、おかしかったら直して使ってください。
以前のブログは2011年3月にあります。

#!usr/bin/env ruby

require 'ffi'

module CwiidFFI
extend FFI::Library
ffi_lib '/usr/local/lib/libcwiid.so.1.0'

# Flags
CWIID_FLAG_MESG_IFC = 0x01
CWIID_FLAG_CONTINUOUS = 0x02
CWIID_FLAG_REPEAT_BTN = 0x04
CWIID_FLAG_NONBLOCK = 0x08
CWIID_FLAG_MOTIONPLUS = 0x10

# Report Mode Flags
CWIID_RPT_STATUS = 0x01
CWIID_RPT_BTN = 0x02
CWIID_RPT_ACC = 0x04
CWIID_RPT_IR = 0x08
CWIID_RPT_NUNCHUK = 0x10
CWIID_RPT_CLASSIC = 0x20
CWIID_RPT_BALANCE = 0x40
CWIID_RPT_MOTIONPLUS = 0x80
CWIID_RPT_EXT = CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC |
CWIID_RPT_BALANCE | CWIID_RPT_MOTIONPLUS

# LED flags
CWIID_LED1_ON = 0x01
CWIID_LED2_ON = 0x02
CWIID_LED3_ON = 0x04
CWIID_LED4_ON = 0x08

# Button flags
CWIID_BTN_2 = 0x0001
CWIID_BTN_1 = 0x0002
CWIID_BTN_B = 0x0004
CWIID_BTN_A = 0x0008
CWIID_BTN_MINUS = 0x0010
CWIID_BTN_HOME = 0x0080
CWIID_BTN_LEFT = 0x0100
CWIID_BTN_RIGHT = 0x0200
CWIID_BTN_DOWN = 0x0400
CWIID_BTN_UP = 0x0800
CWIID_BTN_PLUS = 0x1000

enum :cwiid_ext_type, [
:CWIID_EXT_NONE,
:CWIID_EXT_NUNCHUK,
:CWIID_EXT_CLASSIC,
:CWIID_EXT_BALANCE,
:CWIID_EXT_MOTIONPLUS,
:CWIID_EXT_UNKNOWN
]

enum :cwiid_error,[
:CWIID_ERROR_NONE,
:CWIID_ERROR_DISCONNECT,
:CWIID_ERROR_COMM
]
class AccCal < FFI::Struct
layout :zero, [:uint16,3],
:one, [:uint16,3]
end

class BalanceCal < FFI::Struct
layout :right_top, [:uint16,3],
:right_bottom, [:uint16,3],
:left_top, [:uint16,3],
:left_bottom, [:uint16,3]
end

class CwiidIrSrc < FFI::Struct
layout :valid, :char,
:pos, [:uint16, 2],
:size, :uint8
end

class NunchuckState < FFI::Struct
layout :stick, [:uint8, 2],
:acc, [:uint8, 3],
:buttons, :uint8
end

class ClassicState < FFI::Struct
layout :l_stick, [:uint8, 2],
:r_stick, [:uint8, 2],
:l, :uint8,
:r, :uint8,
:buttons, :uint16
end


class BalanceState < FFI::Struct
layout :right_top, :uint16,
:right_bottom, :uint16,
:left_top, :uint16,
:left_bottom, :uint16
end

class MotionplusState < FFI::Struct
layout :angle_rate, [:uint16, 3],
:low_speed, [:uint8,3]
end

class ExtState < FFI::Union
layout :nunchuck, NunchuckState,
:classic, ClassicState,
:balance, BalanceState,
:motionplus, MotionplusState
end


class CwiidState < FFI::Struct
layout :rpt_mode, :uint8,
:led, :uint8,
:rumble, :uint8,
:battery, :uint8,
:buttons, :uint16,
:acc, [:uint8, 3],
:ir_src, [CwiidIrSrc, 4,],
:ext_type, :cwiid_ext_type,
:ext, ExtState,
:error, :cwiid_error
end

attach_function :str2ba,[:string,:pointer],:int
attach_function :cwiid_open,[:pointer,:int],:pointer
attach_function :cwiid_close,[:pointer],:int
attach_function :cwiid_set_rumble,[:pointer,:int],:int
attach_function :cwiid_set_led,[:pointer,:int],:int
attach_function :cwiid_get_acc_cal,[:pointer,:cwiid_ext_type,AccCal],:int
attach_function :cwiid_get_balance_cal,[:pointer,BalanceCal],:int
attach_function :cwiid_set_rpt_mode,[:pointer,:uint8],:int
attach_function :cwiid_get_state, [:pointer, CwiidState], :int
end
[PR]
by gaziya | 2011-05-28 21:38