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



185
186
187
188
189
190
191
192
# File 'ext/rjoystick.c', line 185

VALUE js_dev_close(VALUE klass)
{
	int *fd;

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

#eventObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'ext/rjoystick.c', line 161

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

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