diff options
author | Piotr Dobrowolski <admin@tastycode.pl> | 2017-01-23 22:20:21 +0100 |
---|---|---|
committer | Piotr Dobrowolski <admin@tastycode.pl> | 2017-01-23 22:20:21 +0100 |
commit | 97f30431b170b916552cd5c224134ef4c0523748 (patch) | |
tree | ff7b6a22c0f11907a9b0d2f1acd63139a077d267 | |
parent | bef00a347e1d4e4eabba5483403c1062fa478edd (diff) | |
download | love2d-signage-97f30431b170b916552cd5c224134ef4c0523748.tar.gz love2d-signage-97f30431b170b916552cd5c224134ef4c0523748.tar.bz2 love2d-signage-97f30431b170b916552cd5c224134ef4c0523748.tar.xz love2d-signage-97f30431b170b916552cd5c224134ef4c0523748.zip |
Add newdash node
-rw-r--r-- | config.lua | 6 | ||||
-rw-r--r-- | nodes/newdash.lua | 103 | ||||
-rw-r--r-- | nodes/newdash_thread.lua | 39 |
3 files changed, 143 insertions, 5 deletions
@@ -3,12 +3,8 @@ return { transitionTime = 0.5, showProgress = true, nodes = { - {'nodes.at'}, - {'nodes.cube'}, - {'nodes.time'}, - {'nodes.weather'}, + {'nodes.newdash', displayTime=10}, {'nodes.misery', displayTime = 7}, - {'nodes.screen1'}, {'nodes.slideshow', fileName='images/pig.png', displayTime=5}, }, environment = os.getenv('ENV') or 'prod', diff --git a/nodes/newdash.lua b/nodes/newdash.lua new file mode 100644 index 0000000..4a68a25 --- /dev/null +++ b/nodes/newdash.lua @@ -0,0 +1,103 @@ +local node = ThreadNode:extend('nodes.newdash', { + threadFile = 'nodes/newdash_thread.lua', + threadChannel = 'newdash', + + updateInterval = 60, +}) + +local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.ttf', 165) +local tempFont = love.graphics.newFont('fonts/Lato-Light.ttf', 120) +local timeFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 330) +local dateFont = love.graphics.newFont('fonts/Lato-Light.ttf', 90) + +local headerFont = love.graphics.newFont('fonts/Lato-Regular.ttf', 40) +local valueFont = love.graphics.newFont('fonts/Lato-Light.ttf', 45) +local atFont = love.graphics.newFont('fonts/Lato-Light.ttf', 35) + +local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 300) +local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30) + +local weatherGlyphs = { + snow = "", + mist = "", + clear = "", + -- clouds = "", + clouds = "", -- x---DDD + drizzle = "", +} + +local mockup = love.graphics.newImage("memes/new-dash-mockup.svg.png") + +function node:render() + love.graphics.setColor( 0, 0, 0 ) + love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) + + --love.graphics.setColor(255, 255, 255, 100) + --love.graphics.draw(mockup, 0, 0) + + if self.state then + love.graphics.setColor( 255, 255, 255 ) + + if weatherGlyphs[self.state.weather] then + love.graphics.setFont(weatherFont) + love.graphics.print(weatherGlyphs[self.state.weather], 100, 340) + else + love.graphics.setFont(smallFont) + love.graphics.print(self.state.weather, 100, 370) + end + + love.graphics.setFont(tempFont) + love.graphics.printf(tostring(self.state.temperature) .. "°", 350, 390, 270, 'center') + + love.graphics.setFont(headerFont) + love.graphics.printf("Ambient:", 720, 380, 160, 'right') + love.graphics.printf("Exhaust:", 720, 440, 160, 'right') + love.graphics.printf("Lights:", 720, 500, 160, 'right') + + love.graphics.setFont(valueFont) + if self.state.insideTemperature then + love.graphics.printf(tostring(self.state.insideTemperature) .. "° / " .. tostring(self.state.insideHumidity) .. "%RH", 900, 378, 400, 'left') + else + love.graphics.printf("?!", 900, 378, 400, 'left') + end + love.graphics.printf("ON or OFF?", 900, 438, 400, 'left') + love.graphics.printf("ON or OFF?", 900, 498, 400, 'left') + --love.graphics.setFont(smallFont) + --love.graphics.printf(os.date("Last update: %Y/%m/%d %H:%M", self.state.lastUpdate), 0, love.graphics.getHeight() - 60, love.graphics.getWidth(), 'center') + --if self.state.insideTemperature then + -- love.graphics.printf("Room: " .. tostring(self.state.insideTemperature) .. "° / " .. tostring(self.state.insideHumidity) .. "%RH", 0, love.graphics.getHeight() - 100, love.graphics.getWidth(), 'center') + --end + love.graphics.setFont(headerFont) + love.graphics.printf("at hackerspace:", 50, 593, 300, 'left') + love.graphics.setFont(atFont) + if self.state.at then + users = lume.map(self.state.at.users, function(v) return v.login end) + if self.state.at.unknown > 0 then + users[#users + 1] = tostring(self.state.at.unknown) .. " unknown creatures" + end + if self.state.at.kektops > 0 then + users[#users + 1] = tostring(self.state.at.kektops) .. " kektops" + end + if self.state.at.esps > 0 then + users[#users + 1] = tostring(self.state.at.esps) .. " ESPs" + end + end + + usersList = (table.concat(users, ', ') or 'nobody...') + + love.graphics.printf(usersList, 350, 598, 900, 'left') + else + love.graphics.setColor(255, 255, 255, 150) + love.graphics.setFont(valueFont) + love.graphics.printf("Loading...", 0, 530, love.graphics.getWidth(), "center") + end + + love.graphics.setColor( 255, 255, 255 ) + love.graphics.setFont(timeFont) + love.graphics.printf(os.date("%H:%M"), 50, -10, 850, 'center') + love.graphics.setFont(dateFont) + love.graphics.printf(os.date("%Y\n%m/%d"), 960, 80, 270, 'center') + +end + +return node diff --git a/nodes/newdash_thread.lua b/nodes/newdash_thread.lua new file mode 100644 index 0000000..eafda8a --- /dev/null +++ b/nodes/newdash_thread.lua @@ -0,0 +1,39 @@ +local socket = require("socket") +local http = require("socket.http") +local json = require("vendor.json") + +local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=b1b15e88fa797225412429c1c50c122a1' +local insideURL = 'http://dht01.waw.hackerspace.pl/' +local atURL = 'http://at.hackerspace.pl/api' +local insideData = {} +local atData = nil + +local r, c, h = http.request(weatherURL) +if c == 200 then + local data = json.decode(r) + + local r, c, h = http.request(insideURL) + if c == 200 then + for n in string.gmatch(string.gsub(r, ",", "."), ":%s*(%S+)[*%%]") do + insideData[#insideData+1] = n + end + end + + local r, c, h = http.request(atURL) + + if c == 200 then + atData = json.decode(r) + end + + love.thread.getChannel('newdash'):push({ + weather = data.weather[1].main:lower(), + temperature = data.main.temp, + lastUpdate = data.dt, + insideTemperature = insideData[1], + insideHumidity = insideData[2], + at = atData, + }) + print("Update finished") +else + print("Update failed") +end |