bluebutton 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/VERSION +1 -1
  4. data/bin/bluebutton +19 -6
  5. data/lib/bluebutton.rb +20 -1
  6. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7acbf7cc26de082f53cb7a9a3e015a8a19b8bbf6
4
- data.tar.gz: dd167b970527b72bce24821cf15a60c6f8492db6
3
+ metadata.gz: 8d6f698dc7fdff2883ca47dec71fa6a846c28dcc
4
+ data.tar.gz: 3f7f65cce9d8192be8176e97a98e2d75d7a7c1a9
5
5
  SHA512:
6
- metadata.gz: dd962b4c2992ac63348b0517612cfc8fbe4bf4311023502073d2df31239ea3e7b5b8793dd4c34d84f08f054cf03cc6dbbcfff15bfe05c96398f2e084c3fd9253
7
- data.tar.gz: 27944393f31dbabc7e8704d7ad1ce07ed3aa4521dc2ea7682cb7074a7dcca32be10929b44db532425b15fe6bd29e5b45ee05f9959c5ee12fd089a883f2cd3680
6
+ metadata.gz: 7a43afe974ba63e50fb123a110b56a91828576cea5eae19f7e750ced92e349f5fa4bee46f9e95a4fa60312faaea761d0c9dfe3ca9f4c3bb1a5e7d2922dadf94d
7
+ data.tar.gz: f0d123d004db1a666c242bf7b6a12db149c381ee9739366eca1446ef9dfe05cf9903851c15defb53b538019aa13ae740ae89fb61a897a51a2284e7cf9d83d41a
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Bluebutton
2
2
 
3
+ Simple daemon that allows you to execute action when bluetooth button shutter pressed. So you can control your PC by low energy button device and few scripts.
4
+
5
+ ![Bluetooth Remote Shutter](https://github.com/kinnalru/bluebutton/blob/master/button.jpg)
6
+
7
+
3
8
  # Usage
4
9
 
5
10
  ```shell
6
11
  $ bluebutton -d="Shutter3" # sudo as necessary
7
12
  ```
8
13
 
9
- **With config***
14
+ **With config**
10
15
  ```shell
11
16
  $ cat /home/.config/bluebutton
12
17
  keyup=echo UP
@@ -25,9 +30,10 @@ $ bluebutton -d="Shutter3" -c /home/.config/bluebutton # sudo as necessary
25
30
 
26
31
  * Ruby >= 2.0
27
32
 
28
- **DEPENDENCIES**
33
+ * Kernel config
34
+ ![Kernel config](https://github.com/kinnalru/bluebutton/blob/master/kernel.png)
29
35
 
30
- * none
36
+ * BlueZ
31
37
 
32
38
  Install the gem:
33
39
  ```shell
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2
1
+ 0.2.1
@@ -35,14 +35,27 @@ if opts[:config]
35
35
  end
36
36
  end
37
37
 
38
- button = Bluebutton.new(device)
39
38
 
40
- button.on_keydown = actions[:keydown] || -> {puts "Key pressed"}
41
- button.on_keyup = actions[:keyup] || -> {puts "Key released"}
42
- button.on_longdown = actions[:longdown] || -> {puts "Long pressed"}
43
- button.on_longup = actions[:longup] || -> {puts "Long released"}
44
39
 
45
- button.run
40
+
41
+
42
+ while true do
43
+ begin
44
+ puts "Try to find device #{device}..."
45
+ button = Bluebutton.new(device)
46
+
47
+ button.on_keydown = actions[:keydown] || -> {puts "Key pressed"}
48
+ button.on_keyup = actions[:keyup] || -> {puts "Key released"}
49
+ button.on_longdown = actions[:longdown] || -> {puts "Long pressed"}
50
+ button.on_longup = actions[:longup] || -> {puts "Long released"}
51
+ puts "Reading events from #{button.device}..."
52
+ button.run
53
+ rescue => e
54
+ $stderr.puts e.message
55
+ end
56
+
57
+ sleep 3
58
+ end
46
59
 
47
60
 
48
61
 
@@ -1,17 +1,26 @@
1
1
  require 'device_input'
2
2
 
3
+
3
4
  class Bluebutton
4
5
  attr_accessor :on_keydown
5
6
  attr_accessor :on_keyup
6
7
  attr_accessor :on_longdown
7
8
  attr_accessor :on_longup
9
+ attr_accessor :device
8
10
 
9
11
  def initialize name
10
12
  @finder = Finder.new(name)
11
13
  @device = @finder.from_sys
12
14
 
13
15
  raise "#{@device} is not a character device" unless File.chardev? @device
14
- raise "#{@device} is not readable. Try sudo" unless File.readable? @device
16
+ raise "#{@device} is not readable. Try sudo -E bluebutton" unless File.readable? @device
17
+
18
+ puts "Device #{name} find at #{@device}"
19
+
20
+ if xinput_id = @finder.from_xinput
21
+ puts "xinput device finded with id=#{xinput_id}... Try disable for current X..."
22
+ system("xinput disable #{xinput_id}")
23
+ end
15
24
  end
16
25
 
17
26
  def run
@@ -72,6 +81,16 @@ class Finder
72
81
 
73
82
  return device
74
83
  end
84
+
85
+ def from_xinput
86
+ if device =`xinput`.split("\n").compact.map(&:strip).select{|l| l.downcase[@name.downcase]}.first
87
+ puts "find:#{device}"
88
+ return /id=(\d+)/.match(device)[1]
89
+ end
90
+ rescue
91
+ return nil
92
+ end
93
+
75
94
  end
76
95
 
77
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluebutton
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
@@ -38,7 +38,9 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: 'Connect to Bluetooth button and execute action when pressed.
41
+ description: 'Simple daemon that allows you to execute action when bluetooth button
42
+ shutter pressed. So you can control your PC by low energy button device and few
43
+ scripts.
42
44
 
43
45
  '
44
46
  email:
@@ -74,5 +76,5 @@ rubyforge_project:
74
76
  rubygems_version: 2.5.1
75
77
  signing_key:
76
78
  specification_version: 4
77
- summary: Deal with Bluetooth button aka selfy button
79
+ summary: Deal with Bluetooth button aka selfy shutter
78
80
  test_files: []