rawhid 0.1.3 → 0.1.4

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: f864ececa0852d9cd49c85bd6083ed763f4f1d86
4
- data.tar.gz: 6717fde14ea698e27ae14c01c992bb20a729ce03
3
+ metadata.gz: 6687a92269d84106c45e377dc80e608509ca0ded
4
+ data.tar.gz: 2b780571990dde4bad71c010a38b682918fd70c2
5
5
  SHA512:
6
- metadata.gz: 6461914cc74daff2a07c52c69ee1d4314aca19d2287280c5b4df8a3da635b738a848e10272c5d4f3888cfd61ba51dbd73a0d7c2e5bd13a2a9568c86ebd983fa7
7
- data.tar.gz: 8469b76678ef69ec201845c96d8b77f29b86441aaf4fde37f4aa9553762cd89b955a6d48f29a1913123b7c26be2a4085cfc4323549aa0b651148ebe3ba687d21
6
+ metadata.gz: aa031a1b89150e4d4d0522c5f52971e9a61b7dfaeba58ea9fdc0afea1493297a9d2fa2fd56716ae7f31f14016b14d47e77db40a765bf34a5b14e4c4b29807ecb
7
+ data.tar.gz: df77c46ca12185600d029d3630bec5325d4139c41f877e744aff562b84b531f0c6a1e886b57d515603d010380144a5c4d03f7dbdf31e1a45a70bf5beee945019
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/extensiontask"
3
3
  task :default => :spec
4
- Rake::ExtensionTask.new 'rawhid'
4
+ Rake::ExtensionTask.new 'teensy_rawhid'
@@ -14,7 +14,7 @@ VALUE RawHIDError;
14
14
  VALUE RawHID_new(VALUE class, VALUE vendorId, VALUE productId) {
15
15
  void *dev = NULL;
16
16
  int vId = NUM2INT(vendorId);
17
- int pId = NUM2INT(pId);
17
+ int pId = NUM2INT(productId);
18
18
  int devices_opened = rawhid_open(1, &dev, vId, pId, -1, -1);
19
19
  if(devices_opened == 0 || dev == NULL) {
20
20
  rb_raise(RawHIDError, "Unable to open device");
@@ -38,9 +38,6 @@ VALUE RawHID_send(int argc, VALUE *argv, VALUE class) {
38
38
  return INT2NUM(0);
39
39
  }
40
40
  int sent = rawhid_send(dev, buf, len, timeout);
41
- if(sent == -1) {
42
- rb_raise(RawHIDError, "Error sending data to device");
43
- }
44
41
  return INT2NUM(sent);
45
42
  }
46
43
 
@@ -66,8 +63,8 @@ VALUE RawHID_recv(int argc, VALUE *argv, VALUE class) {
66
63
  }
67
64
  int received = rawhid_recv(dev, buf, len, timeout);
68
65
 
69
- if(received == -1) {
70
- rb_raise(RawHIDError, "Error receiving data from device");
66
+ if(received < 0) {
67
+ return INT2NUM(received);
71
68
  }
72
69
  data = rb_str_new(buf, received);
73
70
  return data;
@@ -78,8 +75,8 @@ void Init_teensy_rawhid() {
78
75
  RawHIDError = rb_define_class_under(RawHID, "RawHIDError", rb_eRuntimeError);
79
76
 
80
77
  rb_define_singleton_method(RawHID, "new", RawHID_new, 2);
81
- rb_define_method(RawHID, "send", RawHID_send, -1);
82
- rb_define_method(RawHID, "recv", RawHID_recv, -1);
78
+ rb_define_method(RawHID, "raw_send", RawHID_send, -1);
79
+ rb_define_method(RawHID, "raw_recv", RawHID_recv, -1);
83
80
 
84
81
  }
85
82
 
data/lib/rawhid.rb CHANGED
@@ -1,2 +1,34 @@
1
1
  require "rawhid/version"
2
2
  require "teensy_rawhid"
3
+
4
+ class RawHID
5
+ class RawHIDError
6
+ def initialize(msg, error_code=nil)
7
+ @code = error_code
8
+ super msg
9
+ end
10
+ attr_accessor :code
11
+ end
12
+ private :raw_send, :raw_recv
13
+
14
+ def send(data, timeout=0)
15
+ if Array === data
16
+ data = data.map(&:chr).join
17
+ end
18
+ ret = raw_send(data, timeout)
19
+ if ret > 0
20
+ ret
21
+ else
22
+ raise RawHIDError.new("Failed sending data", ret)
23
+ end
24
+ end
25
+
26
+ def recv(len, timeout)
27
+ ret = raw_recv(len, timeout)
28
+ if String === data
29
+ return ret
30
+ else
31
+ raise RawHIDError.new("Failed receiving data", ret)
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  class RawHID
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawhid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo P.