Advertisement
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("6502","screen")
- local gpu = component.gpu
- local valve = component.ffs_valve
- local modem = component.modem
- --Ouverture des ports
- modem.open(1001)
- --Résolution
- gpu.bind(screen)
- gpu.setResolution(63,35)
- --Définitions des variables
- local i = 0
- --Fonctions
- local 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 afftemp(x,y,length)
- local amount = valve.getFluidAmount() / 1000
- local capacity = valve.getFluidCapacity() / 1000
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local color = 0x00FFFF
- local textfrac = string.format("%.02f / %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
- local function send()
- local tableau_valeur ={}
- local amount = valve.getFluidAmount() / 1000
- local capacity = valve.getFluidCapacity() / 1000
- local value = amount / capacity
- tableau_valeur[1] = amount
- tableau_valeur[2] = capacity
- tableau_valeur[3] = value
- local table_s = serialization.serialize(tableau_valeur)
- modem.broadcast(1001, table_s)
- i = i + 1
- if i > 9 then
- i = 0
- end
- gpu.set(2,15,string.format("%s", i))
- gpu.set(2,16,table_s)
- 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()
- afftemp(2,7,61)
- send()
- 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)
- local timer = event.timer(1,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- gpu.fill(1,1,63,35," ")
- gpu.setResolution(160,50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement