Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Liste des require
- local computer = require("computer")
- local component = require("component")
- local term = require("term")
- local math = require("math")
- local event = require("event")
- local string = require("string")
- local unicode = require("unicode")
- local colors = require("colors")
- local sides = require("sides")
- local serialization = require("serialization")
- --Récupération du matériel
- local screen = component.get("d191","screen")
- local gpu = component.gpu
- local modem = component.modem
- --Ouverture des ports
- modem.open(1001)
- --Résolution
- gpu.bind(screen)
- gpu.setResolution(63,35)
- --Déclaration de variables
- local value_receive
- --Fonctions
- function loadbar(x,y,width,cur,text,bg)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(0xFFFFFF - bg)
- gpu.set(x,y,unicode.sub(raw,1,cur))
- gpu.setBackground(oldbg)
- gpu.setForeground(oldfg)
- gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
- end
- local function afflevel(x,y,length,tableau)
- local amount = tableau[1]
- local capacity = tableau[2]
- local pct = tableau[3]
- local color = 0x00FFFF
- local cur = math.floor(pct * length)
- local textfrac = string.format("%s / %s", amount, capacity)
- local textpct = string.format("%.02f%%", pct*100)
- local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- local dir = ""
- loadbar(x,y,length,cur,dir,color)
- loadbar(x,y+1,length,cur,dir,color)
- loadbar(x,y+2,length,cur,text,color)
- end
- --Trame de fond
- gpu.set(1,1,"╔═════════════════════════════════════════════════════════════╗")
- gpu.set(1,2,"║ ║")
- gpu.set(1,3,"║ ║")
- gpu.set(1,4,"║ ║")
- gpu.set(1,5,"║ ║")
- gpu.set(1,6,"║ ║")
- gpu.set(1,7,"║ ║")
- gpu.set(1,8,"║ ║")
- gpu.set(1,9,"║ ║")
- gpu.set(1,10,"║ ║")
- gpu.set(1,11,"║ ║")
- gpu.set(1,12,"║ ║")
- gpu.set(1,13,"║ ║")
- gpu.set(1,14,"║ ║")
- gpu.set(1,15,"║ ║")
- gpu.set(1,16,"║ ║")
- gpu.set(1,17,"║ ║")
- gpu.set(1,18,"║ ║")
- gpu.set(1,19,"║ ║")
- gpu.set(1,20,"║ ║")
- gpu.set(1,21,"║ ║")
- gpu.set(1,22,"║ ║")
- gpu.set(1,23,"║ ║")
- gpu.set(1,24,"║ ║")
- gpu.set(1,25,"║ ║")
- gpu.set(1,26,"║ ║")
- gpu.set(1,27,"║ ║")
- gpu.set(1,28,"║ ║")
- gpu.set(1,29,"║ ║")
- gpu.set(1,30,"║ ║")
- gpu.set(1,31,"║ ║")
- gpu.set(1,32,"║ ║")
- gpu.set(1,33,"║ ║")
- gpu.set(1,34,"║ ║")
- gpu.set(1,35,"╚═════════════════════════════════════════════════════════════╝")
- local function drawbars()
- afflevel(2,7,61,value_receive)
- end
- local function onModem(_,_,from,port,_,message)
- value_receive = serialization.unserialize(message)
- gpu.set(2,15,string.format("%.02f°C", value_receive))
- end
- local function onTouch(_,address,x,y,_,pseudo)
- gpu.set(2,2,"X : "..string.format("% 3s",x))
- gpu.set(2,3,"Y : "..string.format("% 3s",y))
- gpu.set(2,4,"Pseudo : "..pseudo)
- if x~=1 and y~=1 then
- elseif x==1 and y==1 then
- computer.pushSignal("quit")
- gpu.fill(1,1,63,35," ")
- term.setCursor(1,1)
- return false
- end
- end
- local function onTimer(_,timer)
- drawbars()
- return true
- end
- event.listen("touch",onTouch)
- event.listen("modem_message",onModem)
- local timer = event.timer(1,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- event.ignore("modem_message",onModem)
- gpu.fill(1,1,63,35," ")
- gpu.setResolution(160,50)
Add Comment
Please, Sign In to add comment