class Joystick::SixAxis
Public Class Methods
new(path)
click to toggle source
TODO
VALUE js_six_init(VALUE klass, VALUE path) { int *fh; if((fh = malloc(sizeof(int))) != NULL) { if((*fh = open(RSTRING_PTR(path), O_RDONLY)) >= 0) { return Data_Wrap_Struct(klass, jssix_mark, jssix_free, fh); } else rb_raise(rb_eException, "Error opening %s", RSTRING_PTR(path)); } return Qnil; }
Public Instance Methods
close(path)
click to toggle source
TODO
VALUE js_six_close(VALUE klass) { int *fh; Data_Get_Struct(klass, int, fh); return INT2FIX(close(*fh)); }
get_sixaxis()
click to toggle source
TODO
VALUE js_six_get_six(VALUE klass) { int *fh; int res; int x = -1; int y = -1; int z = -1; unsigned char buf[128]; VALUE saxis = rb_hash_new(); Data_Get_Struct(klass, int, fh); if(res = read(*fh, buf, sizeof(buf))) { if(res == 48) { x = buf[40]<<8 | buf[41]; y = buf[42]<<8 | buf[43]; z = buf[44]<<8 | buf[45]; } else if(res == 49) { x = buf[41]<<8 | buf[42]; y = buf[43]<<8 | buf[44]; z = buf[45]<<8 | buf[46]; } rb_hash_aset(saxis, ID2SYM(rb_intern("x")), INT2FIX(x)); rb_hash_aset(saxis, ID2SYM(rb_intern("y")), INT2FIX(y)); rb_hash_aset(saxis, ID2SYM(rb_intern("z")), INT2FIX(z)); return saxis; } else rb_raise(rb_eException, "error"); return Qnil; }