go_easy_btn 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/go_easy_btn.rb +15 -7
  2. metadata +3 -3
data/lib/go_easy_btn.rb CHANGED
@@ -6,24 +6,25 @@ class GoEasyButton
6
6
  BTN_COMMAND = 'PRESSED'
7
7
 
8
8
  def initialize(options = {})
9
- raise 'not found serial port has been' unless File.exists? options[:dev]
9
+ raise Errno::ENOENT, 'not found serial port has been' unless File.exists? options[:dev]
10
10
  @cmd = options[:cmd]
11
11
  @device = options[:dev]
12
- @port = options[:baud] || 115200
12
+ @baud = options[:baud] || 115200
13
13
  @count = 0
14
14
  @start_time = Time.now
15
15
  end
16
16
 
17
17
  def make_it_easy
18
- puts "Making It Easy\n\n"
19
-
20
- SerialPort.open @device, @port do |port|
18
+ SerialPort.open @device, @baud do |port|
21
19
  begin
20
+ puts "Making It Easy\n\n"
22
21
  while data = port.readline
23
22
  run_command if data.strip == BTN_COMMAND
24
23
  end
25
- rescue Interrupt, EOFError
24
+ rescue Interrupt
26
25
  puts "\rgoing bye bye now", stats(true)
26
+ rescue EOFError
27
+ handle_disconnect
27
28
  end
28
29
  end
29
30
  end
@@ -33,7 +34,7 @@ class GoEasyButton
33
34
  def run_command
34
35
  puts border
35
36
 
36
- Alerter.alert 'I am going to make this easy.'
37
+ Thread.new { Alerter.alert 'I am going to make this easy?' }
37
38
  puts "Executing: #{@cmd}"
38
39
 
39
40
  success = system @cmd
@@ -49,6 +50,13 @@ class GoEasyButton
49
50
  puts msg, border, stats
50
51
  end
51
52
 
53
+ def handle_disconnect(msg = 'disconnected')
54
+ make_it_easy
55
+ rescue Errno::ENOENT # still not connected
56
+ sleep 1
57
+ retry
58
+ end
59
+
52
60
  private
53
61
 
54
62
  def stats(verbose = false)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josh Nussbaum, Diego Salazar
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-11-29 00:00:00 -05:00
17
+ date: 2012-11-30 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency