blob: 2e0f6513cc791dbe8158ae5e9a01134a352141e8 [file] [log] [blame]
Serge Bazanski18c1a262022-07-07 14:24:53 +02001local node = ThreadNode:extend('nodes.newdash', {
2 threadFile = 'nodes/newdash_thread.lua',
3 threadChannel = 'newdash',
4
5 updateInterval = 60,
6})
7
8local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.ttf', 165)
9local tempFont = love.graphics.newFont('fonts/Lato-Light.ttf', 120)
10local timeFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 330)
11local dateFont = love.graphics.newFont('fonts/Lato-Light.ttf', 90)
12local headerFont = love.graphics.newFont('fonts/Lato-Regular.ttf', 40)
13local valueFont = love.graphics.newFont('fonts/Lato-Light.ttf', 45)
14local atFont = love.graphics.newFont('fonts/Lato-Light.ttf', 35)
15
16local weatherGlyphs = {
17 snow = "",
18 mist = "",
19 clear = "",
20 -- clouds = "",
21 clouds = "", -- x---DDD
22 drizzle = "",
23}
24
25function node:spejsiotData(node_id, endpoint, parameter)
26 if self.state.spejsiot[node_id] and self.state.spejsiot[node_id]["$online"] and self.state.spejsiot[node_id][endpoint] and self.state.spejsiot[node_id][endpoint][parameter] ~= nil then
27 return self.state.spejsiot[node_id][endpoint][parameter]
28 else
29 return nil
30 end
31end
32
33function node:renderIOTState(node_id, endpoint, parameter, x, y)
34 local rawValue = self:spejsiotData(node_id, endpoint, parameter)
35 if rawValue == true then
36 love.graphics.setColor( 0, 1.0, 0 )
37 love.graphics.printf("ON", x, y, 400, 'left')
38 elseif rawValue == false then
39 love.graphics.setColor( 1.0, 0, 0 )
40 love.graphics.printf("OFF", x, y, 400, 'left')
41 elseif rawValue == nil then
42 love.graphics.setColor( 1.0, 0, 0 )
43 love.graphics.printf("OFFLINE", x, y, 400, 'left')
44 else
45 love.graphics.setColor( 1.0, 1.0, 1.0 )
46 love.graphics.printf(rawValue, x, y, 400, 'left')
47 end
48end
49
50function node:render()
51 love.graphics.setColor( 0, 0, 0 )
52 love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
53
54 if self.state then
55 love.graphics.setColor( 1.0, 1.0, 1.0 )
56
57 if weatherGlyphs[self.state.weather] then
58 love.graphics.setFont(weatherFont)
59 love.graphics.print(weatherGlyphs[self.state.weather], 100, 340)
60 else
61 love.graphics.setFont(atFont)
62 love.graphics.print(self.state.weather, 100, 370)
63 end
64
65 love.graphics.setFont(tempFont)
66 love.graphics.printf(string.format("%d°", self.state.temperature), 350, 390, 270, 'center')
67
68 love.graphics.setFont(headerFont)
69 love.graphics.printf("Ambient:", 720, 380, 160, 'right')
70 love.graphics.printf("Exhaust:", 720, 440, 160, 'right')
71 love.graphics.printf("Pope:", 720, 500, 160, 'right')
72
73 love.graphics.setFont(valueFont)
74
75 if self:spejsiotData("d106e1", "environment", "degree") then
76 love.graphics.printf(string.format(
77 "%d° / %d%%RH",
78 self:spejsiotData("d106e1", "environment", "degree"),
79 self:spejsiotData("d106e1", "environment", "humidity")
80 ), 900, 378, 400, 'left')
81 else
82 love.graphics.printf("?!", 900, 378, 400, 'left')
83 end
84
85 self:renderIOTState("c0dbe7", "relay", "on", 900, 438)
86 self:renderIOTState("0eac42", "spin and blink", "on", 900, 498)
87
88 love.graphics.setColor( 1.0, 1.0, 1.0 )
89 love.graphics.setFont(headerFont)
90 love.graphics.printf("at hackerspace:", 50, 593, 300, 'left')
91 love.graphics.setFont(atFont)
92 users = {}
93 if self.state.at then
94 users = lume.map(self.state.at.users, function(v) return v.login end)
95 if self.state.at.unknown > 0 then
96 users[#users + 1] = string.format("%d unknown creatures", self.state.at.unknown)
97 end
98 if self.state.at.kektops > 0 then
99 users[#users + 1] = string.format("%d kektops", self.state.at.kektops)
100 end
101 if self.state.at.esps > 0 then
102 users[#users + 1] = string.format("%d ESPs", self.state.at.esps)
103 end
104 end
105
106 usersList = (table.concat(users, ', ') or 'nobody...')
107
108 love.graphics.printf(usersList, 350, 598, 900, 'left')
109 else
110 love.graphics.setColor(1.0, 1.0, 1.0, 0.5)
111 love.graphics.setFont(valueFont)
112 love.graphics.printf("Loading...", 0, 530, love.graphics.getWidth(), "center")
113 end
114
115 love.graphics.setColor( 1.0, 1.0, 1.0 )
116 love.graphics.setFont(timeFont)
117 love.graphics.printf(os.date("%H:%M"), 50, -10, 850, 'center')
118 love.graphics.setFont(dateFont)
119 love.graphics.printf(os.date("%Y\n%m/%d"), 960, 80, 270, 'center')
120
121end
122
123return node