diff options
Diffstat (limited to 'led_marquee')
-rw-r--r-- | led_marquee/README.md | 31 | ||||
-rw-r--r-- | led_marquee/depends.txt | 4 | ||||
-rw-r--r-- | led_marquee/init.lua | 135 | ||||
-rw-r--r-- | led_marquee/screenshot_20180816_234431.png | bin | 0 -> 664346 bytes | |||
-rw-r--r-- | led_marquee/screenshot_20180816_234431_1.png | bin | 0 -> 664346 bytes | |||
-rw-r--r-- | led_marquee/textures/led_marquee_char_138.png | bin | 272 -> 451 bytes |
6 files changed, 124 insertions, 46 deletions
diff --git a/led_marquee/README.md b/led_marquee/README.md index 3cbf23c..00508dc 100644 --- a/led_marquee/README.md +++ b/led_marquee/README.md @@ -4,9 +4,11 @@ Simply place one or more panels, and set a channel on just the left-most or uppe Then send a character, a string, or one of several control words or codes to that channel from a Mesecons Lua Controller and the mod will try to display it. -A single character will be displayed on the connected panel. A numeric message (i.e. not a string) will display the first digit on the connected panel. +A single character will be displayed on the connected panel. -Strings will be displayed using all panels in a lineup, so long as they all face the same way, starting from the panel the Lua Controller is connected to, going left to right. The other panels in the line do not need to be connected to anything - think of them as being connected together internally. Only the panel at the far left need be connected to the Lua Controller. +A numeric message (i.e. not a string) will be converted into a string. + +Strings of all types (other than the keywords below) will be displayed using all panels in a lineup, so long as they all face the same way, starting from the panel the Lua Controller is connected to, going left to right. The other panels in the line do not need to be connected to anything - think of them as being connected together internally. Only the panel at the far left need be connected to the Lua Controller. The string will spread down the line until either a panel is found that faces the wrong way, or has a channel that's not empty/nil and is set to something other than what the first is set to, or if a node is encountered that is not an alpha-numeric panel at all. @@ -40,13 +42,22 @@ This mod uses the full ISO-8859-1 character set (see https://en.wikipedia.org/wi If a string is prefixed with character code 255, it is treated as UTF-8 and passed through a simple translation function. Only characters with codes greater than 159 are altered; normal ASCII text, color codes, control codes, and the above symbols are passed through unchanged. Note that in this mode, a character code over 159 is treated as the first byte of a two-byte symbol. The panels also respond to these control messages: -the keywords "off", "colon" and "period" translate to a blank space, ":", and ".", respectively (they're leftover from the nixie tubes fork, but might be useful anyway) -* "del" is mapped to character #127, a square with an X in it. -* "allon" is mapped to character #144, the full/all-on block graphic. -* "cursor" or character code 31 will display a short, thick, flashing line at the bottom of the panel. -* "off_multi" turns all panels in a lineup or wall off - essentially a "clear screen" command. -* "allon_multi" turns on all LEDs of all panels in a lineup/wall (by filling them with char #144). +* "clear" turns all panels in a lineup or wall off - essentially a "clear screen" command. +* "allon" fills all panels in a lineup/wall with char(144), i.e. the reverse of "clear". +* "start_scroll" starts the automatic scrolling function, repeatedly moving the last displayed message to the left one character space each time the scroll timer runs out (and automatically restarting it, natch). The scroll action will spread across the line, and down a multi-line wall (just set a new, different channel on the first row you want to exclude), and will continue until "stop_scroll" or any displayable message is received. + + As it advances through the message, the scroll code will search through the message for a printable character, on each scroll step, basically stripping-out color code, and using just the last one before the new start position. This is done in order to keep a constant visible speed (the text will still be colored properly though). +* "stop_scroll" does just what it says - it stops the auto-scroll timer. +* "scroll_speed" followed by a decimal number (in the string, not a byte value) sets the time between scroll steps. Minimum 0.5s, maximum 5s. +* "scroll_step" will immediately advance the last-displayed message by one character. Omit the above automatic scrolling keywords, and use ONLY this keyword instead if you want to let your LuaController control the scrolling speed. Optionally, you can follow this with a number and the scroll code will skip forward that many bytes into the message, starting from the current position, before starting the above-mentioned color-vs-character search. Essentially, this value will roughly translate to the number of printable characters to skip. +* "get" will read the one character (as a numerical character value) currently displayed by the master panel (by reading its node name) +* "getstr" will read the last-stored message for the entire lineup/wall (from the master panel's meta). Note that even if the message has been or is being scrolled, you'll get the original stored message. +* "getindex" will read the scroll index position in that message, which will always point at a printable character, per the above color-versus-character search. + +During a scroll event, the printed string is padded with spaces (one in auto mode, or as many as the skip value when manually stepping). + +If you need vertical scrolling, you will have to handle that yourself (since the size of a screen/wall is not hard-coded). A byte value of 0 to 27 in a string will change colors (i.e. string.char(0 to 27) ). @@ -64,8 +75,10 @@ A byte value of 28 in a string will act as a line feed (I would have used 10, bu A byte value of 29 in a string signals a cursor position command. The next two byte values select a column and row, respectively. The next character after the row byte will be printed there, and the rest of the string then continues printing from that spot onward with normal line wrapping, colors and so forth. Note that any string that does NOT contain cursor positioning commands will automatically start printing at the upper-left. -You can use "get" and "getstr" to read the one character from the connected panel. These messages will not read the other panels in the lineup. +Any number of color, line feed, and cursor position commands may be present in a string, making it possible to "frame-buffer" a screen full of text into a string before printing it. All panels emit a small amount of light when displaying something. The panels only mount on a wall. + +The "master"/connected panel stores the last-displayed message and some other details in its metadata, so you may occasionally need to dig and re-place the panel if things go wonky (this won't happen during normal use, but it may happen if you're making lots of changes to the panels' layout, channel names, etc). diff --git a/led_marquee/depends.txt b/led_marquee/depends.txt index 8c54f92..98f1e3e 100644 --- a/led_marquee/depends.txt +++ b/led_marquee/depends.txt @@ -1,5 +1,5 @@ default digilines mesecons_luacontroller -mesecons_microcontroller -mesecons_lamp +mesecons_microcontroller? +mesecons_lamp? diff --git a/led_marquee/init.lua b/led_marquee/init.lua index f60dfbd..5bfc1e0 100644 --- a/led_marquee/init.lua +++ b/led_marquee/init.lua @@ -1,6 +1,8 @@ -- simple LED marquee mod -- by Vanessa Dannenberg +led_marquee = {} + local S if minetest.get_modpath("intllib") then S = intllib.make_gettext_pair() @@ -53,6 +55,51 @@ local make_iso = function(s) return s2 end +-- scrolling + +led_marquee.set_timer = function(pos, timeout) + local timer = minetest.get_node_timer(pos) + timer:stop() + if timeout > 0 then + local meta = minetest.get_meta(pos) + timer:start(timeout) + end +end + +led_marquee.scroll_text = function(pos, elapsed, skip) + local meta = minetest.get_meta(pos) + local msg = meta:get_string("last_msg") + local channel = meta:get_string("channel") + local index = meta:get_int("index") + if not index or index < 1 or not string.byte(msg, index) then index = 1 end + local len = string.len(msg) + skip = skip or 1 + + index = index + skip + + while index < len and string.byte(msg, index) < 28 do + index = index + 1 + if index > len then index = 1 break end + end + + if string.byte(msg, index - 1) < 28 then + led_marquee.display_msg(pos, channel, string.sub(msg, index - 1)..string.rep(" ", skip + 1)) + else + local i = index - 1 + local color = "" + while i > 0 and string.byte(msg, i) > 27 do + i = i - 1 + if i == 0 then break end + end + if i > 0 then color = string.sub(msg, i, i) end + led_marquee.display_msg(pos, channel, color..string.sub(msg, index)..string.rep(" ", skip + 1)) + end + + meta:set_int("index", index) + if not elapsed or elapsed < 0.5 then return false end + return true +end + -- the nodes: local fdir_to_right = { @@ -71,14 +118,10 @@ local cbox = { wall_side = { -8/16, -8/16, -8/16, -7/16, 8/16, 8/16 } } -local display_string = function(pos, channel, string) - string = string.sub(string, 1, 1024) - if string == "off_multi" then - string = string.rep(" ", 1024) - elseif string == "allon_multi" then - string = string.rep(string.char(144), 1024) - elseif string.sub(string,1,1) == string.char(255) then -- treat it as incoming UTF-8 - string = make_iso(string.sub(string, 2, 1024)) +led_marquee.display_msg = function(pos, channel, msg) + msg = string.sub(msg, 1, 4096) + if string.sub(msg,1,1) == string.char(255) then -- treat it as incoming UTF-8 + msg = make_iso(string.sub(msg, 2, 4096)) end local master_fdir = minetest.get_node(pos).param2 % 8 @@ -90,7 +133,7 @@ local display_string = function(pos, channel, string) master_meta:set_int("last_color", 0) end local i = 1 - local len = string.len(string) + local len = string.len(msg) local wrapped = nil while i <= len do local node = minetest.get_node(pos2) @@ -98,7 +141,7 @@ local display_string = function(pos, channel, string) local meta = minetest.get_meta(pos2) local setchan = nil if meta then setchan = meta:get_string("channel") end - local asc = string.byte(string, i, i) + local asc = string.byte(msg, i, i) if not string.match(node.name, "led_marquee:char_") then if not wrapped then pos2.x = pos.x @@ -118,8 +161,8 @@ local display_string = function(pos, channel, string) i = i + 1 wrapped = nil elseif asc == 29 then - local c = string.byte(string, i+1, i+1) or 0 - local r = string.byte(string, i+2, i+2) or 0 + local c = string.byte(msg, i+1, i+1) or 0 + local r = string.byte(msg, i+2, i+2) or 0 pos2.x = pos.x + (fdir_to_right[fdir+1][1])*c pos2.y = pos.y - r pos2.z = pos.z + (fdir_to_right[fdir+1][2])*c @@ -153,43 +196,65 @@ local on_digiline_receive_string = function(pos, node, channel, msg) if setchan ~= channel then return end if msg and msg ~= "" and type(msg) == "string" then if string.len(msg) > 1 then - if msg == "off" then - minetest.swap_node(pos, { name = "led_marquee:char_32", param2 = fdir + (last_color*8)}) - elseif msg == "colon" then - minetest.swap_node(pos, { name = "led_marquee:char_58", param2 = fdir + (last_color*8)}) - elseif msg == "period" then - minetest.swap_node(pos, { name = "led_marquee:char_46", param2 = fdir + (last_color*8)}) - elseif msg == "del" then - minetest.swap_node(pos, { name = "led_marquee:char_127", param2 = fdir + (last_color*8)}) + if msg == "clear" then + led_marquee.set_timer(pos, 0) + msg = string.rep(" ", 2048) + meta:set_string("last_msg", msg) + led_marquee.display_msg(pos, channel, msg) + meta:set_int("index", 1) elseif msg == "allon" then - minetest.swap_node(pos, { name = "led_marquee:char_144", param2 = fdir + (last_color*8)}) - elseif msg == "cursor" then - minetest.swap_node(pos, { name = "led_marquee:char_31", param2 = fdir + (last_color*8)}) + led_marquee.set_timer(pos, 0) + msg = string.rep(string.char(144), 2048) + meta:set_string("last_msg", msg) + led_marquee.display_msg(pos, channel, msg) + meta:set_int("index", 1) + elseif msg == "start_scroll" then + local timeout = meta:get_int("timeout") + if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end + led_marquee.set_timer(pos, timeout) + elseif msg == "stop_scroll" then + led_marquee.set_timer(pos, 0) + return + elseif string.sub(msg, 1, 12) == "scroll_speed" then + local timeout = tonumber(string.sub(msg, 13)) + if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end + meta:set_int("timeout", timeout) + led_marquee.set_timer(pos, timeout) + elseif string.sub(msg, 1, 11) == "scroll_step" then + local skip = tonumber(string.sub(msg, 12)) + led_marquee.scroll_text(pos, nil, skip) + elseif msg == "get" then -- get the master panel's displayed char as ASCII numerical value + digilines.receptor_send(pos, digiline.rules.default, channel, tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)"))) -- wonderfully horrible string manipulaiton + elseif msg == "getstr" then -- get the last stored message + digilines.receptor_send(pos, digiline.rules.default, channel, meta:get_string("last_msg")) + elseif msg == "getindex" then -- get the scroll index + digilines.receptor_send(pos, digiline.rules.default, channel, meta:get_int("index")) else - display_string(pos, channel, msg) + led_marquee.set_timer(pos, 0) + meta:set_string("last_msg", msg) + led_marquee.display_msg(pos, channel, msg) + meta:set_int("index", 1) end else local asc = string.byte(msg) if asc > 30 and asc < 256 then minetest.swap_node(pos, { name = "led_marquee:char_"..asc, param2 = fdir + (last_color*8)}) + meta:set_string("last_msg", tostring(msg)) + meta:set_int("index", 1) elseif asc < 28 then last_color = asc meta:set_int("last_color", asc) - elseif msg == "get" then -- get value as ASCII numerical value - digiline:receptor_send(pos, digiline.rules.default, channel, tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)"))) -- wonderfully horrible string manipulaiton - elseif msg == "getstr" then -- get actual char - digiline:receptor_send(pos, digiline.rules.default, channel, string.char(tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)")))) end end elseif msg and type(msg) == "number" then - if msg == 0 then - minetest.swap_node(pos, { name = "led_marquee:char_32", param2 = fdir + (last_color*8)}) - elseif msg > 30 then - minetest.swap_node(pos, { name = "led_marquee:char_"..tostring(msg), param2 = fdir + (last_color*8)}) - end + meta:set_string("last_msg", tostring(msg)) + led_marquee.display_msg(pos, channel, tostring(msg)) + meta:set_int("index", 1) end end +-- the nodes! + for i = 31, 255 do local groups = { cracky = 2, not_in_creative_inventory = 1} local light = LIGHT_MAX-2 @@ -244,13 +309,13 @@ for i = 31, 255 do action = on_digiline_receive_string, }, }, - drop = "led_marquee:char_32" + drop = "led_marquee:char_32", + on_timer = led_marquee.scroll_text }) end -- crafts - minetest.register_craft({ output = "led_marquee:char_32 6", recipe = { diff --git a/led_marquee/screenshot_20180816_234431.png b/led_marquee/screenshot_20180816_234431.png Binary files differnew file mode 100644 index 0000000..c154de3 --- /dev/null +++ b/led_marquee/screenshot_20180816_234431.png diff --git a/led_marquee/screenshot_20180816_234431_1.png b/led_marquee/screenshot_20180816_234431_1.png Binary files differnew file mode 100644 index 0000000..c154de3 --- /dev/null +++ b/led_marquee/screenshot_20180816_234431_1.png diff --git a/led_marquee/textures/led_marquee_char_138.png b/led_marquee/textures/led_marquee_char_138.png Binary files differindex ce35cc2..091a34c 100644 --- a/led_marquee/textures/led_marquee_char_138.png +++ b/led_marquee/textures/led_marquee_char_138.png |