infobeamer-testcard/node.lua

86 lines
1.9 KiB
Lua

node.alias "testcard"
util.init_hosted()
local json = require "json"
local serial = sys.get_env "SERIAL"
local location = ""
local description = "<please wait>"
util.data_mapper{
["device_info"] = function(info)
info = json.decode(info)
location = info.location
description = info.description
end
}
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
card = resource.load_image("testcard.png")
font = resource.load_font("vera.ttf")
local v = {}
util.data_mapper{
["update/(.*)"] = function(key, val)
v[key] = val
end
}
function node.render()
gl.clear(0,0,0,1)
card:draw(0, 0, 1920, 1080)
-- upper: 623
-- lower: 707
upper_text = "CCC: " .. description
if location == nil or location == '' then
lower_text = "Serial " .. serial
else
lower_text = location .. " - Serial " .. serial
end
upper_width = font:width(upper_text, 40)
font:write(960-(upper_width/2), 631, upper_text, 40, 1,1,1,1)
lower_width = font:width(lower_text, 20)
font:write(960-(lower_width/2), 679, lower_text, 20, 1,1,1,1)
-- available space y: 450 to 700
local size = 40
local x_left = 70
local x_right = 1000
local y_start = 450
-- left side: network config, online status
if v.network then
font:write(x_left, y_start, "Mode: " .. v.network, size, 1,1,1,1)
end
if v.online then
local col = {1,0,0,1}
if v.online == "online" then
col = {0,1,0,1}
end
font:write(x_left, y_start+50, v.online, size, col)
end
-- right side: IP address
if v.ethip then
font:write(x_right, y_start, "Eth IPv4: " .. v.ethip, size, 1,1,1,1)
end
if v.wlanip then
font:write(x_right, y_start+50, "WiFi IPv4: " .. v.wlanip, size, 1,1,1,1)
end
if v.gw then
font:write(x_right, y_start+100, "Gateway: " .. v.gw, size, 1,1,1,1)
end
end