betabrite 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +7 -0
- data/EXAMPLES +28 -73
- data/History.txt +16 -0
- data/Manifest.txt +35 -0
- data/{README → README.txt} +58 -52
- data/Rakefile +11 -0
- data/lib/betabrite.rb +6 -120
- data/lib/betabrite/autotest.rb +43 -0
- data/lib/betabrite/base.rb +86 -0
- data/lib/betabrite/files.rb +4 -0
- data/lib/betabrite/files/dots.rb +24 -0
- data/lib/betabrite/files/file_dsl.rb +18 -0
- data/lib/betabrite/files/string.rb +22 -0
- data/lib/betabrite/files/text.rb +122 -0
- data/lib/{memory → betabrite}/memory.rb +27 -5
- data/lib/betabrite/serial.rb +28 -0
- data/lib/{string.rb → betabrite/string.rb} +41 -15
- data/lib/betabrite/usb.rb +64 -0
- data/script/alloc.rb +21 -0
- data/script/clear_memory.rb +16 -0
- data/script/client.rb +39 -0
- data/script/dots_file.rb +35 -0
- data/script/server.rb +12 -0
- data/script/sign_test.rb +17 -0
- data/script/stock_alloc.rb +81 -0
- data/script/stock_client.rb +40 -0
- data/script/stockdata.rb +65 -0
- data/test/helper.rb +6 -0
- data/test/{tc_many_mem.rb → test_many_mem.rb} +6 -10
- data/test/{tc_memory.rb → test_memory.rb} +11 -24
- data/test/{tc_set_string.rb → test_set_string.rb} +5 -9
- data/test/test_string.rb +34 -0
- data/test/test_text_file.rb +19 -0
- data/test/test_usb_betabrite.rb +94 -0
- metadata +94 -60
- data/CHANGELOG +0 -10
- data/NOTES +0 -29
- data/lib/bb_version.rb +0 -3
- data/lib/files/dotsfile.rb +0 -24
- data/lib/files/stringfile.rb +0 -22
- data/lib/files/textfile.rb +0 -114
- data/test/bb_override.rb +0 -5
- data/test/tc_string.rb +0 -20
- data/test/tc_text_file.rb +0 -18
- data/test/ts_bb.rb +0 -7
data/.autotest
ADDED
data/EXAMPLES
CHANGED
@@ -2,85 +2,40 @@
|
|
2
2
|
|
3
3
|
== Allocate Memory
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
dots = BetaBrite::Memory::Dots.new('1', 7, 7)
|
14
|
-
text = BetaBrite::Memory::Text.new('A', 256)
|
15
|
-
|
16
|
-
sign.add text
|
17
|
-
sign.add dots
|
18
|
-
sign.add string
|
19
|
-
|
20
|
-
sign.allocate { |text|
|
21
|
-
sp.write text
|
22
|
-
}
|
5
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
6
|
+
sign.allocate do |memory|
|
7
|
+
memory.text('A', 4096)
|
8
|
+
memory.string('0', 64)
|
9
|
+
memory.dots('1', 7, 7)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
bb.write_memory!
|
23
13
|
|
24
14
|
== Reset the sign
|
25
15
|
|
26
|
-
|
27
|
-
require 'serialport'
|
28
|
-
|
29
|
-
sp = SerialPort.new(0, 9600, 8, 1, SerialPort::NONE)
|
16
|
+
BetaBrite::Serial.new('/dev/ttyUSB0').clear_memory!
|
30
17
|
|
31
|
-
sign = BetaBrite.new
|
32
|
-
sign.add BetaBrite::Memory::Clear.new
|
33
|
-
|
34
|
-
sign.allocate { |text|
|
35
|
-
sp.write text
|
36
|
-
}
|
37
|
-
|
38
18
|
== Write a text file
|
39
19
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
tf.message = ARGV[0]
|
48
|
-
|
49
|
-
sign.add tf
|
50
|
-
|
51
|
-
sign.write { |text|
|
52
|
-
sp.write text
|
53
|
-
}
|
20
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
21
|
+
sign.textfile do
|
22
|
+
print left_arrow + string("Hello ").green
|
23
|
+
print string(" world.").green + sail_boat
|
24
|
+
end
|
25
|
+
end
|
26
|
+
bb.write!
|
54
27
|
|
55
28
|
== Write a text file that references a string file
|
56
29
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# Set up a BetaBrite::String
|
70
|
-
name = BetaBrite::String.new('James',
|
71
|
-
:color => BetaBrite::String::Color::AMBER
|
72
|
-
)
|
73
|
-
# Create a StringFile which can be modified without making the sign blink.
|
74
|
-
sf = BetaBrite::StringFile.new('0', name)
|
75
|
-
|
76
|
-
# Set the TextFile message and reference the StringFile
|
77
|
-
tf.message = BetaBrite::String.new("Aaron #{sf.id} Patterson")
|
78
|
-
|
79
|
-
|
80
|
-
sign.add tf
|
81
|
-
sign.add sf
|
82
|
-
|
83
|
-
sign.write { |text|
|
84
|
-
sp.write text
|
85
|
-
}
|
86
|
-
|
30
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
31
|
+
sign.stringfile('0') do
|
32
|
+
print string("cruel").red
|
33
|
+
end
|
34
|
+
|
35
|
+
sign.textfile do
|
36
|
+
print left_arrow + string("Hello ").green
|
37
|
+
print stringfile("0")
|
38
|
+
print string(" world.").green + sail_boat
|
39
|
+
end
|
40
|
+
end
|
41
|
+
bb.write!
|
data/History.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
=== 1.0.0
|
2
|
+
|
3
|
+
* 3 Major Enhancements:
|
4
|
+
|
5
|
+
* Adding support for USB betabrite signs (Thanks Thought Hammer)
|
6
|
+
* Added an autotest hook
|
7
|
+
* Changed API to use more DSL type interface
|
8
|
+
|
9
|
+
=== 0.0.2
|
10
|
+
|
11
|
+
* Added new syntax to BetaBrite::String and BetaBrite::TextFile
|
12
|
+
|
13
|
+
=== 0.0.1
|
14
|
+
|
15
|
+
* First release
|
16
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
.autotest
|
2
|
+
EXAMPLES
|
3
|
+
History.txt
|
4
|
+
LICENSE
|
5
|
+
Manifest.txt
|
6
|
+
README.txt
|
7
|
+
Rakefile
|
8
|
+
lib/betabrite.rb
|
9
|
+
lib/betabrite/autotest.rb
|
10
|
+
lib/betabrite/base.rb
|
11
|
+
lib/betabrite/files.rb
|
12
|
+
lib/betabrite/files/dots.rb
|
13
|
+
lib/betabrite/files/file_dsl.rb
|
14
|
+
lib/betabrite/files/string.rb
|
15
|
+
lib/betabrite/files/text.rb
|
16
|
+
lib/betabrite/memory.rb
|
17
|
+
lib/betabrite/serial.rb
|
18
|
+
lib/betabrite/string.rb
|
19
|
+
lib/betabrite/usb.rb
|
20
|
+
script/alloc.rb
|
21
|
+
script/clear_memory.rb
|
22
|
+
script/client.rb
|
23
|
+
script/dots_file.rb
|
24
|
+
script/server.rb
|
25
|
+
script/sign_test.rb
|
26
|
+
script/stock_alloc.rb
|
27
|
+
script/stock_client.rb
|
28
|
+
script/stockdata.rb
|
29
|
+
test/helper.rb
|
30
|
+
test/test_many_mem.rb
|
31
|
+
test/test_memory.rb
|
32
|
+
test/test_set_string.rb
|
33
|
+
test/test_string.rb
|
34
|
+
test/test_text_file.rb
|
35
|
+
test/test_usb_betabrite.rb
|
data/{README → README.txt}
RENAMED
@@ -1,8 +1,20 @@
|
|
1
1
|
= BetaBrite Library
|
2
2
|
|
3
|
-
|
3
|
+
* http://rubyforge.org/projects/betabrite/
|
4
|
+
* http://betabrite.rubyforge.org/
|
5
|
+
* mailto:aaron@tenderlovemaking.com
|
4
6
|
|
5
|
-
|
7
|
+
== DESCRIPTION
|
8
|
+
|
9
|
+
Provides a Ruby interface to BetaBrite LED signs.
|
10
|
+
|
11
|
+
== DEPENDENCIES
|
12
|
+
|
13
|
+
* ruby-usb[http://raa.ruby-lang.org/project/ruby-usb/]
|
14
|
+
* ruby-serialport[http://rubyforge.org/projects/ruby-serialport/]
|
15
|
+
|
16
|
+
PLEASE NOTE!!!! You must require 'usb' or 'serialport' depending on which
|
17
|
+
sign you are using!!!!
|
6
18
|
|
7
19
|
== More Information
|
8
20
|
|
@@ -15,42 +27,40 @@ file displayed on the sign is labeled 'A'.
|
|
15
27
|
|
16
28
|
Here is an example of modifying the default sign text:
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
31
|
+
sign.textfile do
|
32
|
+
print ARGV[0]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
bb.write!
|
36
|
+
|
37
|
+
== Autotest Support
|
38
|
+
Here is an example of a .autotest file using the BetaBrite module:
|
39
|
+
|
40
|
+
require 'betabrite/autotest'
|
41
|
+
require 'usb'
|
25
42
|
|
26
|
-
|
27
|
-
|
28
|
-
|
43
|
+
Autotest::BetaBrite.hook(BetaBrite::USB) do |failures, erorrs|
|
44
|
+
failures.rgb('0000FF') if failures.green?
|
45
|
+
end
|
46
|
+
|
47
|
+
You don't need to give the hook method a block, but you can if you'd like to
|
48
|
+
customize your messages.
|
29
49
|
|
30
50
|
== Allocating Memory
|
31
51
|
The memory in the BetaBrite sign should be configured before anything is
|
32
|
-
written to it.
|
33
|
-
|
34
|
-
just haven't figured out if it is possible to allocate memory and write data
|
35
|
-
at the same time.
|
52
|
+
written to it. You only have to configure the memory once before writing to
|
53
|
+
it. So subsequent executions of your script do not require allocating memory.
|
36
54
|
|
37
55
|
Here is an example of allocating memory on the sign:
|
38
56
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
sign.add text
|
48
|
-
sign.add dots
|
49
|
-
sign.add string
|
50
|
-
|
51
|
-
sign.allocate { |text|
|
52
|
-
sp.write text
|
53
|
-
}
|
57
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
58
|
+
sign.memory do |memory|
|
59
|
+
memory.text('A', 4096)
|
60
|
+
memory.string('0', 64)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
bb.write_memory!
|
54
64
|
|
55
65
|
For more examples, see the EXAMPLES file.
|
56
66
|
|
@@ -69,27 +79,18 @@ be displayed unless referenced from a Text File.
|
|
69
79
|
|
70
80
|
Here is an example of referencing a String File from a Text File:
|
71
81
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
tf.message = BetaBrite::String.new("Aaron #{sf.id} Patterson")
|
85
|
-
|
86
|
-
|
87
|
-
sign.add tf
|
88
|
-
sign.add sf
|
89
|
-
|
90
|
-
sign.write { |text|
|
91
|
-
sp.write text
|
92
|
-
}
|
82
|
+
bb = BetaBrite::Serial.new('/dev/ttyUSB0') do |sign|
|
83
|
+
sign.stringfile('0') do
|
84
|
+
print string("cruel").red
|
85
|
+
end
|
86
|
+
|
87
|
+
sign.textfile do
|
88
|
+
print string("Goodbye ").green
|
89
|
+
print stringfile("0")
|
90
|
+
print string(" world.").green + sail_boat
|
91
|
+
end
|
92
|
+
end
|
93
|
+
bb.write!
|
93
94
|
|
94
95
|
Once the String file is allocated and displayed, it can be changed at any
|
95
96
|
time and the string will be updated without the screen going blank.
|
@@ -98,3 +99,8 @@ time and the string will be updated without the screen going blank.
|
|
98
99
|
Dots files can contain pictures. Each pixel is set in an array of strings.
|
99
100
|
See dots_file.rb under the script directory for an example. Or see the
|
100
101
|
EXAMPLES file.
|
102
|
+
|
103
|
+
== Author
|
104
|
+
|
105
|
+
* {Aaron Patterson}[http://tenderlovemaking.com] <aaronp@rubyforge.org>
|
106
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
|
4
|
+
require 'betabrite'
|
5
|
+
|
6
|
+
Hoe.new('betabrite', BetaBrite::VERSION) do |p|
|
7
|
+
p.rubyforge_name = 'betabrite'
|
8
|
+
p.author = 'Aaron Patterson'
|
9
|
+
p.email = 'aaronp@rubyforge.org'
|
10
|
+
p.summary = "Provides a Ruby interface to BetaBrite LED signs"
|
11
|
+
end
|
data/lib/betabrite.rb
CHANGED
@@ -1,121 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require 'files
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
1
|
+
require 'betabrite/string'
|
2
|
+
require 'betabrite/files'
|
3
|
+
require 'betabrite/base'
|
4
|
+
require 'betabrite/usb'
|
5
|
+
require 'betabrite/serial'
|
6
|
+
require 'betabrite/memory'
|
7
7
|
|
8
|
-
# = Synopsis
|
9
|
-
# This class assembles all packets (different files) and yields the data
|
10
|
-
# that needs to be written back to the caller of the BetaBrite#write method.
|
11
|
-
class BetaBrite
|
12
|
-
HEADER = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ]
|
13
|
-
STX = 0x02.chr
|
14
|
-
ETX = 0x03.chr
|
15
|
-
EOT = 0x04.chr
|
16
|
-
ESC = 0x1b.chr
|
17
|
-
DLE = 0x10.chr
|
18
|
-
STRING = 0x14.chr
|
19
|
-
CR = 0x0d.chr
|
20
|
-
MEMORY_CODE = "E$"
|
21
|
-
|
22
|
-
# Beta Brite sign
|
23
|
-
SIGN_TYPE = 0x5a.chr
|
24
|
-
|
25
|
-
attr_reader :sleep_time
|
26
|
-
attr_reader :string_files, :text_files, :dots_files
|
27
|
-
|
28
|
-
def initialize
|
29
|
-
# Default address is "00" which means broadcast to all signs
|
30
|
-
@sign_address = [ 0x30, 0x30 ]
|
31
|
-
@string_files = []
|
32
|
-
@text_files = []
|
33
|
-
@dots_files = []
|
34
|
-
@memory = []
|
35
|
-
|
36
|
-
# This shouldn't change except for unit testing
|
37
|
-
@sleep_time = 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def header
|
41
|
-
header_str = HEADER.collect { |a| a.chr }.join
|
42
|
-
header_str << SIGN_TYPE << @sign_address.collect { |a| a.chr }.join
|
43
|
-
end
|
44
|
-
|
45
|
-
def inspect
|
46
|
-
header
|
47
|
-
end
|
48
|
-
|
49
|
-
def add(packet)
|
50
|
-
if packet.is_a? BetaBrite::Memory
|
51
|
-
add_memory packet
|
52
|
-
elsif packet.is_a? BetaBrite::StringFile
|
53
|
-
add_stringfile packet
|
54
|
-
elsif packet.is_a? BetaBrite::TextFile
|
55
|
-
add_textfile packet
|
56
|
-
elsif packet.is_a? BetaBrite::DotsFile
|
57
|
-
add_dotsfile packet
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def add_stringfile(packet)
|
62
|
-
@string_files << packet
|
63
|
-
end
|
64
|
-
|
65
|
-
def add_textfile(packet)
|
66
|
-
@text_files << packet
|
67
|
-
end
|
68
|
-
|
69
|
-
def add_dotsfile(packet)
|
70
|
-
@dots_files << packet
|
71
|
-
end
|
72
|
-
|
73
|
-
def add_memory(packet)
|
74
|
-
@memory << packet
|
75
|
-
end
|
76
|
-
|
77
|
-
# This method is used to write on the sign
|
78
|
-
def write(&block)
|
79
|
-
if @text_files.length > 0 || @string_files.length > 0
|
80
|
-
write_header &block
|
81
|
-
@text_files.each { |packet| yield packet.to_s }
|
82
|
-
@string_files.each { |packet| block.call(packet.to_s) }
|
83
|
-
write_end &block
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def write_dots(&block)
|
88
|
-
if @dots_files.length > 0
|
89
|
-
write_header &block
|
90
|
-
@dots_files.each { |packet|
|
91
|
-
yield packet.to_s
|
92
|
-
sleep sleep_time
|
93
|
-
}
|
94
|
-
write_end &block
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# This method is used to allocate memory on the sign
|
99
|
-
def allocate(&block)
|
100
|
-
if @memory.length > 0
|
101
|
-
write_header &block
|
102
|
-
yield STX
|
103
|
-
yield MEMORY_CODE
|
104
|
-
@memory.each { |packet| yield packet.to_s }
|
105
|
-
write_end &block
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def write_header(&block)
|
112
|
-
header.split(//).each { |c|
|
113
|
-
yield c
|
114
|
-
sleep sleep_time
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
def write_end(&block)
|
119
|
-
yield EOT
|
120
|
-
end
|
121
|
-
end
|