Class: GoEasyButton

Inherits:
Object
  • Object
show all
Defined in:
lib/go_easy_btn.rb

Constant Summary collapse

BTN_COMMAND =
'PRESSED'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GoEasyButton

Returns a new instance of GoEasyButton.

Raises:

  • (Errno::ENOENT)


8
9
10
11
12
13
14
15
# File 'lib/go_easy_btn.rb', line 8

def initialize(options = {})
  raise Errno::ENOENT, 'not found serial port has been' unless File.exists? options[:dev]
  @cmd = options[:cmd]
  @device = options[:dev]
  @baud = options[:baud] || 115200
  @count = 0
  @start_time = Time.now
end

Instance Method Details

#make_it_easyObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/go_easy_btn.rb', line 17

def make_it_easy
  SerialPort.open @device, @baud do |port| 
    begin
      puts "Making It Easy\n\n"
      while data = port.readline
        run_command if data.strip == BTN_COMMAND
      end
    rescue Interrupt
      puts "\rgoing bye bye now", stats(true)
    rescue EOFError
      handle_disconnect
    end
  end
end