-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.lua
110 lines (90 loc) · 3.04 KB
/
display.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require("lib/tablelib")
local graphics = require("graphics")
local colors = require("colors")
local alphabet = require("alphabet")
Display = {}
function Display:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function Display:show(text, color, slide)
local fb = graphics.find_device("RPi-Sense FB")
local fd = io.open(fb, "w")
text_color = colors.color_to_bin(string.sub(color, 2, color:len()))
if slide == true then
local panorama = {}
for i = 1, #text do
local letter = text:sub(i, i)
local pixels = alphabet[string.upper(letter)]
local res = colors.letter_to_pixels(pixels, text_color)
for _, pix in ipairs(res) do
table.insert(panorama, pix)
end
end
local first = 1
local iterations = (text:len() - 1) * 8 + 1
for iter = 1, iterations do
local window = {}
if iter == 1 then
window = table.slice(panorama, 1, 64)
elseif iter == iterations then
window = table.slice(panorama, (text:len() - 1) * 64 + 1)
else
local old_first = first
local multiplier = math.floor(old_first / 64) * 64
local line = 1
while line <= 8 do
local j = (8 * line) + multiplier
local counter = 0
local last_i = first
for i = first, j do
counter = counter + 1
table.insert(window, panorama[i])
last_i = i
end
for ix = 1, 8 - counter do
table.insert(window, panorama[last_i + 57])
last_i = last_i + 1
end
first = first + 8
line = line + 1
end
first = old_first
end
if math.fmod(first, 8) == 0 then
first = first + 56
end
first = first + 1
for j, clr in ipairs(window) do
fd:seek("set", 2 * (j - 1))
fd:write(clr)
end
os.execute("sleep 0.1")
end
else
for i = 1, #text do
local letter = text:sub(i, i)
local pixels = alphabet[string.upper(letter)]
local res = colors.letter_to_pixels(pixels, text_color)
for j, clr in ipairs(res) do
fd:seek("set", 2 * (j - 1))
fd:write(clr)
end
os.execute("sleep 2")
self:clear()
end
end
fd:close()
end
function Display:clear()
local fb = graphics.find_device("RPi-Sense FB")
local fd = io.open(fb, "w")
for i = 1, 64 do
fd:seek("set", 2 * (i - 1))
fd:write(colors.color_to_bin("000000"))
end
fd:close()
end
return Display