Added notificaiton sound
This commit is contained in:
@@ -4,11 +4,14 @@ local monitor = kernel.addDriver("monitor-driver")
|
|||||||
local data = kernel.addDriver("disk-driver")
|
local data = kernel.addDriver("disk-driver")
|
||||||
local chat = kernel.addProgram("chat")
|
local chat = kernel.addProgram("chat")
|
||||||
local gps = kernel.addProgram("gps")
|
local gps = kernel.addProgram("gps")
|
||||||
|
local speaker = kernel.addProgram("speaker-driver")
|
||||||
|
|
||||||
|
|
||||||
local function run()
|
local function run()
|
||||||
monitor.initialize()
|
monitor.initialize()
|
||||||
data.initialize()
|
data.initialize()
|
||||||
|
speaker.initialize()
|
||||||
|
|
||||||
monitor.writeLine("Starting system...")
|
monitor.writeLine("Starting system...")
|
||||||
monitor.writeLine("System started successfully!")
|
monitor.writeLine("System started successfully!")
|
||||||
computerName = data.getRead("computer-name")
|
computerName = data.getRead("computer-name")
|
||||||
|
|||||||
13
kernel.lua
13
kernel.lua
@@ -30,6 +30,17 @@ local function addProgram(fileName)
|
|||||||
return require(fileName)
|
return require(fileName)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function addSound(fileName)
|
||||||
|
local extension = ".dfpwm"
|
||||||
|
local fullFile = fileName .. extension
|
||||||
|
shell.execute("rm", fullFile)
|
||||||
|
local baseRoute = "https://git.astrocore.space/root/nova-corp/raw/branch/main/"
|
||||||
|
shell.execute("wget", baseRoute .. "sounds" .. "/" .. fullFile)
|
||||||
|
sleep(2)
|
||||||
|
return require(fileName)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
addDriver("task-manager")
|
addDriver("task-manager")
|
||||||
|
|
||||||
return { addDriver = addDriver, addFolderDriver = addFolderDriver, addProgram = addProgram }
|
return { addDriver = addDriver, addFolderDriver = addFolderDriver, addProgram = addProgram, addSound = addSound }
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
local modem = peripheral.find("modem")
|
local modem = peripheral.find("modem")
|
||||||
local PORT = 1
|
local PORT = 1
|
||||||
|
local speaker = require("speaker")
|
||||||
|
|
||||||
local function start()
|
local function start()
|
||||||
if modem then
|
if modem then
|
||||||
@@ -30,6 +31,7 @@ local function receiveLoop()
|
|||||||
term.setCursorPos(1, y)
|
term.setCursorPos(1, y)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
print("Received: " .. tostring(message))
|
print("Received: " .. tostring(message))
|
||||||
|
speaker.play("notification")
|
||||||
write("> ")
|
write("> ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
sounds/notification.dfpwm
Normal file
BIN
sounds/notification.dfpwm
Normal file
Binary file not shown.
56
speaker-driver.lua
Normal file
56
speaker-driver.lua
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
local speaker = peripheral.find("speaker")
|
||||||
|
local dfpwm = require("cc.audio.dfpwm")
|
||||||
|
local kernel = require("kernel")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local sounds = {
|
||||||
|
{name = "notification", file = "notification.dfpwm"}
|
||||||
|
}
|
||||||
|
|
||||||
|
local function initialize()
|
||||||
|
|
||||||
|
kernel.addSound("notification")
|
||||||
|
|
||||||
|
speaker = peripheral.find("speaker")
|
||||||
|
if not speaker then
|
||||||
|
print("Warning: No speaker attached.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function play(name)
|
||||||
|
if not speaker then return false end
|
||||||
|
|
||||||
|
local filePath
|
||||||
|
for _, sound in ipairs(sounds) do
|
||||||
|
if sound.name == name then
|
||||||
|
filePath = sound.file
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not filePath then
|
||||||
|
print("Sound '" .. name .. "' not defined.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if not fs.exists(filePath) then
|
||||||
|
print("File '" .. filePath .. "' not found.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a new decoder for this playback to reset state
|
||||||
|
local decoder = dfpwm.make_decoder()
|
||||||
|
|
||||||
|
for chunk in io.lines(filePath, 16 * 1024) do
|
||||||
|
local buffer = decoder(chunk)
|
||||||
|
while not speaker.playAudio(buffer) do
|
||||||
|
os.pullEvent("speaker_audio_empty")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return { initialize = initialize, play = play }
|
||||||
Reference in New Issue
Block a user