class Rjoystick::Device
Public Class Methods
new(p1)
click to toggle source
VALUE js_dev_init(VALUE klass, VALUE dev_path) { int *fd; if((fd = malloc(sizeof(int))) != NULL) { if((*fd = open(RSTRING_PTR(dev_path), O_RDONLY)) >= 0) { if(*fd >= MAX_JS) rb_raise(rb_eException, "Error"); return Data_Wrap_Struct(klass, jsdevice_mark, jsdevice_free, fd); } } return Qnil; }
Public Instance Methods
axes()
click to toggle source
VALUE js_dev_axes(VALUE klass) { int *fd; unsigned char axes; Data_Get_Struct(klass, int, fd); if(ioctl(*fd, JSIOCGAXES, &axes) == -1) { rb_raise(rb_eException, "cannot retrive axes"); } return INT2FIX(axes); }
axes_maps()
click to toggle source
VALUE js_dev_axes_maps(VALUE klass) { int *fd; uint8_t axes_maps[ABS_MAX + 1]; Data_Get_Struct(klass, int, fd); if(ioctl(*fd, JSIOCGAXMAP, &axes_maps) == -1) { rb_raise(rb_eException, "cannot retrive axes"); } return INT2FIX(axes_maps); }
close()
click to toggle source
VALUE js_dev_close(VALUE klass) { int *fd; Data_Get_Struct(klass, int, fd); close(*fd); return Qnil; }
event()
click to toggle source
VALUE js_dev_event_get(VALUE klass) { int * fd; struct js_dev_blocking_read_param jdbrp; Data_Get_Struct(klass, int, fd); jdbrp.fd = *fd; jdbrp.result = 0; // kill thread if called, otherwise just return the event or nil rb_thread_blocking_region(js_dev_blocking_read, &jdbrp, RUBY_UBF_IO, NULL); if( jdbrp.result > 0) { jse[jdbrp.fd] = jdbrp.event; return Data_Wrap_Struct(rb_cEvent, 0, 0, fd); } else { return Qnil; } }
name()
click to toggle source
VALUE js_dev_name(VALUE klass) { int *fd; char name[NAME_LENGTH] = "Unknow"; Data_Get_Struct(klass, int, fd); if(ioctl(*fd, JSIOCGNAME(NAME_LENGTH), name) == -1) { rb_raise(rb_eException, "cannot retrieve name"); } return rb_str_new2(name); }
version()
click to toggle source
VALUE js_dev_version(VALUE klass) { int *fd; int version = 0x000800; char js_version[16]; Data_Get_Struct(klass, int, fd); if(ioctl(*fd, JSIOCGVERSION, &version) == -1) { rb_raise(rb_eException, "version error"); } sprintf(js_version, "%d.%d.%d\n", version >> 16, (version >> 8) & 0xff, version & 0xff); return rb_str_new2(js_version); }