device_input 0.2.1.1 → 0.3.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: ef70d561e40df5e3bd0df134ede59a38b11b8b78
4
- data.tar.gz: 5c902897dcd290b0cac172629833e12851dd04e2
3
+ metadata.gz: 00eb69decfeb19916bef79e450c1971bf73876a6
4
+ data.tar.gz: 101794e4db2d8cb6e3550c1f515e92a54b8fd526
5
5
  SHA512:
6
- metadata.gz: '00688046ffe558c9d16b321eb33e121acfacd88ff61ab6eddc2a3abe076a71662fc4224b1c7cbc9e6457c16c88b1f58ae566784852dcffba3e0edb873cd53915'
7
- data.tar.gz: d547249fbaf0dd1872910a7b55b61512e27054a0169489a8c81ed5672bb521fa0d62570a0b53c1de95ed77c121cc86bc46f58e5f95ac39747097a483afe8c571
6
+ metadata.gz: ed04d353a1879d3a3cde29514efd6f97b15411b0f114c9638a7d56facd99cbc1213bcb3c75f014377d1971748258231b71364c6f3b831e343a7265b72d369aa6
7
+ data.tar.gz: 8675d1bb76626cd90924aa62abb017b7779ce114effa82619bd24235044e3d478f971b9c0c163f51b42f28eb2a5d36c102844eaac64a26f67c12081ac71e18f3
data/README.md CHANGED
@@ -66,7 +66,7 @@ $ gem install device_input # sudo as necessary
66
66
 
67
67
  Or, if using [Bundler](http://bundler.io/), add to your `Gemfile`:
68
68
  ```ruby
69
- gem 'device_input', '~> 0.1'
69
+ gem 'device_input', '~> 0.3'
70
70
  ```
71
71
 
72
72
  # Usage
@@ -74,7 +74,7 @@ gem 'device_input', '~> 0.1'
74
74
  ## Executable
75
75
 
76
76
  ```shell
77
- $ sudo devsniff /dev/input/event0
77
+ $ evdump /dev/input/event0 # sudo as necessary
78
78
  ```
79
79
 
80
80
  When the `f` key is pressed:
@@ -96,7 +96,7 @@ EV_SYN:SYN_REPORT:0
96
96
 
97
97
  How about pretty mode?
98
98
  ```shell
99
- $ sudo devsniff /dev/input/event0 pretty
99
+ $ sudo cat /dev/input/event0 | evdump --print pretty
100
100
 
101
101
  # f
102
102
 
@@ -110,7 +110,7 @@ $ sudo devsniff /dev/input/event0 pretty
110
110
 
111
111
  We can pull off the labels and go raw:
112
112
  ```shell
113
- $ sudo devsniff /dev/input/event0 raw
113
+ $ sudo cat /dev/input/event0 | evdump --print raw
114
114
 
115
115
  # f
116
116
 
@@ -124,7 +124,7 @@ $ sudo devsniff /dev/input/event0 raw
124
124
 
125
125
  Fulfill your hacker-matrix fantasies:
126
126
  ```shell
127
- $ sudo devsniff /dev/input/event0 hex
127
+ $ sudo cat /dev/input/event0 | evdump --print hex
128
128
 
129
129
  # f
130
130
 
@@ -141,10 +141,12 @@ $ sudo devsniff /dev/input/event0 hex
141
141
  ```ruby
142
142
  require 'device_input'
143
143
 
144
- # this loops forever and blocks waiting for input
145
- DeviceInput.read_from('/dev/input/event0') do |event|
146
- puts event
147
- # break if event.time > start + 30
144
+ File.open('/dev/input/event0', 'r') do |dev|
145
+ # this loops forever and blocks waiting for input
146
+ DeviceInput.read_loop(dev) do |event|
147
+ puts event
148
+ # break if event.time > start + 30
149
+ end
148
150
  end
149
151
  ```
150
152
 
@@ -157,11 +159,11 @@ An event has:
157
159
  * `#value`: Fixnum (signed) from `#data`
158
160
 
159
161
  You will probably want to write your own read loop for your own project.
160
- [`DeviceInput.read_from`](lib/device_input.rb#L100) is very simple and can
162
+ [`DeviceInput.read_loop`](lib/device_input.rb#L102) is very simple and can
161
163
  easily be rewritten outside of this project's namespace and adapted for your
162
164
  needs.
163
165
 
164
- # Research
166
+ # Background
165
167
 
166
168
  ## Kernel docs
167
169
 
@@ -206,7 +208,7 @@ What's a [`__kernel_time_t`](https://git.kernel.org/cgit/linux/kernel/git/torval
206
208
  ```
207
209
  typedef long __kernel_long_t;
208
210
  # ...
209
- typedef __kernel_long_t __kernel_suseconds_t;
211
+ typedef __kernel_long_t __kernel_suseconds_t;
210
212
  # ...
211
213
  typedef __kernel_long_t __kernel_time_t;
212
214
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1.1
1
+ 0.3.0.2
data/bin/evdump ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'device_input'
4
+ require 'slop'
5
+
6
+ opts = Slop.parse do |o|
7
+ o.banner = "evdump [OPTIONS] [DEVICE]"
8
+ o.string '-p', '--print', 'pretty|raw|hex'
9
+ o.on '-h', '--help' do
10
+ puts o
11
+ exit
12
+ end
13
+ end
14
+
15
+ def opts.error(msg = nil)
16
+ puts self
17
+ puts "ERROR: #{msg}" if msg
18
+ exit 1
19
+ end
20
+
21
+ case opts[:print]
22
+ when 'pretty', 'raw', 'hex'
23
+ print_meth = opts[:print]
24
+ else
25
+ print_meth = 'to_s'
26
+ end
27
+
28
+ if $stdin.tty?
29
+ device = opts.arguments.shift
30
+ opts.error "Please specify an input device file" unless device
31
+ opts.error "#{device} is not a character device" unless File.chardev? device
32
+ opts.error "#{device} is not readable" unless File.readable? device
33
+ device = File.new(device, 'r')
34
+ else
35
+ device = $stdin
36
+ end
37
+
38
+ DeviceInput.read_loop(device) { |event|
39
+ puts event.send(print_meth)
40
+ }
data/lib/device_input.rb CHANGED
@@ -99,14 +99,12 @@ module DeviceInput
99
99
  alias_method :hex, RUBY23 ? :ruby23_hex : :to_s
100
100
  end
101
101
 
102
- # never gonna give you up
103
- def self.read_from(filename)
104
- File.open(filename, 'r') { |f|
105
- loop {
106
- bytes = f.read(Event::BYTE_LENGTH)
107
- data = Event.decode(bytes)
108
- yield Event.new(data)
109
- }
102
+ def self.read_loop(io)
103
+ loop {
104
+ bytes = io.read(Event::BYTE_LENGTH)
105
+ break unless (bytes and bytes.length == Event::BYTE_LENGTH)
106
+ data = Event.decode(bytes)
107
+ yield Event.new(data)
110
108
  }
111
109
  end
112
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.1
4
+ version: 0.3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
@@ -29,13 +29,13 @@ description: |
29
29
  No dependencies. Ruby 2+ required
30
30
  email:
31
31
  executables:
32
- - devsniff
32
+ - evdump
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - README.md
37
37
  - VERSION
38
- - bin/devsniff
38
+ - bin/evdump
39
39
  - lib/device_input.rb
40
40
  - lib/device_input/compat.rb
41
41
  - lib/device_input/labels.rb
data/bin/devsniff DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'device_input'
4
-
5
- device = ARGV.shift || '/dev/input/event0'
6
- mode = (ARGV.shift || 'normal').downcase
7
-
8
- if !File.readable?(device)
9
- puts "#{device} cannot be read. Perhaps you need to sudo?"
10
- exit 1
11
- end
12
-
13
- case mode
14
- when 'normal'
15
- mode = 'to_s'
16
- when 'bytes' # legacy
17
- mode = 'hex'
18
- when 'pretty', 'raw', 'hex'
19
- # ok
20
- else
21
- raise "unsupported mode: #{mode}"
22
- end
23
-
24
- DeviceInput.read_from(device) { |event|
25
- puts event.send(mode)
26
- }