Class: Rjoystick::Device

Inherits:
Object
  • Object
show all
Defined in:
ext/rjoystick.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(dev_path) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/rjoystick.c', line 66

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;
}

Instance Method Details

#axesObject



81
82
83
84
85
86
87
88
89
90
91
# File 'ext/rjoystick.c', line 81

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_mapsObject



117
118
119
120
121
122
123
124
125
126
127
# File 'ext/rjoystick.c', line 117

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);
}

#buttonsObject



93
94
95
96
97
98
99
100
101
102
103
# File 'ext/rjoystick.c', line 93

VALUE js_dev_buttons(VALUE klass)
{
	int *fd;
	unsigned char buttons;
	Data_Get_Struct(klass, int, fd);
	if(ioctl(*fd, JSIOCGBUTTONS, &buttons) == -1) {
		rb_raise(rb_eException, "cannot retrieve buttons");
	}

	return INT2FIX(buttons);
}

#closeObject



155
156
157
158
159
160
161
162
# File 'ext/rjoystick.c', line 155

VALUE js_dev_close(VALUE klass)
{
	int *fd;
	
	Data_Get_Struct(klass, int, fd);
	close(*fd);
	return Qnil;
}

#eventObject



145
146
147
148
149
150
151
152
153
# File 'ext/rjoystick.c', line 145

VALUE js_dev_event_get(VALUE klass)
{
	int *fd;
	Data_Get_Struct(klass, int, fd);
	if(read(*fd, &jse[*fd], sizeof(struct js_event)) > 0)
		return Data_Wrap_Struct(rb_cEvent, 0, 0, fd);
	
	return Qnil;
}

#nameObject



105
106
107
108
109
110
111
112
113
114
115
# File 'ext/rjoystick.c', line 105

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);
}

#versionObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/rjoystick.c', line 129

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);
}