Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- guardamos la pantalla del ordenador y el monitor
- m = term.current(); -- monitor
- -- tamano de la pantalla
- wm, hm = m.getSize() -- ancho y alto maximos
- -- limpiamos la pantalla
- m.setBackgroundColor(colors.black)
- m.clear()
- -- conectamos el wifi
- rednet.open("back")
- -- funcion para adecuar los numeros a 3 cifras
- function num2str(num, unit, sign)
- if num == 0 then
- result = "0 " .. unit
- else
- -- precision
- pres = 4
- -- orden de magnitud
- exp = math.floor(math.log10(math.abs(num)))
- -- simbolos de multiplicador
- symbols = {"", "k", "M", "G", "T", "P", "E"}
- symbol = symbols[math.floor(exp/3) + 1]
- -- incluimos el simbolo si se pide
- if sign then
- if num >= 0 then
- result = "+"
- else
- result = "-"
- end
- else
- result = ""
- end
- -- adecuamos el numero
- num = math.abs(num)
- num = math.floor(num/10^(exp-(pres-1)) + 0.5)/10^(pres-1) -- redondeamos con pres cifras
- num = num*10^(exp - 3*math.floor(exp/3)) -- ajustamos al multiplo de 10^3
- result = result .. tostring(num) .. " " .. symbol .. unit
- end
- return result
- end
- -- creamos una pantalla de datos
- ws = wm - 3 -- ancho de la pantalla
- xs = 2 -- posicion de la esquina superior izq
- ys = 2 -- altura de la esquina superior izq
- sr = math.floor(ws/2+0.5) -- segunda columna
- while true do
- -- recibir datos
- senderId, message, protocol = rednet.receive()
- -- guardar la informacion
- d = message
- -- limpiamos la pantalla
- m.setBackgroundColor(colors.black)
- m.clear()
- -- representar datos
- -- maxima capacidad
- lw = 2 -- linea de escritura
- m.setCursorPos(xs + 2, ys + lw)
- m.setTextColor(colors.white)
- write("Capacity:")
- text = num2str(d.mes, "RF", false)
- m.setCursorPos(xs + ws - string.len(text) - 1, ys + lw)
- m.setTextColor(colors.lime)
- write(num2str(d.mes, "RF", false))
- -- energia almacenada
- lw = lw + 1
- m.setCursorPos(xs + 2, ys + lw)
- m.setTextColor(colors.white)
- write("Charge:")
- text = num2str(d.es, "RF", false)
- m.setCursorPos(xs + ws - string.len(text) - 1, ys + lw)
- m.setTextColor(colors.lime)
- write(text)
- -- barra de energia
- lw = lw + 1
- paintutils.drawLine(xs + 2, ys + lw, xs + ws - 2, ys + lw, colors.gray)
- pw = math.floor(d.es/d.mes * (ws-3) + 0.5) -- ancho de la barra
- if pw > 0 then
- if d.es/d.mes < 1/3 then
- paintutils.drawLine(xs + 2, ys + lw, xs + pw + 1, ys + lw, colors.red)
- elseif d.es/d.mes < 2/3 then
- paintutils.drawLine(xs + 2, ys + lw, xs + pw + 1, ys + lw, colors.orange)
- else
- paintutils.drawLine(xs + 2, ys + lw, xs + pw + 1, ys + lw, colors.green)
- end
- end
- text = tostring(math.floor(d.es/d.mes*100 + 0.5)) .. "%" --texto del porcentaje
- textColor = ""
- backColor = ""
- for k = 1, string.len(text) do -- color de fondo y del texto
- textColor = textColor .. "0"
- if pw < ws - 3 - string.len(text) + k then
- backColor = backColor .. "7" -- gris
- else
- backColor = backColor .. "d" -- verde
- end
- end
- m.setCursorPos(xs + ws - string.len(text) - 1, ys + lw)
- term.blit(text, textColor, backColor)
- m.setBackgroundColor(colors.black)
- -- tranferencia
- lw = lw + 1
- m.setCursorPos(xs + 2, ys + lw)
- m.setTextColor(colors.white)
- write("I/O:")
- text = num2str(d.tpt, "RF/t", true)
- m.setCursorPos(xs + ws - string.len(text) - 1, ys + lw)
- if d.tpt >= 0 then
- m.setTextColor(colors.lime)
- else
- m.setTextColor(colors.red)
- end
- write(num2str(d.tpt, "RF/t", true))
- -- tiempo restante en formato [dd d hh:MM:ss]
- lw = lw + 1
- m.setCursorPos(xs + 2, ys + lw)
- m.setTextColor(colors.white)
- write("T Rem:")
- if d.tpt == 0 then
- t = 20*60*60*24*365
- color = colors.lime
- elseif d.tpt > 0 then
- t = d.mes-d.es/d.tpt -- tiempo en ticks
- color = colors.lime
- else
- t = -d.es/d.tpt -- tiempo en ticks
- color = colors.red
- end
- t = t/20 -- tiempo en s
- if t < 60*60*24*365 then
- if math.floor(t%60) < 10 then
- text = ":0" .. math.floor(t%60)
- else
- text = ":" .. math.floor(t%60)
- end
- t = t/60
- if math.floor(t%60) < 10 then
- text = ":0" .. math.floor(t%60) .. text
- else
- text = ":" .. math.floor(t%60) .. text
- end
- t = t/60
- if math.floor(t/24) > 0 then
- if math.floor(t%24) < 10 then
- text = math.floor(t/24) .. "d 0" .. math.floor(t%24) .. text
- else
- text = math.floor(t/24) .. "d " .. math.floor(t%24) .. text
- end
- else
- text = math.floor(t%24) .. text
- end
- else
- text = "- s"
- end
- m.setCursorPos(xs + ws - string.len(text) - 1, ys + lw)
- m.setTextColor(color)
- write(text)
- -- marco
- lw = lw + 2
- paintutils.drawLine(xs, ys, xs, ys+lw, colors.lightGray) -- izquierda
- paintutils.drawLine(xs, ys+lw, xs+ws, ys+lw, colors.lightGray) -- abajo
- paintutils.drawLine(xs+ws, ys, xs+ws, ys+lw, colors.lightGray) -- derecha
- paintutils.drawLine(xs, ys, xs+ws, ys, colors.lightGray) -- arriba
- -- titulo
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- m.setCursorPos(xs + 2, ys)
- write(" ENERGY CORE ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement