Class: Ruinput::UinputUserDev

Inherits:
Object
  • Object
show all
Includes:
Revdev::EachValuesEqual
Defined in:
lib/ruinput/uinput_user_dev.rb,
lib/ruinput.rb,
ext/ruinput/ruinput.c

Overview

import uinput_user_dev from uinput.h

struct uinput_user_dev

char name[UINPUT_MAX_NAME_SIZE];
struct input_id id;
int ff_effects_max;
int absmax[ABS_CNT];
int absmin[ABS_CNT];
int absfuzz[ABS_CNT];
int absflat[ABS_CNT];

;

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ UinputUserDev

TODO String class



24
25
26
27
28
29
30
31
32
33
# File 'lib/ruinput/uinput_user_dev.rb', line 24

def initialize arg=nil
  if arg.kind_of? Hash
    [:name, :id, :ff_effects_max, :absmax,
     :absmin, :absfuzz, :absflat].each do |n|
      instance_variable_set("@#{n}", arg[n] || arg[n.to_s])
    end
  elsif not arg.nil?
    raise ArgumentError, "expected a Hash"
  end
end

Instance Attribute Details

#absflatObject

Returns the value of attribute absflat.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def absflat
  @absflat
end

#absfuzzObject

Returns the value of attribute absfuzz.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def absfuzz
  @absfuzz
end

#absmaxObject

Returns the value of attribute absmax.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def absmax
  @absmax
end

#absminObject

Returns the value of attribute absmin.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def absmin
  @absmin
end

#ff_effects_maxObject

Returns the value of attribute ff_effects_max.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def ff_effects_max
  @ff_effects_max
end

#idObject

Returns the value of attribute id.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def id
  @id
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/ruinput/uinput_user_dev.rb', line 19

def name
  @name
end

Instance Method Details

#raw_initialize(bytes) ⇒ Object



45
46
47
48
49
50
51
52
# File 'ext/ruinput/ruinput.c', line 45

VALUE uinput_user_dev_raw_initalize(VALUE self, VALUE bytes)
{
  struct uinput_user_dev *uud;
  uud = RSTRING(bytes)->ptr;
  printf("name: %s, ff_effects_max: %d\n", uud->name, uud->ff_effects_max);
  printf("id.bustype: %d, id.version: %d\n", uud->id.bustype, uud->id.version);
  printf("firsts-> absmax: %d, absflat: %d \n", uud->absmax[0], uud->absflat[0]);
}

#to_byte_stringObject



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/ruinput/ruinput.c', line 54

VALUE uinput_user_dev_to_byte_string(VALUE self)
{
  struct uinput_user_dev uud;
  char* name;
  VALUE value_tmp;

  // TODO check @name size
  // @name
  value_tmp = rb_iv_get(self, "@name");
  if(TYPE(value_tmp) != T_STRING){
    type_exception("@name", "String");
    return Qnil;
  }
  strncpy(uud.name, StringValuePtr(value_tmp), UINPUT_MAX_NAME_SIZE);

  // @id
  value_tmp = rb_iv_get(self, "@id");
  if(TYPE(value_tmp) != T_OBJECT){
    type_exception("@id", "Revdev::UserId");
    return Qnil;
  }
  value_tmp = rb_funcall(value_tmp, rb_intern("to_byte_string"), 0);
  memcpy(&(uud.id), StringValuePtr(value_tmp), sizeof(struct input_id));

  // @ff_effects_max
  value_tmp = rb_iv_get(self, "@ff_effects_max");
  FIXNUM_P(value_tmp);
  uud.ff_effects_max = FIX2INT(value_tmp);

  // @absmax
  abs_array_cpy(uud.absmax, rb_iv_get(self, "@absmax"));

  // @absmin
  abs_array_cpy(uud.absmin, rb_iv_get(self, "@absmin"));

  // @absfuzz
  abs_array_cpy(uud.absfuzz, rb_iv_get(self, "@absfuzz"));

  // @absflat
  abs_array_cpy(uud.absflat, rb_iv_get(self, "@absflat"));

  return rb_str_new(&uud, sizeof(struct uinput_user_dev));
}