urix-util 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8908e919b75e555842c3d630babfc6659e7c40ac
4
+ data.tar.gz: 7ea747b67cc3b09e33d3e67dfc381a64622c6556
5
+ SHA512:
6
+ metadata.gz: 0ebf3d851c1904bdc2dfd7f3ca20f75935da4aed00c4417ed195029e9b8ff7091f380713c989be4195d186cdc6590c790967c55e8dbc3fdb48be987986863098
7
+ data.tar.gz: c043775f78ab99f7f32178ba26b286e794baba91c4915f7565a6587c00640da2d8ac478b184814f0b672530c952098d1c78adc02d92b7f72dfb3b07931a08660
data/lib/urix.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ module URIx
4
+ require_relative 'urix/urix.rb'
5
+ require_relative 'urix/urix_defs.rb'
6
+ end
7
+
8
+
data/lib/urix/urix.rb ADDED
@@ -0,0 +1,95 @@
1
+
2
+ require 'libusb'
3
+
4
+
5
+ module URIx
6
+
7
+ class URIx
8
+
9
+ attr :usb, :device, :handle
10
+ attr_reader :pin_states, :pin_modes, :claimed
11
+
12
+ def initialize
13
+ @usb = LIBUSB::Context.new
14
+ @pin_states = 0x0
15
+ @pin_modes = 0x0
16
+ @claimed = false
17
+
18
+ set_pin_mode( PTT_PIN, :output )
19
+ end
20
+
21
+ def claim_interface
22
+ devices = usb.devices(:idVendor => VENDOR_ID, :idProduct => PRODUCT_ID)
23
+
24
+ unless devices.first then
25
+ return
26
+ end
27
+
28
+ @device = devices.first
29
+ @handle = @device.open
30
+
31
+ @handle.detach_kernel_driver(HID_INTERFACE)
32
+ @handle.claim_interface( HID_INTERFACE )
33
+ end
34
+
35
+ def close_interface
36
+ @handle.release_interface( HID_INTERFACE )
37
+ @handle.attach_kernel_driver(HID_INTERFACE)
38
+ @handle.close
39
+ end
40
+
41
+ def set_output pin, state
42
+ state = false if state == :low
43
+ state = true if state == :high
44
+
45
+ if ( @pin_states >> ( pin - 1 )).odd? && ( state == false ) or
46
+ ( @pin_states >> ( pin - 1 )).even? && ( state == true ) then
47
+
48
+ mask = 0 + ( 1 << ( pin - 1 ))
49
+ @pin_states ^= mask
50
+ end
51
+
52
+ write_output
53
+ end
54
+
55
+ def set_pin_mode pin, mode
56
+ if ( @pin_modes >> ( pin - 1 )).odd? && ( mode == :input ) or
57
+ ( @pin_modes >> ( pin - 1 )).even? && ( mode == :output ) then
58
+
59
+ mask = 0 + ( 1 << ( pin - 1 ))
60
+ @pin_modes ^= mask
61
+ end
62
+ end
63
+
64
+ def set_ptt state
65
+ set_output PTT_PIN, state
66
+ end
67
+
68
+ private
69
+ def write_output
70
+ type = LIBUSB::ENDPOINT_OUT
71
+ type += LIBUSB::REQUEST_TYPE_CLASS
72
+ type += LIBUSB::RECIPIENT_INTERFACE
73
+
74
+ request = HID_REPORT_SET
75
+
76
+ value = 0 + ( HID_RT_OUTPUT << 8 )
77
+
78
+ index = HID_INTERFACE
79
+
80
+ dout = 0.chr
81
+ dout += @pin_states.chr
82
+ dout += @pin_modes.chr
83
+ dout += 0.chr
84
+
85
+ @handle.control_transfer(
86
+ :bmRequestType => type,
87
+ :bRequest => request,
88
+ :wValue => value,
89
+ :wIndex => index,
90
+ :dataOut => dout
91
+ )
92
+ end
93
+ end
94
+ end
95
+
@@ -0,0 +1,20 @@
1
+
2
+
3
+ module URIx
4
+
5
+ VENDOR_ID = 0x0d8c
6
+ PRODUCT_ID = 0x013a
7
+
8
+ HID_REPORT_SET = 0x09
9
+ HID_REPORT_GET = 0x01
10
+
11
+ HID_RT_INPUT = 0x01
12
+ HID_RT_OUTPUT = 0x02
13
+
14
+ HID_INTERFACE = 3
15
+
16
+ PTT_PIN = 3
17
+
18
+ end
19
+
20
+
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: urix-util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Herting
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A library to talk to a URIx radio interface.
14
+ email: aaron@herting.cc
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/urix.rb
20
+ - lib/urix/urix.rb
21
+ - lib/urix/urix_defs.rb
22
+ homepage: https://github.com/qwertos/URIx-Util
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: A library to talk to a URIx radio interface.
46
+ test_files: []