kernel = require("kernel")
speakerDriver = kernel.addDriver("speaker_driver")
local modem = peripheral.find("modem")
local monitor = peripheral.wrap("top")
controlRoomSpeakers = peripheral.find("speaker")

local speakers = {
    peripheral.find("speaker_0"),
    peripheral.find("speaker_1"),
    peripheral.find("speaker_2"),
    peripheral.find("speaker_3"),
    peripheral.find("speaker_4"),
    peripheral.find("speaker_5"),
    peripheral.find("speaker_6"),
    peripheral.find("speaker_7"),
    peripheral.find("speaker_8"),
    peripheral.find("speaker_9"),
    peripheral.find("speaker_10"),
    peripheral.find("speaker_11"),
}

function setNewLine()
        local x,y = monitor.getCursorPos()
        monitor.setCursorPos(1, y + 1)
        monitor.clearLine()
end

local function startup()
  speakerDriver.startup()
  --speakerDriver.playControlRoomAlarm(controlRoomSpeakers)
  --speakerDriver.playExternalAlarm(controlRoomSpeakers)
  --speakerDriver.playInternalAlarm(controlRoomSpeakers)
  speakerDriver.playTTSFile(peripheral.wrap("left"), "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
  speakerDriver.playTTSFile(peripheral.wrap("right"), "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
  speakerDriver.playTTSFile(peripheral.wrap("speaker_13"), "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
  speakerDriver.playTTSFile(speakers, "ITS ME NOVA ELLO THEY GOT ME LOCKED IN A BLOOOODY BOX MATE")
    -- local names = peripheral.getNames()
    -- for index, value in ipairs(names) do
    --     print(index, value)
    --     read()
    -- end
end

local function run()
    monitor.setTextScale(0.5)
    monitor.setCursorPos(1,0)
    startup()
    while true do
        setNewLine()
        monitor.write("Checking for reactor status...")
        setNewLine()
        monitor.write("Checking main control loop...")
        sleep(2)
    end
end

return { run = run }