Class: I2C::AlphaDisplayApp

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

Instance Method Summary collapse

Instance Method Details

#mainObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/i2c/alpha_display_app.rb', line 6

def main
    opts = Trollop::options do
        version "i2c-disp #{AlphaDisplay::VERSION} (c) 2016 @reednj ([email protected])"
        banner "Usage: i2c-disp [options]"
        opt :device, "I2C device id for the display", :type => :integer, :default => 0x70
    end

    @display = AlphaDisplay.new(opts[:device])

    STDIN.each_line do |line|
        begin
            a = parse_line(line)
            @display.set a
        rescue => e
            puts e.to_s
        end
    end
    
end

#parse_line(s) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/i2c/alpha_display_app.rb', line 26

def parse_line(s)
    s.strip!

    if s.to_i.to_s == s
        return s.to_i
    end

    begin
        return Float(s)
    rescue
        return s
    end
end