-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrs_audio_trainscreen.lua
87 lines (80 loc) · 2.36 KB
/
rs_audio_trainscreen.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
local dfpwm = require("cc.audio.dfpwm")
local speaker = peripheral.find("speaker")
local decoder = dfpwm.make_decoder()
local monitor = peripheral.find("monitor")
local config = {}
if fs.exists("cfg_rs_audio.txt") then
local cfg_file = io.open("cfg_rs_audio.txt","r")
config = textutils.unserialise(cfg_file:read("*a"))
cfg_file:close()
else
print("Starting Config!")
print("Side?")
config.side = read()
print("Audio Url?")
config.url = read()
print("Additional Audio Url?")
config.url2 = read()
print("Text to Write?")
config.txt = read()
print("Text writing delay?")
config.txt_delay = tonumber(read())
local cfg_file = io.open("cfg_rs_audio.txt","w")
cfg_file:write(textutils.serialise(config))
cfg_file:close()
end
local function playAudio(link)
local request = http.get(link,nil,true)
while true do
local chunk = request.read(16*1024)
if chunk == nil then break end
local buffer = decoder(chunk)
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end
end
request.close()
end
local old_signal = 0
local maxX, maxY = monitor.getSize()
for i1=1, maxX do
for i2=1, maxY do
monitor.setCursorPos(i1,i2)
monitor.write(" ")
end
os.sleep(0.05)
end
while true do
old_signal = redstone.getAnalogInput(config.side)
os.pullEvent("redstone")
local new_signal = redstone.getAnalogInput(config.side)
if new_signal > 0 and old_signal == 0 then
print("Playing Audio!")
speaker.stop()
playAudio(config.url)
monitor.clear()
monitor.setCursorPos(1,1)
local maxX, maxY = monitor.getSize()
for i1=1, config.txt:len() do
local currX,currY = monitor.getCursorPos()
if (config.txt:sub(i1,i1) == "\n") then
monitor.setCursorPos(1,currY+1)
else
monitor.write(config.txt:sub(i1,i1))
end
if currX == maxX then
monitor.setCursorPos(1,currY+1)
end
os.sleep(config.text_delay)
end
playAudio(config.url2)
os.sleep(6)
for i1=1, maxX do
for i2=1, maxY do
monitor.setCursorPos(i1,i2)
monitor.write(" ")
end
os.sleep(0.05)
end
end
end