123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- gl.setup(1920, 1080)
- util.resource_loader{
- "font.ttf";
- "background.png";
- "logo.png";
- "spaceapi_logo.png";
- }
- local json = require('json')
- local white = resource.create_colored_texture(1,1,1,1)
- --
- -- Global variables and default values
- --
- local bus = "in N/A minutes"
- local power = 1337
- local network_in = '1337 MB'
- local network_out = '1337 MB'
- local spaceapi = {
- ["Status"] = "Unknown",
- ["Device present"] = "N/A",
- --["Member count"] = "N/A",
- ["URL"] = "Unknown",
- }
- local events = {
- {
- ["s_day"] = '23',
- ["s_month"] = 'Feb',
- ["s_time"] = '19:99',
- ["name"] = 'No event',
- }
- }
- --
- -- Communication
- --
- util.file_watch("events.json", function(data)
- events = {}
- evt = json.decode(data)
- week = evt.week_events
- for i, f in ipairs(week) do
- table.insert(events, f)
- end
- future = evt.future_events
- for i, f in ipairs(future) do
- table.insert(events, f)
- end
- end)
- util.file_watch("spaceapi.json", function(data)
- api = json.decode(data)
- spaceapi = {
- ["Status"] = api['state']['message'],
- ["Device present"] = api['sensors']['people_now_present'][1]['value'],
- ["Member count"] = api['sensors']['total_member_count'][3]['value'],
- }
- end)
- util.data_mapper{
- ["power/set"] = function(content)
- power = content
- end;
- ["network/in/set"] = function(content)
- network_in = content
- end;
- ["network/out/set"] = function(content)
- network_out = content
- end;
- }
- util.file_watch("bus.txt", function(content)
- bus = content
- end)
- util.file_watch("cat.jpg", function(content)
- cat = resource.load_image("cat.jpg")
- end)
- --
- -- Fragments
- --
- function fixme()
- function draw()
- background:draw(0,0,WIDTH,HEIGHT)
- --logo:draw(WIDTH-250,5,WIDTH-35,185)
- font:write(150, 50, "FIXME", 200, 1,1,1,1)
- end
- return {
- draw = draw;
- }
- end
- function scroller()
- function texts()
- return {
- "https://git.fixme.ch/FIXME/screen",
- "Next bus (Renens-Village) " .. bus,
- }
- end
- local text = util.running_text{
- font = font;
- size = 80;
- speed = 300;
- color = {1,1,1,1};
- generator = util.generator(texts)
- }
- function draw()
- text:draw(HEIGHT-95)
- end
- return {
- draw = draw;
- }
- end
- --
- -- Main screen cycler
- --
- function cycler(panels, interval)
- local panel
- local next_cycle = 0
- function next_panel()
- panel = panels.next()
- next_cycle = sys.now() + interval
- end;
- function draw()
- if sys.now() > next_cycle then
- next_panel()
- end;
- panel:draw()
- local remaining = next_cycle - sys.now()
- --if remaining < 0.2 or remaining > 4.8 then
- -- print(remaining)
- --end
- local size = 5
- local xpos = 270
- white:draw(remaining / interval * WIDTH, xpos, 0, xpos + size)
- end;
- return {
- draw = draw
- }
- end;
- function panel_events()
- function draw()
- pos = 360
- for i, e in ipairs(events) do
- date = string.format("%s %s %s", e.s_day, e.s_month, e.s_time)
- font:write(150, pos, date, 60, 0.5,0.5,0.5,1)
- font:write(150, pos+60, e.name, 80, 1,1,1,1)
- pos = pos + 135
- if i > 3 then
- break
- end
- end
- end;
- return {
- draw = draw;
- }
- end;
- function panel_spaceapi()
- -- TODO: Maybe instead pick a random space from the api ?
- function draw()
- -- Logo
- util.draw_correct(spaceapi_logo, 50, 400, WIDTH-1200, HEIGHT-250)
- -- Fields
- local xpos = 700
- local ypos = 450
- for k, v in pairs(spaceapi) do
- local name = string.format("%-16s", k)
- font:write(xpos, ypos, name, 60, 1,1,1,1)
- font:write(xpos+500, ypos+10, v, 40, 0.5, 0.5, 0.5,1)
- ypos = ypos + 90
- end
- end;
- return {
- draw = draw;
- }
- end;
- function panel_clock()
- function draw()
- --TODO: Add date
- util.draw_correct(resource.render_child("analogclock"), 550, 400, WIDTH-550, HEIGHT-200)
- end;
- return {
- draw = draw;
- }
- end;
- function panel_cat()
- function draw()
- util.draw_correct(cat, WIDTH/2-1000, 300, WIDTH, HEIGHT-150)
- end;
- return {
- draw = draw;
- }
- end;
- --
- -- MAIN
- --
- local fix = fixme()
- local scroll = scroller()
- local cycling = cycler(util.generator(function()
- return {
- panel_spaceapi(),
- panel_events(),
- panel_cat(),
- }
- end), 8)
- function node.render()
- fix:draw()
- cycling:draw()
- scroll:draw()
- util.draw_correct(resource.render_child("analogclock"), 260, 260, WIDTH/2+750, 10)
- local pos = 30
- font:write(WIDTH-650, pos, "DL: " .. network_in .. "/s", 80, 1,1,1,1)
- font:write(WIDTH-650, pos+70, "UP: " .. network_out .. "/s", 80, 1,1,1,1)
- font:write(WIDTH-650, pos+140, "Power: " .. power .. " W", 80, 1,1,1,1)
- end
|