Class: BetaBrite::Device

Inherits:
Object
  • Object
show all
Includes:
Files
Defined in:
lib/betabrite/device.rb

Direct Known Subclasses

Serial, USB

Constant Summary collapse

HEADER =

Synopsis

This class assembles all packets (different files) and yields the data that needs to be written back to the caller of the BetaBrite#write method.

[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ]
STX =
0x02.chr
ETX =
0x03.chr
EOT =
0x04.chr
ESC =
0x1b.chr
DLE =
0x10.chr
STRING =
0x14.chr
CR =
0x0d.chr
MEMORY_CODE =
"E$"
SIGN_TYPE =

Beta Brite sign

0x5a.chr

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Device

Returns a new instance of Device.

Yields:

  • (_self)

Yield Parameters:



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

def initialize
  # Default address is "00" which means broadcast to all signs
  @sign_address = [ 0x30, 0x30 ]
  @string_files = []
  @text_files   = []
  @dots_files   = []
  @memory       = []

  # This shouldn't change except for unit testing
  @sleep_time = 0
  yield self if block_given?
end

Instance Attribute Details

#dots_filesObject (readonly)

Returns the value of attribute dots_files.



24
25
26
# File 'lib/betabrite/device.rb', line 24

def dots_files
  @dots_files
end

#memoryObject (readonly)

Returns the value of attribute memory.



24
25
26
# File 'lib/betabrite/device.rb', line 24

def memory
  @memory
end

#sleep_timeObject

Returns the value of attribute sleep_time.



23
24
25
# File 'lib/betabrite/device.rb', line 23

def sleep_time
  @sleep_time
end

#string_filesObject (readonly)

Returns the value of attribute string_files.



24
25
26
# File 'lib/betabrite/device.rb', line 24

def string_files
  @string_files
end

#text_filesObject (readonly)

Returns the value of attribute text_files.



24
25
26
# File 'lib/betabrite/device.rb', line 24

def text_files
  @text_files
end

Instance Method Details

#allocate(&block) ⇒ Object



51
52
53
# File 'lib/betabrite/device.rb', line 51

def allocate(&block)
  @memory.push(*(BetaBrite::Memory::Factory.find(&block)))
end

#clear_memory!Object



55
56
57
58
# File 'lib/betabrite/device.rb', line 55

def clear_memory!
  @memory = []
  self.write_memory!
end

#dotsfile(label, rows = nil, columns = nil, picture = nil, &block) ⇒ Object



47
48
49
# File 'lib/betabrite/device.rb', line 47

def dotsfile(label, rows = nil, columns = nil, picture = nil, &block)
  @dots_files << Dots.new(label, rows, columns, picture,&block)
end

#memory_messageObject



69
70
71
# File 'lib/betabrite/device.rb', line 69

def memory_message
"#{header}#{STX}#{MEMORY_CODE}#{@memory.map { |packet| packet.to_s }.join('')}#{tail}"
end

#messageObject

Get the message to be sent to the sign



61
62
63
64
65
66
67
# File 'lib/betabrite/device.rb', line 61

def message
  header +
    @text_files.each { |tf| tf.to_s }.join('') +
    @string_files.each { |tf| tf.to_s }.join('') +
    @dots_files.each { |tf| tf.to_s }.join('') +
    tail
end

#stringfile(label, message = nil, &block) ⇒ Object



43
44
45
# File 'lib/betabrite/device.rb', line 43

def stringfile(label, message = nil, &block)
  @string_files << Files::String.new(label, message, &block)
end

#textfile(label = 'A', &block) ⇒ Object



39
40
41
# File 'lib/betabrite/device.rb', line 39

def textfile(label = 'A', &block)
  @text_files << Text.new(label, &block)
end