hid_api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7a83252db8cfeddaede2f200665db20a8184d4f
4
- data.tar.gz: 815203c00e14784e31db522e2c68820f818f6623
3
+ metadata.gz: 6bec3d023bb6aff34ad5546a6d3d251c09ac8843
4
+ data.tar.gz: 7274f344c0fbc04263e5df8173448f1024753c44
5
5
  SHA512:
6
- metadata.gz: af6be07a04225a86cbe005fb7df1b27db1099b361e1284dbd0175910d4213dc3da73ad75e71c3f93ecb31237c7771ba6cd07dbc52d6c276d1d43a6b185c67c90
7
- data.tar.gz: 6538313c51e2add16a1d1353437a32b806a32b7bd93bc1c6c45bf78925510c785a9377ea6747ba1cd723ceec3e2420eafa146fd930573c79860f9360395f7c87
6
+ metadata.gz: f9702dd5834be34f41318d4f7bc16884cc527fe86822b5d3ce2e516ae0a42df0dc500a3bff1b91024568833c9f3738528aba9c4e1395a2ab928407928d4ad88b
7
+ data.tar.gz: db3451def500983a7516cee86fba247a2ae8fbc9c71c68d93b5dcdfe0fdb45d99e841953fa7c00da60ab8c48f6b4c1fbc4de3fc1dcb68795835303ad7205415e
@@ -30,7 +30,7 @@ module HidApi
30
30
  end
31
31
 
32
32
  def read(length)
33
- buffer = FFI::Buffer.new(1, length, true)
33
+ buffer = clear_buffer length
34
34
  with_hid_error_handling do
35
35
  HidApi.hid_read self, buffer, buffer.length
36
36
  end
@@ -38,7 +38,7 @@ module HidApi
38
38
  end
39
39
 
40
40
  def read_timeout(length, timeout)
41
- buffer = FFI::Buffer.new(1, length, true)
41
+ buffer = clear_buffer length
42
42
  with_hid_error_handling do
43
43
  HidApi.hid_read_timeout self, buffer, buffer.length, timeout
44
44
  end
@@ -46,7 +46,7 @@ module HidApi
46
46
  end
47
47
 
48
48
  def write(data)
49
- buffer = FFI::Buffer.new(1, data.length, true)
49
+ buffer = clear_buffer data.length
50
50
  case data
51
51
  when String then buffer.put_bytes 0, data
52
52
  when Array then buffer.put_array_of_char 0, data
@@ -72,8 +72,15 @@ module HidApi
72
72
  end
73
73
 
74
74
  private
75
+ def clear_buffer length
76
+ b = FFI::Buffer.new(1, length)
77
+ # FFI::Buffer doesn't clear the first byte if length < 8
78
+ b.put_char 0, 0
79
+ b
80
+ end
81
+
75
82
  def get_buffered_string field
76
- buffer = FFI::Buffer.new(1, 255, true)
83
+ buffer = clear_buffer 255
77
84
  HidApi.send "hid_get_#{field}_string", self, buffer, buffer.length
78
85
  buffer.read_wchar_string
79
86
  end
@@ -1,3 +1,3 @@
1
1
  module HidApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hid_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gareth Adams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi