140 lines
No EOL
2.9 KiB
Lua
140 lines
No EOL
2.9 KiB
Lua
local ascii_digits = {
|
|
{
|
|
" 0000 ",
|
|
"00 00",
|
|
"00 00",
|
|
"00 00",
|
|
" 0000 "
|
|
},
|
|
{
|
|
"1111 ",
|
|
" 11 ",
|
|
" 11 ",
|
|
" 11 ",
|
|
"111111"
|
|
},
|
|
{
|
|
" 2222 ",
|
|
"22 22",
|
|
" 22 ",
|
|
" 22 ",
|
|
"222222",
|
|
},
|
|
{
|
|
" 3333 ",
|
|
"33 33",
|
|
" 333",
|
|
"33 33",
|
|
" 3333 ",
|
|
},
|
|
{
|
|
"44 44",
|
|
"44 44",
|
|
"444444",
|
|
" 44",
|
|
" 44"
|
|
},
|
|
{
|
|
"555555",
|
|
"55 ",
|
|
"55555 ",
|
|
" 55",
|
|
"55555"
|
|
},
|
|
{
|
|
" 6666 ",
|
|
"66 ",
|
|
"66666 ",
|
|
"66 66",
|
|
" 6666 "
|
|
},
|
|
{
|
|
"777777",
|
|
" 77 ",
|
|
" 77 ",
|
|
" 77 ",
|
|
"77 "
|
|
},
|
|
{
|
|
" 8888 ",
|
|
"88 88",
|
|
" 8888 ",
|
|
"88 88",
|
|
" 8888 "
|
|
},
|
|
{
|
|
" 9999 ",
|
|
"99 99",
|
|
" 99999",
|
|
" 99",
|
|
" 9999 "
|
|
}
|
|
}
|
|
local seperator = {
|
|
" ",
|
|
" # ",
|
|
" ",
|
|
" # ",
|
|
" ",
|
|
}
|
|
|
|
local function draw_time(x, y, monitor)
|
|
local date = os.date("%b %d")
|
|
local h, m = tostring(os.date("%H")), tostring(os.date("%M"))
|
|
local h1, h2 = tonumber(string.sub(h, 1, 1)), tonumber(string.sub(h, 2, 2))
|
|
local m1, m2 = tonumber(string.sub(m, 1, 1)), tonumber(string.sub(m, 2, 2))
|
|
|
|
local s = os.date("%S")
|
|
|
|
monitor.setCursorPos(x, y)
|
|
monitor.blit(date, "eeef00", "ffffff")
|
|
monitor.setCursorPos(x, y + 1)
|
|
|
|
for i = 1, 5 do
|
|
monitor.setCursorPos(x, select(2, monitor.getCursorPos()) + 1)
|
|
monitor.write(ascii_digits[h1 + 1][i] .. " " .. ascii_digits[h2 + 1][i] .. seperator[i] .. ascii_digits[m1 + 1][i] .. " " .. ascii_digits[m2 + 1][i])
|
|
end
|
|
end
|
|
|
|
local function draw_timezone(x, y, tz_name, utc_offset, tz_monitor)
|
|
--[[
|
|
/SYD\
|
|
|22:34|
|
|
\_ _/
|
|
]]
|
|
if #tz_name ~= 3 then error("Invalid timezone name (not 3 letters)") end
|
|
local utc = os.date("!*t")
|
|
local tz_hour = utc.hour + utc_offset
|
|
if tz_hour > 23 then
|
|
tz_hour = -24 + tz_hour end
|
|
|
|
|
|
local day_part = {
|
|
["day"] = "☼",
|
|
["night"] = "☾"
|
|
}
|
|
local tz_symbol
|
|
if (tz_hour > 20 or tz_hour < 7) then tz_symbol = day_part["night"] else tz_symbol = day_part["day"] end
|
|
|
|
tz_monitor.setCursorPos(x, y)
|
|
tz_monitor.blit(" /" .. tz_name .. "\\", "f04440", "ffffff")
|
|
tz_monitor.setCursorPos(x, y + 1)
|
|
tz_monitor.write("|" .. tostring(utc.hour + utc_offset) .. ":" .. tostring(utc.min) .. "|")
|
|
tz_monitor.setCursorPos(x, y + 2)
|
|
tz_monitor.blit(" \\_" .. tz_symbol .. "_/ ", "f00400f", "fffffff")
|
|
end
|
|
|
|
local clock = {}
|
|
clock.new = function (monitor_wrap)
|
|
local self = {}
|
|
local monitor = monitor_wrap or peripheral.find("monitor")
|
|
|
|
function self.update()
|
|
draw_time(2, 2, monitor)
|
|
draw_timezone(2, 11, "SYD", 10, monitor)
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
return clock |