Add newdash node

master
informatic 2017-01-23 22:20:21 +01:00
parent bef00a347e
commit 97f30431b1
3 changed files with 143 additions and 5 deletions

View File

@ -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',

103
nodes/newdash.lua Normal file
View File

@ -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

39
nodes/newdash_thread.lua Normal file
View File

@ -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