Class: HidApi::Device

Inherits:
FFI::Pointer
  • Object
show all
Extended by:
FFI::DataConverter
Defined in:
lib/hid_api/device.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_native(value, ctx) ⇒ Object



8
9
10
# File 'lib/hid_api/device.rb', line 8

def self.from_native(value, ctx)
  new(value)
end

Instance Method Details

#closeObject



12
13
14
# File 'lib/hid_api/device.rb', line 12

def close
  HidApi.close(self)
end

#errorObject



68
69
70
71
72
# File 'lib/hid_api/device.rb', line 68

def error
  # NOTE: hid_error is only implemented on Windows systems and returns nil
  # on other platforms
  HidApi.hid_error(self)
end

#get_feature_report(data) ⇒ Object

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/hid_api/device.rb', line 60

def get_feature_report(data)
  raise NotImplementedError
end

#get_manufacturer_stringObject



20
21
22
# File 'lib/hid_api/device.rb', line 20

def get_manufacturer_string
  get_buffered_string :manufacturer
end

#get_product_stringObject



24
25
26
# File 'lib/hid_api/device.rb', line 24

def get_product_string
  get_buffered_string :product
end

#get_serial_number_stringObject



28
29
30
# File 'lib/hid_api/device.rb', line 28

def get_serial_number_string
  get_buffered_string :serial_number
end

#read(length) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/hid_api/device.rb', line 32

def read(length)
  buffer = clear_buffer length
  with_hid_error_handling do
    HidApi.hid_read self, buffer, buffer.length
  end
  buffer
end

#read_timeout(length, timeout) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/hid_api/device.rb', line 40

def read_timeout(length, timeout)
  buffer = clear_buffer length
  with_hid_error_handling do
    HidApi.hid_read_timeout self, buffer, buffer.length, timeout
  end
  buffer
end

#send_feature_report(data) ⇒ Object

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/hid_api/device.rb', line 64

def send_feature_report(data)
  raise NotImplementedError
end

#set_nonblocking(int) ⇒ Object



16
17
18
# File 'lib/hid_api/device.rb', line 16

def set_nonblocking(int)
  HidApi.hid_set_nonblocking self, int
end

#write(data) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hid_api/device.rb', line 48

def write(data)
  buffer = clear_buffer data.length
  case data
  when String then buffer.put_bytes 0, data
  when Array then buffer.put_array_of_char 0, data
  end

  with_hid_error_handling do
    HidApi.hid_write self, buffer, buffer.length
  end
end