usbutils 0.0.1 → 0.0.2

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: 44280c8cb845604e93470fc9b0ee9c012d281c5c
4
- data.tar.gz: f8c12da7e5fd1ebb1cf568fcdaa91201b5b3a7d8
3
+ metadata.gz: f457bb52154815702f858cad6f446efaff89b0c4
4
+ data.tar.gz: cbb7883c2b255c2b26f86495686f593a87e80a78
5
5
  SHA512:
6
- metadata.gz: d9a42ebc0646e43ea12e4ffca7987725e707f9f8969bf47f5bd1c474a264ba2a807267c8c074e4eea5f457b8e0851f6ac47307c56ea3115ed3219b2ee5f67a35
7
- data.tar.gz: b5b6a9657b63de970880b70c2d0ed6df9c631ba2116f6ca55da743d099b9488e8fac741e8ac2634942917927de5011bf2c9697907f025181d21e419b3b6c2bb2
6
+ metadata.gz: 1f8b83a7d53c7f8d90122827eb1ce06f59296d3e4bb2042a9e010d47b5dc7c9bd31183413881e7247479d4bbd1389d862ab211858b09d323b9a38e6adbed6852
7
+ data.tar.gz: eb1881bdc559095a7c5d6890ca2504e52ac27c8e1e7939a7a37edb3b83ca6b4bf384f1b56f6a8670e40d26eafed5f0e5bd8b5c6c17cdd6c8e8a2784d5c121348
data/README.md CHANGED
@@ -1,24 +1,30 @@
1
1
  # USBUtils
2
2
 
3
- TODO: Write a gem description
3
+ Utilities to control the USB devices.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ $ gem install usbutils
8
8
 
9
- gem 'usbutils'
9
+ ## Usage
10
10
 
11
- And then execute:
11
+ show command list
12
12
 
13
- $ bundle
13
+ $ usbutils
14
+ Commands:
15
+ usbutils devices # list all usb devices
16
+ usbutils help [COMMAND] # Describe available commands or one specific command
17
+ usbutils reset <serial no> # reset device
14
18
 
15
- Or install it yourself as:
19
+ show usb devices
16
20
 
17
- $ gem install usbutils
21
+ $ usbutils devices
22
+ serial=0000:00:06.0 product=OHCI Host Controller manufacturer=Linux 3.2.0-23-generic ohci_hcd
23
+ serial=01498A4D15005015 product=Galaxy Nexus manufacturer=samsung
18
24
 
19
- ## Usage
25
+ reset(reconnect) usb device
20
26
 
21
- TODO: Write usage instructions here
27
+ $ usbutils reset 01498A4D15005015
22
28
 
23
29
  ## Contributing
24
30
 
@@ -107,6 +107,7 @@ print_device() {
107
107
  fi
108
108
  speed=`cat speed`
109
109
  maxchild=`cat maxchild`
110
+ printf "\nPATH: $devpath"
110
111
  printf "\nT: Bus=%02i Lev=%02i Prnt=%02i Port=%02i Cnt=%02i Dev#=%3i Spd=%-3s MxCh=%2i\n" \
111
112
  $busnum $level $parent $port $count $devnum $speed $maxchild
112
113
 
@@ -6,9 +6,6 @@ require "usbutils/cli"
6
6
 
7
7
  module USBUtils
8
8
  class << self
9
- def reset(serial)
10
- end
11
-
12
9
  def find_by(by, value)
13
10
  devices.each do |device|
14
11
  return device if device[by.to_sym] == value
@@ -21,14 +18,12 @@ module USBUtils
21
18
  Dir.glob("/sys/bus/usb/devices/usb*") do |device|
22
19
  set_device(devices, device, 0, 0)
23
20
  end
24
- devices
25
-
26
21
  usb = LIBUSB::Context.new
27
22
  usb.devices.each do |usbdev|
28
23
  idvendor = format("%04x", usbdev.idVendor)
29
- idproduct = format("%04x", usbdev.idProduct)
24
+ idproduct = format("%04x", usbdev.idProduct)
30
25
  device = devices.select {|item| item[:idvendor] == idvendor && item[:idproduct] == idproduct}.first
31
- device[:usbdev] = usbdev
26
+ device[:usbdev] = usbdev if device
32
27
  end
33
28
  devices
34
29
  end
@@ -36,23 +31,26 @@ module USBUtils
36
31
  def set_device(devices, devpath, parent, level)
37
32
  return unless FileTest::directory?(devpath)
38
33
  Dir.chdir(devpath) do
39
- next unless File.exists? "#{devpath}/serial"
40
- busnum = `cat busnum`.chomp
41
- devnum = `cat devnum`.chomp
42
- idvendor = `cat idVendor`.chomp
43
- idproduct = `cat idProduct`.chomp
44
- manufacturer = `cat manufacturer`.chomp
45
- product = `cat product`.chomp
46
- serial = `cat serial`.chomp
47
- devices << {
48
- :serial => serial,
49
- :idvendor => idvendor,
50
- :idproduct => idproduct,
51
- :manufacturer => manufacturer,
52
- :product => product,
53
- }
54
- Dir.glob("#{busnum}-*") do |subdev|
55
- set_device devices, "#{devpath}/#{subdev}", devnum, level + 1
34
+ next unless File.exists? "busnum"
35
+ busnum = `cat busnum`.chomp
36
+ if File.exists? "serial"
37
+ devnum = `cat devnum`.chomp
38
+ idvendor = `cat idVendor`.chomp
39
+ idproduct = `cat idProduct`.chomp
40
+ manufacturer = `cat manufacturer`.chomp
41
+ product = `cat product`.chomp
42
+ serial = `cat serial`.chomp
43
+ devices << {
44
+ :serial => serial,
45
+ :idvendor => idvendor,
46
+ :idproduct => idproduct,
47
+ :manufacturer => manufacturer,
48
+ :product => product,
49
+ }
50
+ end
51
+ Dir.glob("#{devpath}/#{busnum}-*") do |subdev|
52
+ subdev = subdev.chomp
53
+ set_device devices, subdev, devnum, level + 1
56
54
  end
57
55
  end
58
56
  end
@@ -4,30 +4,23 @@ require 'thor'
4
4
 
5
5
  module USBUtils
6
6
  class CLI < Thor
7
- desc "find_by <by> <value>", "find device"
8
- def find_by(by, value)
9
- pp USBUtils.find_by(by, value)
10
- end
11
-
12
- desc "reset_by <by> <value>", "reset device"
13
- def reset_by(by, value)
14
- device = USBUtils.find_by(by, value)
15
- device[:usbdev].open.reset_device
7
+ desc "devices", "list all usb devices"
8
+ option :detail, :aliases => "d"
9
+ def devices
10
+ devices = USBUtils.devices
11
+ USBUtils.devices.each do |device|
12
+ if options[:detail]
13
+ pp device
14
+ else
15
+ print "serial=#{device[:serial]}\tproduct=#{device[:product]}\tmanufacturer=#{device[:manufacturer]}\n"
16
+ end
17
+ end
16
18
  end
17
19
 
18
20
  desc "reset <serial no>", "reset device"
19
21
  def reset(serial)
20
22
  device = USBUtils.find_by(:serial, serial)
21
- p device[:usbdev]
22
- p device[:usbdev].open
23
- #device[:usbdev].open.reset_device
24
- end
25
-
26
- desc "devices", "list all usb devices"
27
- def devices
28
- USBUtils.devices.each do |device|
29
- pp device
30
- end
23
+ device[:usbdev].open.reset_device
31
24
  end
32
25
  end
33
26
  end
@@ -1,3 +1,3 @@
1
1
  module USBUtils
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usbutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-yamada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler