go_easy_btn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/go_easy_btn ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+ Example Usage:
5
+ Linux: go_easy_btn <cmd> /dev/ttyUSB0
6
+ Mac: go_easy_btn <cmd> /dev/tty.usbmodem12341
7
+ =end
8
+
9
+ require File.expand_path('../lib/big_ass_button', File.dirname(__FILE__))
10
+
11
+ btn = BigAssButton.new :cmd => ARGV[0], :dev => (ARGV[1] || '/dev/tty.usbmodem12341')
12
+ btn.make_it_easy
data/lib/alerter.rb ADDED
@@ -0,0 +1,23 @@
1
+ class Alerter
2
+ class << self
3
+ def alert(msg, options ={})
4
+ if mac?
5
+ system "say -v Cellos \"#{msg}\""
6
+ elsif linux?
7
+ system "echo \"#{msg}\"|espeak"
8
+ else
9
+ # fuck it
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def mac?
16
+ RUBY_PLATFORM =~ /darwin/
17
+ end
18
+
19
+ def linux?
20
+ RUBY_PLATFORM =~ /linux/
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'serialport'
3
+ require File.expand_path('alerter', File.dirname(__FILE__))
4
+
5
+ class BigAssButton
6
+ BTN_COMMAND = 'PRESSED'
7
+
8
+ def initialize(options = {})
9
+ raise 'not found serial port has been' unless File.exists? options[:dev]
10
+ @cmd = options[:cmd]
11
+ @device = options[:dev]
12
+ @port = options[:port] || 115200
13
+ @count = 0
14
+ @start_time = Time.now
15
+ end
16
+
17
+ def make_it_easy
18
+ puts "Making It Easy™\n\n"
19
+ SerialPort.open @device, @port do |port|
20
+ begin
21
+ while data = port.readline
22
+ if data.strip == BTN_COMMAND
23
+ puts border
24
+
25
+ Alerter.alert 'I am going to make this easy.'
26
+ puts "Executing: #{@cmd}"
27
+
28
+ success = system @cmd
29
+
30
+ msg = success ? "That was easy!" : "Error: #{$?}"
31
+ Alerter.alert msg
32
+ puts msg
33
+
34
+ puts border
35
+ @count += 1
36
+
37
+ puts stats
38
+ end
39
+ end
40
+ rescue Interrupt, EOFError
41
+ puts "\rgoing bye bye now"
42
+ puts stats(true)
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def stats(verbose = false)
50
+ s = "Called #{@count} times\n#{"\n" unless verbose}"
51
+ if verbose
52
+ s << "Since: #{@start_time};\n"
53
+ s << "Uptime: #{sprintf '%.4f', (Time.now.to_f - @start_time.to_f) / 60} mins"
54
+ end
55
+ s
56
+ end
57
+
58
+ def border
59
+ '*'*80
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_easy_btn
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Josh Nussbaum, Diego Salazar
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-11-29 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: serialport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: Hook up easy button via USB serial port and trigger shell commands
33
+ email:
34
+ - joshnuss@gmail.com
35
+ - diego@pixelheadstudio.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/big_ass_button.rb
44
+ - lib/alerter.rb
45
+ - bin/go_easy_btn
46
+ has_rdoc: true
47
+ homepage: https://github.com/joshnuss/easy-button
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ - bin
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 1
62
+ - 8
63
+ - 7
64
+ version: 1.8.7
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.6
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Make things Easy!
79
+ test_files: []
80
+