Class: LD220

Inherits:
Object
  • Object
show all
Defined in:
lib/ld220.rb,
lib/ld220/version.rb,
lib/ld220/mode/utc.rb

Defined Under Namespace

Classes: Mode

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device, mode, options = {}) ⇒ LD220

Returns a new instance of LD220.



7
8
9
10
11
12
# File 'lib/ld220.rb', line 7

def initialize(device, mode, options = {})
  extend mode
  options[:speed] ||= 9600
  @debug = options[:debug]
  @display = Serial.new device, options[:speed]
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/ld220.rb', line 5

def debug
  @debug
end

Instance Method Details

#type(string, delay = 0.1) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ld220.rb', line 14

def type(string, delay = 0.1)
  clear
  sleep delay
  string.split('').each do |char|
    write char
    sleep delay
  end
end

#write(data) ⇒ Object



23
24
25
26
27
# File 'lib/ld220.rb', line 23

def write(data)
  data = data.encode Encoding::US_ASCII
  puts "Sending: #{data.inspect}" if @debug
  @display.write data
end