Class: Ruinput::UinputDevice
- Inherits:
-
Revdev::EventDevice
- Object
- Revdev::EventDevice
- Ruinput::UinputDevice
- Defined in:
- lib/ruinput/uinput_device.rb,
lib/ruinput.rb
Overview
a class for /dev/uinput
Constant Summary collapse
- DEFUALT_LOCATION =
"/dev/uinput"
- DEFAULT_DEVICE_NAME =
"ruinput"
- DEFAULT_INPUT_ID =
Revdev::InputId.new({ :bustype => Revdev::BUS_VIRTUAL, :vendor => 1, :product => 1, :version => 1 })
Instance Attribute Summary collapse
-
#is_created ⇒ Object
readonly
Returns the value of attribute is_created.
Instance Method Summary collapse
-
#create(name = DEFAULT_DEVICE_NAME, id = DEFAULT_INPUT_ID) ⇒ Object
- create virtual event divece name
- device name id
-
InputId (“struct input_id” on input.h).
- #destroy ⇒ Object
-
#initialize(location = nil) ⇒ UinputDevice
constructor
A new instance of UinputDevice.
- #set_all_events ⇒ Object
Constructor Details
#initialize(location = nil) ⇒ UinputDevice
Returns a new instance of UinputDevice.
18 19 20 21 22 |
# File 'lib/ruinput/uinput_device.rb', line 18 def initialize location=nil @is_created = false location ||= DEFUALT_LOCATION super location end |
Instance Attribute Details
#is_created ⇒ Object (readonly)
Returns the value of attribute is_created.
9 10 11 |
# File 'lib/ruinput/uinput_device.rb', line 9 def is_created @is_created end |
Instance Method Details
#create(name = DEFAULT_DEVICE_NAME, id = DEFAULT_INPUT_ID) ⇒ Object
create virtual event divece
- name
-
device name
- id
-
InputId (“struct input_id” on input.h)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruinput/uinput_device.rb', line 27 def create name = DEFAULT_DEVICE_NAME, id = DEFAULT_INPUT_ID if not name.kind_of? String raise ArgumentError, "1st arg expect String" elsif not id.kind_of? Revdev::InputId raise ArgumentError, "2nd arg expect Revdev::InputId" end uud = UinputUserDev.new({ :name => name, :id => id, :ff_effects_max => 0, :absmax => [20], :absmin => [30], :absfuzz => [4], :absflat => [5] }) @file.syswrite uud.to_byte_string set_all_events @file.ioctl UI_DEV_CREATE, nil @is_created = true end |
#destroy ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ruinput/uinput_device.rb', line 46 def destroy if not @is_created raise Exception, "invalid method call: this uinput is not created" end @file.ioctl UI_DEV_DESTROY, nil @file.close end |
#set_all_events ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruinput/uinput_device.rb', line 54 def set_all_events if @is_created raise Exception, "invalid method call: this uinput is already created" end @file.ioctl UI_SET_EVBIT, Revdev::EV_KEY Revdev::KEY_CNT.times do |i| @file.ioctl UI_SET_KEYBIT, i end @file.ioctl UI_SET_EVBIT, Revdev::EV_MSC Revdev::MSC_CNT.times do |i| @file.ioctl UI_SET_MSCBIT, i end @file.ioctl UI_SET_EVBIT, Revdev::EV_MSC Revdev::MSC_CNT.times do |i| @file.ioctl UI_SET_MSCBIT, i end @file.ioctl UI_SET_EVBIT, Revdev::EV_ABS Revdev::ABS_CNT.times do |i| @file.ioctl UI_SET_ABSBIT, i end @file.ioctl UI_SET_EVBIT, Revdev::EV_REP end |