summaryrefslogtreecommitdiffstats
path: root/screens
diff options
context:
space:
mode:
Diffstat (limited to 'screens')
-rw-r--r--screens/screen1.lua20
-rw-r--r--screens/time.lua21
-rw-r--r--screens/weather.lua55
-rw-r--r--screens/weather_thread.lua18
4 files changed, 106 insertions, 8 deletions
diff --git a/screens/screen1.lua b/screens/screen1.lua
index 71f8fd4..8a62628 100644
--- a/screens/screen1.lua
+++ b/screens/screen1.lua
@@ -1,15 +1,19 @@
local node = {}
-function node.render()
-love.graphics.setColor( 0, 80, 0 )
-love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
-love.graphics.setColor(255, 255, 255, 255)
-love.graphics.setNewFont(60)
+function node.load()
+end
-love.graphics.printf("Welcome to Warsaw Hackerspace\nextreme digital signage technology!", 0, love.graphics.getHeight()/2 - 30, love.graphics.getWidth(), 'center')
+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, 0, 0)
-love.graphics.circle("fill", 20, 300, 50)
+ for x = 0, love.graphics.getWidth() / 50, 1 do
+ for y = 0, love.graphics.getHeight() / 50, 1 do
+ local r = math.sin(x + love.timer.getTime() * 2) + math.cos(y + love.timer.getTime() * math.sin(x));
+ love.graphics.setColor(255, 255, 255, (r + 2) * 255)
+ love.graphics.circle("line", x * 50, y * 50, r * 10)
+ end
+ end
end
function node.update(dt)
diff --git a/screens/time.lua b/screens/time.lua
new file mode 100644
index 0000000..bfc7a2d
--- /dev/null
+++ b/screens/time.lua
@@ -0,0 +1,21 @@
+local node = {}
+local socket = require("socket")
+
+local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 400)
+
+function node.load()
+end
+
+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 )
+ love.graphics.setFont(textFont);
+ love.graphics.printf(os.date('%H:%M'), 0, 120, love.graphics.getWidth(), 'center');
+end
+
+function node.update(dt)
+end
+
+return node
diff --git a/screens/weather.lua b/screens/weather.lua
new file mode 100644
index 0000000..df7a400
--- /dev/null
+++ b/screens/weather.lua
@@ -0,0 +1,55 @@
+local node = {}
+
+local inspect = require('vendor.inspect')
+
+local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.ttf', 400)
+local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 300)
+local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 20)
+
+local weatherGlyphs = {
+ snow = "",
+ mist = "",
+}
+
+local updateInterval = 60
+local lastUpdate = 0
+local state = {
+ weather = "snow",
+ temperature = 0,
+}
+
+function node.load()
+end
+
+function node.unload()
+end
+
+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 )
+
+ love.graphics.setFont(textFont);
+ love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center');
+
+ love.graphics.setFont(weatherFont);
+ love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0);
+
+ love.graphics.setFont(smallFont)
+ love.graphics.printf("piździ x---DD", 0, love.graphics.getHeight() - 40, love.graphics.getWidth(), 'center')
+end
+
+function node.update(dt)
+ if lastUpdate < love.timer.getTime() - updateInterval then
+ lastUpdate = love.timer.getTime()
+ print("update")
+ print(inspect(state))
+ local updateThread = love.thread.newThread('screens/weather_thread.lua')
+ updateThread:start()
+ end
+
+ state = love.thread.getChannel('weather'):pop() or state
+end
+
+return node
diff --git a/screens/weather_thread.lua b/screens/weather_thread.lua
new file mode 100644
index 0000000..7638c9a
--- /dev/null
+++ b/screens/weather_thread.lua
@@ -0,0 +1,18 @@
+local socket = require("socket")
+local http = require("socket.http")
+local json = require("vendor.json")
+local inspect = require('vendor.inspect')
+-- local weatherURL = 'http://api.wunderground.com/api/0def10027afaebb7/conditions/q/PL/Warszawa.json'
+local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=b1b15e88fa797225412429c1c50c122a1'
+
+local r, c, h = http.request(weatherURL)
+if c == 200 then
+ local data = json.decode(r)
+ print(inspect(data), data.main.temp)
+ love.thread.getChannel('weather'):push({
+ weather = data.weather[1].main:lower(),
+ temperature = data.main.temp,
+ })
+else
+ print("failed")
+end