Class: BetaBrite::Device
- Inherits:
-
Object
- Object
- BetaBrite::Device
- Includes:
- Files
- Defined in:
- lib/betabrite/device.rb
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
-
#dots_files ⇒ Object
readonly
Returns the value of attribute dots_files.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
-
#string_files ⇒ Object
readonly
Returns the value of attribute string_files.
-
#text_files ⇒ Object
readonly
Returns the value of attribute text_files.
Instance Method Summary collapse
- #allocate(&block) ⇒ Object
- #clear_memory! ⇒ Object
- #dotsfile(label, rows = nil, columns = nil, picture = nil, &block) ⇒ Object
-
#initialize {|_self| ... } ⇒ Device
constructor
A new instance of Device.
- #memory_message ⇒ Object
-
#message ⇒ Object
Get the message to be sent to the sign.
- #stringfile(label, message = nil, &block) ⇒ Object
- #textfile(label = 'A', &block) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Device
Returns a new instance of Device.
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_files ⇒ Object (readonly)
Returns the value of attribute dots_files.
24 25 26 |
# File 'lib/betabrite/device.rb', line 24 def dots_files @dots_files end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
24 25 26 |
# File 'lib/betabrite/device.rb', line 24 def memory @memory end |
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
23 24 25 |
# File 'lib/betabrite/device.rb', line 23 def sleep_time @sleep_time end |
#string_files ⇒ Object (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_files ⇒ Object (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_message ⇒ Object
69 70 71 |
# File 'lib/betabrite/device.rb', line 69 def "#{header}#{STX}#{MEMORY_CODE}#{@memory.map { |packet| packet.to_s }.join('')}#{tail}" end |
#message ⇒ Object
Get the message to be sent to the sign
61 62 63 64 65 66 67 |
# File 'lib/betabrite/device.rb', line 61 def 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 |