rjoystick 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGELOG +4 -0
  2. data/Manifest +1 -2
  3. data/README +16 -4
  4. data/ext/rjoystick.c +52 -21
  5. data/rjoystick.gemspec +4 -4
  6. metadata +24 -28
data/CHANGELOG CHANGED
@@ -1 +1,5 @@
1
+ 0.1.1 28-dec-2012
2
+
3
+ use rb_thread_blocking_region
4
+
1
5
  v0.1. rjoystick is now available as gem
data/Manifest CHANGED
@@ -1,9 +1,8 @@
1
1
  CHANGELOG
2
2
  LICENSE
3
+ Manifest
3
4
  README
4
5
  Rakefile
5
6
  ext/extconf.rb
6
7
  ext/rjoystick.c
7
- rjoystick.gemspec
8
8
  rjoystick.rb
9
- Manifest
data/README CHANGED
@@ -1,5 +1,17 @@
1
- Rjoystick - Ruby c binding to linux/joystick event
2
- Copyright (c) 2008 Claudio Fiorini <claudio@cfiorini.it>
1
+ Now uses rb_thread_blocking_region to read events (not for sixaxis).
2
+ That way you can read events in another thread without locking up the whole RVM:
3
+
4
+ dev = Rjoystick::Device.new '/dev/input/js0'
5
+
6
+ Thread.new do
7
+ dev.event
8
+ end
9
+
10
+ which is useful when you want to build another object that
11
+ holds the current joystick state to be queried anytime.
12
+
13
+ Rjoystick - Ruby c binding to linux/joystick event
14
+ Copyright (c) 2008 Claudio Fiorini <claudio@cfiorini.it>
3
15
 
4
16
  FIRST OF ALL
5
17
  thanks to Ruby core developer, Linux kernel developer and
@@ -22,8 +34,8 @@ To install the code just run:
22
34
  1st example works ok with all joysticks that are good for linux.
23
35
  2nd example is only for PlayStation 3(copyright Sony) Sixaxis controller
24
36
  because gets 3-Axis accelerometer values and to get it works follow
25
- this tutorial first https://help.ubuntu.com/community/Sixaxis and
26
- you can use it in BT mode :)
37
+ this tutorial first https://help.ubuntu.com/community/Sixaxis and
38
+ you can use it in BT mode :)
27
39
 
28
40
 
29
41
  Sixaxis has a gyroscope but for now you can't get values from it with
data/ext/rjoystick.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Rjoystick - Ruby binding for linux kernel joystick
2
+ * Rjoystick - Ruby binding for linux kernel joystick
3
3
  * Copyright (C) 2008 Claudio Fiorini <claudio@cfiorini.it>
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -66,15 +66,15 @@ void jssix_free(int* fh)
66
66
  VALUE js_dev_init(VALUE klass, VALUE dev_path)
67
67
  {
68
68
  int *fd;
69
-
69
+
70
70
  if((fd = malloc(sizeof(int))) != NULL) {
71
71
  if((*fd = open(RSTRING_PTR(dev_path), O_RDONLY)) >= 0) {
72
72
  if(*fd >= MAX_JS)
73
73
  rb_raise(rb_eException, "Error");
74
-
74
+
75
75
  return Data_Wrap_Struct(klass, jsdevice_mark, jsdevice_free, fd);
76
76
  }
77
- }
77
+ }
78
78
  return Qnil;
79
79
  }
80
80
 
@@ -135,27 +135,57 @@ VALUE js_dev_version(VALUE klass)
135
135
  if(ioctl(*fd, JSIOCGVERSION, &version) == -1) {
136
136
  rb_raise(rb_eException, "version error");
137
137
  }
138
-
139
- sprintf(js_version, "%d.%d.%d\n",
138
+
139
+ sprintf(js_version, "%d.%d.%d\n",
140
140
  version >> 16, (version >> 8) & 0xff, version & 0xff);
141
141
 
142
142
  return rb_str_new2(js_version);
143
143
  }
144
144
 
145
+ struct js_dev_blocking_read_param
146
+ {
147
+ int fd;
148
+ struct js_event event;
149
+ int result;
150
+ };
151
+
152
+ VALUE js_dev_blocking_read( void * param )
153
+ {
154
+ struct js_dev_blocking_read_param * jdbrp = (struct js_dev_blocking_read_param*)param;
155
+
156
+ jdbrp->result = read( jdbrp->fd, &jdbrp->event, sizeof(struct js_event) );
157
+
158
+ return Qnil;
159
+ }
160
+
145
161
  VALUE js_dev_event_get(VALUE klass)
146
162
  {
147
- int *fd;
163
+ int * fd;
164
+ struct js_dev_blocking_read_param jdbrp;
165
+
148
166
  Data_Get_Struct(klass, int, fd);
149
- if(read(*fd, &jse[*fd], sizeof(struct js_event)) > 0)
167
+
168
+ jdbrp.fd = *fd;
169
+ jdbrp.result = 0;
170
+
171
+ // kill thread if called, otherwise just return the event or nil
172
+ rb_thread_blocking_region(js_dev_blocking_read, &jdbrp, RUBY_UBF_IO, NULL);
173
+
174
+ if( jdbrp.result > 0)
175
+ {
176
+ jse[jdbrp.fd] = jdbrp.event;
150
177
  return Data_Wrap_Struct(rb_cEvent, 0, 0, fd);
151
-
152
- return Qnil;
178
+ }
179
+ else
180
+ {
181
+ return Qnil;
182
+ }
153
183
  }
154
184
 
155
185
  VALUE js_dev_close(VALUE klass)
156
186
  {
157
187
  int *fd;
158
-
188
+
159
189
  Data_Get_Struct(klass, int, fd);
160
190
  close(*fd);
161
191
  return Qnil;
@@ -179,7 +209,7 @@ VALUE js_event_time(VALUE klass)
179
209
  {
180
210
  int *fd;
181
211
  Data_Get_Struct(klass, int, fd);
182
- return INT2FIX((fd && *fd >= 0) ? jse[*fd].time : -1);
212
+ return INT2FIX((fd && *fd >= 0) ? jse[*fd].time : 0);
183
213
  }
184
214
 
185
215
  VALUE js_event_value(VALUE klass)
@@ -193,12 +223,12 @@ VALUE js_six_init(VALUE klass, VALUE path)
193
223
  {
194
224
  int *fh;
195
225
  if((fh = malloc(sizeof(int))) != NULL) {
196
- if((*fh = open(RSTRING_PTR(path), O_RDONLY)) >= 0) {
226
+ if((*fh = open(RSTRING_PTR(path), O_RDONLY)) >= 0) {
197
227
  return Data_Wrap_Struct(klass, jssix_mark, jssix_free, fh);
198
228
  } else
199
229
  rb_raise(rb_eException, "Error opening %s", RSTRING_PTR(path));
200
230
  }
201
- return Qnil;
231
+ return Qnil;
202
232
  }
203
233
 
204
234
  VALUE js_six_get_six(VALUE klass)
@@ -224,9 +254,9 @@ VALUE js_six_get_six(VALUE klass)
224
254
  z = buf[45]<<8 | buf[46];
225
255
  }
226
256
 
227
- rb_hash_aset(saxis, ID2SYM(rb_intern("x")), INT2FIX(x));
228
- rb_hash_aset(saxis, ID2SYM(rb_intern("y")), INT2FIX(y));
229
- rb_hash_aset(saxis, ID2SYM(rb_intern("z")), INT2FIX(z));
257
+ rb_hash_aset(saxis, ID2SYM(rb_intern("x")), INT2FIX(x));
258
+ rb_hash_aset(saxis, ID2SYM(rb_intern("y")), INT2FIX(y));
259
+ rb_hash_aset(saxis, ID2SYM(rb_intern("z")), INT2FIX(z));
230
260
 
231
261
  return saxis;
232
262
  } else
@@ -238,7 +268,7 @@ VALUE js_six_get_six(VALUE klass)
238
268
  VALUE js_six_close(VALUE klass)
239
269
  {
240
270
  int *fh;
241
-
271
+
242
272
  Data_Get_Struct(klass, int, fh);
243
273
 
244
274
  return INT2FIX(close(*fh));
@@ -258,17 +288,18 @@ void Init_rjoystick()
258
288
  rb_define_method(rb_cDevice, "event", js_dev_event_get, 0);
259
289
  rb_define_method(rb_cDevice, "close", js_dev_close, 0);
260
290
 
261
- rb_cEvent = rb_define_class_under(rb_mRjoystick, "Event", rb_cObject);
291
+ rb_cEvent = rb_define_class_under(rb_mRjoystick, "Event", rb_cObject);
262
292
  rb_define_method(rb_cEvent, "time", js_event_time, 0);
263
293
  rb_define_method(rb_cEvent, "value", js_event_value, 0);
264
294
  rb_define_method(rb_cEvent, "number", js_event_number, 0);
265
295
  rb_define_method(rb_cEvent, "type", js_event_type, 0);
266
-
296
+
267
297
  rb_cSixaxis = rb_define_class_under(rb_mRjoystick, "SixAxis", rb_cObject);
268
298
  rb_define_singleton_method(rb_cSixaxis, "new", js_six_init, 1);
269
- rb_define_method(rb_cSixaxis, "get_sixaxis", js_six_get_six, 0);
299
+ rb_define_method(rb_cSixaxis, "get_sixaxis", js_six_get_six, 0);
270
300
  rb_define_method(rb_cSixaxis, "close", js_six_close, 0);
271
301
 
272
302
  rb_define_const(rb_cEvent, "JSBUTTON", INT2FIX(JS_EVENT_BUTTON));
273
303
  rb_define_const(rb_cEvent, "JSAXIS", INT2FIX(JS_EVENT_AXIS));
304
+ rb_define_const(rb_cEvent, "JSINIT", INT2FIX(JS_EVENT_INIT));
274
305
  }
data/rjoystick.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rjoystick}
5
- s.version = "0.1"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Claudio Fiorini}]
9
- s.date = %q{2011-07-06}
8
+ s.authors = ['Claudio Fiorini', 'Christian Vervoorts', 'John Anderson']
9
+ s.date = %q{2012-12-28}
10
10
  s.description = %q{Ruby binding for linux kernel joystick}
11
11
  s.email = %q{claudio.fiorini@gmail.com}
12
12
  s.extensions = [%q{ext/extconf.rb}]
13
13
  s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README}, %q{ext/extconf.rb}, %q{ext/rjoystick.c}]
14
14
  s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README}, %q{Rakefile}, %q{ext/extconf.rb}, %q{ext/rjoystick.c}, %q{rjoystick.rb}, %q{rjoystick.gemspec}]
15
- s.homepage = %q{https://github.com/cfiorini/rjoystick}
15
+ s.homepage = %q{https://github.com/djellemah/rjoystick}
16
16
  s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Rjoystick}, %q{--main}, %q{README}]
17
17
  s.require_paths = [%q{ext}]
18
18
  s.rubyforge_project = %q{rjoystick}
metadata CHANGED
@@ -1,31 +1,30 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rjoystick
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
4
5
  prerelease:
5
- version: "0.1"
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Claudio Fiorini
9
+ - Christian Vervoorts
10
+ - John Anderson
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
-
13
- date: 2011-07-06 00:00:00 Z
14
+ date: 2012-12-28 00:00:00.000000000 Z
14
15
  dependencies: []
15
-
16
16
  description: Ruby binding for linux kernel joystick
17
17
  email: claudio.fiorini@gmail.com
18
18
  executables: []
19
-
20
- extensions:
19
+ extensions:
21
20
  - ext/extconf.rb
22
- extra_rdoc_files:
21
+ extra_rdoc_files:
23
22
  - CHANGELOG
24
23
  - LICENSE
25
24
  - README
26
25
  - ext/extconf.rb
27
26
  - ext/rjoystick.c
28
- files:
27
+ files:
29
28
  - CHANGELOG
30
29
  - LICENSE
31
30
  - Manifest
@@ -35,37 +34,34 @@ files:
35
34
  - ext/rjoystick.c
36
35
  - rjoystick.rb
37
36
  - rjoystick.gemspec
38
- homepage: https://github.com/cfiorini/rjoystick
37
+ homepage: https://github.com/djellemah/rjoystick
39
38
  licenses: []
40
-
41
39
  post_install_message:
42
- rdoc_options:
40
+ rdoc_options:
43
41
  - --line-numbers
44
42
  - --inline-source
45
43
  - --title
46
44
  - Rjoystick
47
45
  - --main
48
46
  - README
49
- require_paths:
47
+ require_paths:
50
48
  - ext
51
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "1.2"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '1.2'
63
61
  requirements: []
64
-
65
62
  rubyforge_project: rjoystick
66
- rubygems_version: 1.8.5
63
+ rubygems_version: 1.8.24
67
64
  signing_key:
68
65
  specification_version: 3
69
66
  summary: Ruby binding for linux kernel joystick
70
67
  test_files: []
71
-