scrollysign 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/lib/scrollysign.rb +192 -0
- metadata +80 -0
data/lib/scrollysign.rb
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'serialport'
|
2
|
+
|
3
|
+
class ScrollySign
|
4
|
+
class TextBuilder
|
5
|
+
def initialize
|
6
|
+
@text = ""
|
7
|
+
end
|
8
|
+
|
9
|
+
def text(text)
|
10
|
+
@text << text.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def control(*controls)
|
14
|
+
controls.each do |control|
|
15
|
+
@text << ScrollySign::CONTROLS.fetch(control)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
INITIALISATION_STRING = "\x00" * 5
|
25
|
+
SOH = "\x01"
|
26
|
+
STX = "\x02"
|
27
|
+
EOT = "\x04"
|
28
|
+
ESC = "\x1b"
|
29
|
+
|
30
|
+
CONTROLS = {
|
31
|
+
"enable_double_high_characters" => "\x051",
|
32
|
+
"disable_double_high_characters" => "\x050",
|
33
|
+
"enable_true_descenders" => "\x061",
|
34
|
+
"disable_true_descenders" => "\x060",
|
35
|
+
"enable_character_flash" => "\x071",
|
36
|
+
"disable_character_flash" => "\x070",
|
37
|
+
"no_hold_speed" => "\x09",
|
38
|
+
"new_line" => "\x0d",
|
39
|
+
"call_date_mm/dd/yy" => "\x0b0",
|
40
|
+
"call_date_dd/mm/yy" => "\x0b1",
|
41
|
+
"call_date_mm-dd-yy" => "\x0b2",
|
42
|
+
"call_date_dd-mm-yy" => "\x0b3",
|
43
|
+
"call_date_mm.dd.yy" => "\x0b4",
|
44
|
+
"call_date_dd.mm.yy" => "\x0b5",
|
45
|
+
"call_date_mm dd yy" => "\x0b6",
|
46
|
+
"call_date_dd mm yy" => "\x0b7",
|
47
|
+
"call_date_mmm.dd, yyyy" => "\x0b8",
|
48
|
+
"call_date_day_of_week" => "\x0b9",
|
49
|
+
"new_page" => "\x0c",
|
50
|
+
"new_line" => "\x0d",
|
51
|
+
"call_string" => "\x10", # follow by label of string file
|
52
|
+
"disable_wide_characters" => "\x11",
|
53
|
+
"enable_wide_characters" => "\x12",
|
54
|
+
"call_time" => "\x13",
|
55
|
+
"call_small_dots_picture" => "\x14", # follow by label of dots picture
|
56
|
+
"speed_1" => "\x15", # slowest
|
57
|
+
"speed_2" => "\x16",
|
58
|
+
"speed_3" => "\x17",
|
59
|
+
"speed_4" => "\x18",
|
60
|
+
"speed_5" => "\x19",
|
61
|
+
"select_character_set" => "\x20", # follow by character set specifier
|
62
|
+
|
63
|
+
"red" => "\x1c1",
|
64
|
+
"green" => "\x1c2",
|
65
|
+
"amber" => "\x1c3",
|
66
|
+
"dim_red" => "\x1c4",
|
67
|
+
"dim_green" => "\x1c5",
|
68
|
+
"brown" => "\x1c6",
|
69
|
+
"orange" => "\x1c7",
|
70
|
+
"yellow" => "\x1c8",
|
71
|
+
"rainbow_1" => "\x1c9",
|
72
|
+
"rainbow_2" => "\x1cA",
|
73
|
+
"color_mix" => "\x1cB",
|
74
|
+
"autocolor" => "\x1cC",
|
75
|
+
"rgb" => "\x1cZ", # alpha 3.0 only: follow by RRGGBB
|
76
|
+
|
77
|
+
"proportional_characters" => "\x1e0",
|
78
|
+
"fixed_width_characters" => "\x1e1"
|
79
|
+
}
|
80
|
+
|
81
|
+
COMMANDS = {
|
82
|
+
"write_text_file" => "A",
|
83
|
+
"write_string_file" => "G"
|
84
|
+
}
|
85
|
+
|
86
|
+
MODES = {
|
87
|
+
"rotate" => 'a',
|
88
|
+
"hold" => 'b',
|
89
|
+
"flash" => 'c',
|
90
|
+
"roll_up" => 'e',
|
91
|
+
"roll_down" => 'f',
|
92
|
+
"roll_left" => 'g',
|
93
|
+
"roll_right" => 'h',
|
94
|
+
"wipe_up" => 'i',
|
95
|
+
"wipe_down" => 'j',
|
96
|
+
"wipe_left" => 'k',
|
97
|
+
"wipe_right" => 'l',
|
98
|
+
"scroll" => 'm',
|
99
|
+
"automode" => 'o',
|
100
|
+
"roll_in" => 'p',
|
101
|
+
"roll_out" => 'q',
|
102
|
+
"wipe_in" => 'r',
|
103
|
+
"wipe_out" => 's',
|
104
|
+
"compressed_rotate" => 't', # some models only
|
105
|
+
"explode" => 'u', # alpha 3.0 only
|
106
|
+
"clock" => 'v', # alpha 3.0 only
|
107
|
+
|
108
|
+
"special_twinkle" => 'n0',
|
109
|
+
"special_sparkle" => 'n1',
|
110
|
+
"special_snow" => 'n2',
|
111
|
+
"special_interlock" => 'n3',
|
112
|
+
"special_switch" => 'n4',
|
113
|
+
"special_slide" => 'n5',
|
114
|
+
"special_circle_colors" => 'n5',
|
115
|
+
"special_spray" => 'n6',
|
116
|
+
"special_starburst" => 'n7',
|
117
|
+
"special_welcome" => 'n8',
|
118
|
+
"special_slot_machine" => 'n9',
|
119
|
+
"special_news_flash" => 'nA', # Betabrite 1036 only
|
120
|
+
"special_trumpet_animation" => 'nB', # Betabrite 1036 only
|
121
|
+
"special_cycle_colors" => 'nC' # AlphaEclipse 3600 only
|
122
|
+
}
|
123
|
+
|
124
|
+
DISPLAY_POSITIONS = {
|
125
|
+
"middle_line" => ' ',
|
126
|
+
"top_line" => '"',
|
127
|
+
"bottom_line" => '&',
|
128
|
+
"fill" => '0',
|
129
|
+
"left" => '1',
|
130
|
+
"right" => '2'
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
def initialize(port, baud_rate = 9600)
|
135
|
+
@type_code = "Z" # all types of sign
|
136
|
+
@sign_address = "00" # all signs
|
137
|
+
|
138
|
+
@port = SerialPort.new(port, baud_rate)
|
139
|
+
if block_given?
|
140
|
+
begin
|
141
|
+
yield self
|
142
|
+
ensure
|
143
|
+
close
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def port
|
149
|
+
@port
|
150
|
+
end
|
151
|
+
|
152
|
+
def close
|
153
|
+
@port.close
|
154
|
+
@port = nil
|
155
|
+
end
|
156
|
+
|
157
|
+
def c(name)
|
158
|
+
CONTROLS.fetch(name)
|
159
|
+
end
|
160
|
+
|
161
|
+
def build_text(&block)
|
162
|
+
builder = TextBuilder.new
|
163
|
+
if block.arity != 1
|
164
|
+
builder.instance_eval(&block)
|
165
|
+
else
|
166
|
+
yield builder
|
167
|
+
end
|
168
|
+
builder.to_s
|
169
|
+
end
|
170
|
+
|
171
|
+
def write_text(text, file_label = "A", mode = nil, display_position = nil)
|
172
|
+
data = if mode
|
173
|
+
"#{file_label}#{ESC}#{DISPLAY_POSITIONS.fetch((display_position || 'fill').to_s)}#{MODES.fetch(mode.to_s)}#{text}"
|
174
|
+
else
|
175
|
+
"#{file_label}#{text}"
|
176
|
+
end
|
177
|
+
|
178
|
+
write_raw('write_text_file', data)
|
179
|
+
end
|
180
|
+
|
181
|
+
def write_string(text, file_label)
|
182
|
+
write_raw('write_string_file', "#{file_label}#{text}")
|
183
|
+
end
|
184
|
+
|
185
|
+
def write_raw(command, data)
|
186
|
+
raise "port is closed" unless port
|
187
|
+
|
188
|
+
command_code = COMMANDS.fetch(command)
|
189
|
+
|
190
|
+
@port.write "#{INITIALISATION_STRING}#{SOH}#{@type_code}#{@sign_address}#{STX}#{command_code}#{data}#{EOT}"
|
191
|
+
end
|
192
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrollysign
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Roger Nesbitt
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-22 00:00:00 +13:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby-serialport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Driver to write to Adaptive LED signs
|
36
|
+
email: roger@youdo.co.nz
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/scrollysign.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage:
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Driver to write to Adaptive LED signs
|
79
|
+
test_files: []
|
80
|
+
|