Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --1.1.3
- local filtre = "Darking"
- local xmax
- local xmin
- local pas
- local maxline
- local pageMax
- local page
- local continuer = true
- local monSize = nil
- local dialSize = nil
- local destination= {}
- local listPerso = true
- local current_version = "1.1.3"
- local code_pastebin = "bM8xpdHW"
- function version(version,code)
- local function versionSuperieur(ver1,ver2,loc)
- if loc <= string.len(ver2) then
- nb1 = tonumber(string.sub(ver1,loc,loc))
- nb2 = tonumber(string.sub(ver2,loc,loc))
- if nb1 == nil then nb1=0 end
- if nb1 > nb2 then
- return false
- elseif nb1 < nb2 then
- return true
- else
- return versionSuperieur(ver1,ver2,loc+2)
- end
- else
- return false
- end
- end
- local data = http.get("http://pastebin.com/raw.php?i="..code)
- if data then
- print("Download successful")
- local line = data.readLine()
- line = string.sub(line,3)
- if versionSuperieur(version,line,1) then
- print("Mise a jour en cour, ...")
- fs.move("startup","delete")
- local file = fs.open("startup","w")
- file.write(data.readAll())
- file.close()
- print("Mise a jour reussite, reboot !")
- sleep(1)
- os.reboot()
- else
- print("Pas de nouvelle Version disponible !")
- end
- else
- print("Erreur connection Pastebin, echec recherche update")
- end
- if fs.exists("delete") then
- print("Mise a jour completement etablie")
- fs.delete("delete")
- end
- print("Version: "..current_version)
- end
- version(current_version,code_pastebin)
- function loadFiltre()
- if not fs.exists("config") then
- config = fs.open("config","w")
- print("Vous n'avez pas configurer de filtre :")
- filtre = read()
- config.write(filtre)
- config.close()
- end
- config = fs.open("config","r")
- filtre = config.readLine()
- config.close()
- end
- loadFiltre()
- function checkPeripheral()
- print("-------Check Peripheral-------")
- for k,v in pairs(peripheral.getNames()) do
- if string.find(v,"monitor") then
- monSize = v
- elseif string.find(v,"dialing_device") then
- dialSize = v
- end
- for n,m in pairs(rs.getSides()) do
- if m == v then
- if peripheral.getType(v) == "monitor" then
- monSize = v
- elseif peripheral.getType(v) == "dialing_device" then
- dialSize = v
- end
- end
- end
- end
- if monSize ~= nil then
- print("Found monitor as "..monSize)
- else
- print("ERROR:Monitor don't found")
- return(false)
- end
- if dialSize ~= nil then
- print("Found Dialing Device as "..dialSize)
- else
- print("ERROR:Dialing Device don't found")
- return(false)
- end
- print("-------End Check Peripheral-------")
- return(true)
- end
- function setDestination()
- print("-------Set Destination-------")
- destination = {}
- for i=0, dial.getReceiverCount()-1 do
- name = dial.getReceiverName(i)
- if name ~= dial.getTransmitterName(0) then
- list = {["name"]=name;["number"]=i}
- print("Add "..name.." at number "..i)
- if string.find(name, filtre) then
- list["perso"] = true
- else
- list["perso"] = false
- end
- table.insert(destination, list)
- end
- end
- print("-------End Set Destination-------")
- end
- function dialOnce(nb)
- dial.dialOnce(0,nb)
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- function button(text, line, color, xmin, xmax)
- mon.setBackgroundColor(color)
- local xspot = math.floor((xmax - xmin - string.len(text)) /2) +1
- mon.setCursorPos(xmin, line)
- for k = 0, xmax - xmin - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function listing()
- local listTemp = {}
- if listPerso then
- for i,item in pairs(destination) do
- if item["perso"] then
- table.insert(listTemp, item)
- end
- end
- else
- listTemp = destination
- end
- local pageMax = math.ceil(#listTemp/maxline)
- local list = {}
- for i=((page-1)*maxline)+1, (page*maxline) do
- table.insert(list,listTemp[i])
- end
- return list, pageMax
- end
- function screen(pageMax, list)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- heading("Choose you destination")
- button("Perso", 3, persoColor, xmin-1, xmin+6)
- button("Tout", 3, totalColor, xmax-6, xmax+1)
- if page > 1 then
- button("Prev.", heigh, colors.red, xmin-1, xmin+6)
- elseif page < pageMax then
- button("Next", heigh, colors.red, xmax-6, xmax+1)
- end
- for i, item in pairs(list) do
- button(item["name"], 5+(2*(i-1)), colors.red, xmin, xmax)
- end
- end
- function checkClic(x, y, list,pageMax)
- for i, item in pairs(list) do
- if x>=xmin and x <= xmax then
- if y == (5+(2*(i-1))) then
- print("Dial with "..item["name"])
- dialOnce(item["number"])
- button(item["name"], (5+(2*(i-1))), colors.lime, xmin, xmax)
- sleep(0.5)
- end
- end
- end
- if y == 3 then
- if x>=xmin-1 and x <= xmin+6 then
- print("Button : Perso clic")
- persoColor = colors.lime
- totalColor = colors.red
- listPerso = true
- page = 1
- elseif x>=xmax-6 and x <= xmax+1 then
- print("Button : Tout clic")
- persoColor = colors.red
- totalColor = colors.lime
- listPerso = false
- page = 1
- end
- elseif y == heigh then
- if x>=xmin-1 and x <= xmin+6 and page > 1 then
- print("Button : previous clic")
- page = page - 1
- elseif x>=xmax-6 and x <= xmax+1 and page < pageMax then
- print("Button : next clic")
- page = page + 1
- end
- end
- end
- continuer = checkPeripheral()
- mon = peripheral.wrap(monSize)
- dial = peripheral.wrap(dialSize)
- width, heigh = mon.getSize()
- xmax = width-3
- xmin = 3
- pas = 2
- maxline = math.floor(((heigh-2)-4)/pas)
- setDestination()
- local timerID = os.startTimer(30)
- local timer2ID = os.startTimer(60)
- persoColor = colors.lime
- totalColor = colors.red
- page = 1
- while continuer do
- listActive, pageMax = listing()
- screen(pageMax, listActive)
- event, arg2, x, y = os.pullEvent()
- if event == "monitor_touch" then
- checkClic(x, y, listActive,pageMax)
- elseif event == "timer" then
- setDestination()
- os.cancelTimer(timer2ID)
- timerID = os.startTimer(30)
- timer2ID = os.startTimer(60)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement