Class: Rjoystick::SixAxis
- Inherits:
-
Object
- Object
- Rjoystick::SixAxis
- Defined in:
- ext/rjoystick.c
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new(path) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'ext/rjoystick.c', line 222
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;
}
|
Instance Method Details
#close ⇒ Object
268 269 270 271 272 273 274 275 |
# File 'ext/rjoystick.c', line 268
VALUE js_six_close(VALUE klass)
{
int *fh;
Data_Get_Struct(klass, int, fh);
return INT2FIX(close(*fh));
}
|
#get_sixaxis ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'ext/rjoystick.c', line 234
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;
}
|