Class: MyHIDAPI::Handle
- Inherits:
-
Object
- Object
- MyHIDAPI::Handle
- Defined in:
- ext/myhidapi/myhidapi.c
Instance Method Summary collapse
- #manufacturer ⇒ Object
- #product ⇒ Object
- #read(size) ⇒ Object
- #read_timeout(size, timeout_ms) ⇒ Object
- #set_nonblocking(val) ⇒ Object
- #write(str) ⇒ Object
Instance Method Details
#manufacturer ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'ext/myhidapi/myhidapi.c', line 168
static VALUE
rb_manufacturer(VALUE self)
{
hid_device *handle;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
wchar_t buffer[BUF_SIZE];
hid_get_manufacturer_string(handle, buffer, BUF_SIZE);
return rb_wcstombs(buffer);
}
|
#product ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'ext/myhidapi/myhidapi.c', line 180
static VALUE
rb_product(VALUE self)
{
hid_device *handle;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
wchar_t buffer[BUF_SIZE];
hid_get_product_string(handle, buffer, BUF_SIZE);
return rb_wcstombs(buffer);
}
|
#read(size) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'ext/myhidapi/myhidapi.c', line 122
static VALUE
rb_hid_read(VALUE self, VALUE size)
{
hid_device *handle;
unsigned char * buf;
int read;
VALUE ret;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
buf = xcalloc(NUM2SIZET(size), sizeof(unsigned char));
read = hid_read(handle, buf, NUM2SIZET(size));
if (read > 0) {
ret = rb_str_new((char *)buf, read);
} else {
ret = Qnil;
}
xfree(buf);
return ret;
}
|
#read_timeout(size, timeout_ms) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/myhidapi/myhidapi.c', line 145
static VALUE
rb_hid_read_timeout(VALUE self, VALUE size, VALUE timeout_ms)
{
hid_device *handle;
unsigned char * buf;
int read;
VALUE ret;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
buf = xcalloc(NUM2SIZET(size), sizeof(unsigned char));
read = hid_read_timeout(handle, buf, NUM2SIZET(size), NUM2INT(timeout_ms));
if (read > 0) {
ret = rb_str_new((char *)buf, read);
} else {
ret = Qnil;
}
xfree(buf);
return ret;
}
|
#set_nonblocking(val) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'ext/myhidapi/myhidapi.c', line 110
static VALUE
rb_hid_set_nonblocking(VALUE self, VALUE val)
{
hid_device *handle;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
if (!hid_set_nonblocking(handle, NUM2INT(val))) {
return Qtrue;
} else {
return Qnil;
}
}
|
#write(str) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'ext/myhidapi/myhidapi.c', line 93
static VALUE
rb_hid_write(VALUE self, VALUE str)
{
hid_device *handle;
int written;
TypedData_Get_Struct(self, hid_device, &myhidapi_handle_type, handle);
written = hid_write(handle, (unsigned char *)StringValuePtr(str), RSTRING_LEN(str));
if (written >= 0) {
return INT2NUM(written);
} else {
return Qfalse;
}
}
|