README.md in device_input-0.2.1.1 vs README.md in device_input-0.3.0.2

- old
+ new

@@ -64,19 +64,19 @@ $ gem install device_input # sudo as necessary ``` Or, if using [Bundler](http://bundler.io/), add to your `Gemfile`: ```ruby -gem 'device_input', '~> 0.1' +gem 'device_input', '~> 0.3' ``` # Usage ## Executable ```shell -$ sudo devsniff /dev/input/event0 +$ evdump /dev/input/event0 # sudo as necessary ``` When the `f` key is pressed: ``` EV_MSC:ScanCode:33 @@ -94,11 +94,11 @@ EV_SYN:SYN_REPORT:0 ``` How about pretty mode? ```shell -$ sudo devsniff /dev/input/event0 pretty +$ sudo cat /dev/input/event0 | evdump --print pretty # f 2017-01-24 05:29:43.923 Misc:ScanCode:33 2017-01-24 05:29:43.923 Key:F:1 @@ -108,11 +108,11 @@ 2017-01-24 05:29:44.012 Sync:Report:0 ``` We can pull off the labels and go raw: ```shell -$ sudo devsniff /dev/input/event0 raw +$ sudo cat /dev/input/event0 | evdump --print raw # f 4:4:33 1:33:1 @@ -122,11 +122,11 @@ 0:0:0 ``` Fulfill your hacker-matrix fantasies: ```shell -$ sudo devsniff /dev/input/event0 hex +$ sudo cat /dev/input/event0 | evdump --print hex # f 00000000588757bd 00000000000046ca 0004 0004 00000021 00000000588757bd 00000000000046ca 0001 0021 00000001 @@ -139,14 +139,16 @@ ## Library ```ruby require 'device_input' -# this loops forever and blocks waiting for input -DeviceInput.read_from('/dev/input/event0') do |event| - puts event - # break if event.time > start + 30 +File.open('/dev/input/event0', 'r') do |dev| + # this loops forever and blocks waiting for input + DeviceInput.read_loop(dev) do |event| + puts event + # break if event.time > start + 30 + end end ``` An event has: @@ -155,15 +157,15 @@ * `#type`: String label, possibly `UNK-X` where X is the integer from `#data` * `#code`: String label, possibly `UNK-X-Y` where X and Y are from `#data` * `#value`: Fixnum (signed) from `#data` You will probably want to write your own read loop for your own project. -[`DeviceInput.read_from`](lib/device_input.rb#L100) is very simple and can +[`DeviceInput.read_loop`](lib/device_input.rb#L102) is very simple and can easily be rewritten outside of this project's namespace and adapted for your needs. -# Research +# Background ## Kernel docs * https://www.kernel.org/doc/Documentation/input/input.txt * https://www.kernel.org/doc/Documentation/input/event-codes.txt @@ -204,10 +206,10 @@ What's a [`__kernel_time_t`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/posix_types.h#n88)? ``` typedef long __kernel_long_t; # ... -typedef __kernel_long_t __kernel_suseconds_t; +typedef __kernel_long_t __kernel_suseconds_t; # ... typedef __kernel_long_t __kernel_time_t; ``` What's a [`__u16`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/int-l64.h#n23)?