SHOW:
|
|
- or go back to the newest paste.
1 | - | MT_BG = 0x000000 |
1 | + | MT_BG = 0x000000 |
2 | - | MT_FG = 0xFFFFFF |
2 | + | MT_FG = 0xFFFFFF |
3 | - | DAY = 0xFFFF00 |
3 | + | DAY = 0xFFFF00 |
4 | - | EVENING = 0x202080 |
4 | + | EVENING = 0x202080 |
5 | - | NIGHT = 0x000080 |
5 | + | NIGHT = 0x000080 |
6 | - | MORNING = 0x404000 |
6 | + | MORNING = 0x404000 |
7 | - | RT_BG = 0x000000 |
7 | + | RT_BG = 0x000000 |
8 | - | RT_FG = 0xFFFFFF |
8 | + | RT_FG = 0xFFFFFF |
9 | - | TIMER_BG = 0x000080 |
9 | + | TIMEZONE = 0 |
10 | - | TIMER_FG = 0xFFFFFF |
10 | + | CORRECT = 0 |
11 | - | ALARM_BG = 0x008000 |
11 | + | W, H = 40, 8 |
12 | - | ALARM_FG = 0xFFFFFF |
12 | + | REDSTONE = false |
13 | - | TIMEZONE = 6 |
13 | + | TOUCH = true |
14 | - | W, H = 40, 8 |
14 | + | KEY1 = 13 |
15 | - | REDSTONE = true |
15 | + | KEY2 = 28 |
16 | - | TOUCH = true |
16 | + | SHOWSECS = true |
17 | - | KEY1 = 13 |
17 | + | AUTOMODE = true |
18 | - | KEY2 = 28 |
18 | + | SWDATEMT = true |
19 | - | SHOWSECS = true |
19 | + | SWDATERT = true |
20 | - | AUTOMODE = true |
20 | + | SWDTMMT = true |
21 | - | SWDATEMT = true |
21 | + | SWDTMRT = true |
22 | - | SWDATERT = true |
22 | + | |
23 | - | SWDTMMT = true |
23 | + | local com = require("component") |
24 | - | SWDTMRT = true |
24 | + | local gpu = com.gpu |
25 | - | |
25 | + | local unicode = require("unicode") |
26 | - | local com = require("component") |
26 | + | local fs = require("filesystem") |
27 | - | local gpu = com.gpu |
27 | + | local event = require("event") |
28 | - | local unicode = require("unicode") |
28 | + | local term = require("term") |
29 | - | local fs = require("filesystem") |
29 | + | |
30 | - | local event = require("event") |
30 | + | oldw, oldh = gpu.getResolution() |
31 | - | local term = require("term") |
31 | + | gpu.setResolution(W, H) |
32 | - | |
32 | + | w, h = gpu.getResolution() |
33 | - | oldw, oldh = gpu.getResolution() |
33 | + | mode = AUTOMODE |
34 | - | gpu.setResolution(W, H) |
34 | + | noExit = true |
35 | - | w, h = gpu.getResolution() |
35 | + | |
36 | - | mode = AUTOMODE |
36 | + | tz = TIMEZONE + CORRECT |
37 | - | noExit = true |
37 | + | local nums = {} |
38 | - | |
38 | + | nums[0] = {"███", "█ █", "█ █", "█ █", "███"} |
39 | - | tz = TIMEZONE - 1 |
39 | + | nums[1] = {"██ ", " █ ", " █ ", " █ ", "███"} |
40 | - | local nums = {} |
40 | + | nums[2] = {"███", " █", "███", "█ ", "███"} |
41 | - | nums[0] = {"###", "# #", "# #", "# #", "###"} |
41 | + | nums[3] = {"███", " █", "███", " █", "███"} |
42 | - | nums[1] = {"## ", " # ", " # ", " # ", "###"} |
42 | + | nums[4] = {"█ █", "█ █", "███", " █", " █"} |
43 | - | nums[2] = {"###", " #", "###", "# ", "###"} |
43 | + | nums[5] = {"███", "█ ", "███", " █", "███"} |
44 | - | nums[3] = {"###", " #", "###", " #", "###"} |
44 | + | nums[6] = {"███", "█ ", "███", "█ █", "███"} |
45 | - | nums[4] = {"# #", "# #", "###", " #", " #"} |
45 | + | nums[7] = {"███", " █", " █", " █", " █"} |
46 | - | nums[5] = {"###", "# ", "###", " #", "###"} |
46 | + | nums[8] = {"███", "█ █", "███", "█ █", "███"} |
47 | - | nums[6] = {"###", "# ", "###", "# #", "###"} |
47 | + | nums[9] = {"███", "█ █", "███", " █", "███"} |
48 | - | nums[7] = {"###", " #", " #", " #", " #"} |
48 | + | |
49 | - | nums[8] = {"###", "# #", "###", "# #", "###"} |
49 | + | dts = {} |
50 | - | nums[9] = {"###", "# #", "###", " #", "###"} |
50 | + | dts[1] = "Night" |
51 | - | |
51 | + | dts[2] = "Morning" |
52 | - | dts = {} |
52 | + | dts[3] = "Day" |
53 | - | dts[1] = "Night" |
53 | + | dts[4] = "Evening" |
54 | - | dts[2] = "Morning" |
54 | + | |
55 | - | dts[3] = "Day" |
55 | + | local function centerX(str) |
56 | - | dts[4] = "Evening" |
56 | + | local len |
57 | - | |
57 | + | if type(str) == "string" then |
58 | - | local function centerX(str) |
58 | + | len = unicode.len(str) |
59 | - | local len |
59 | + | elseif type(str) == "number" then |
60 | - | if type(str) == "string" then |
60 | + | len = str |
61 | - | len = unicode.len(str) |
61 | + | else |
62 | - | elseif type(str) == "number" then |
62 | + | error("Number excepted") |
63 | - | len = str |
63 | + | end |
64 | - | else |
64 | + | local whereW, _ = math.modf(w / 2) |
65 | - | error("Number excepted") |
65 | + | local whereT, _ = math.modf(len / 2) |
66 | - | end |
66 | + | local where = whereW - whereT + 1 |
67 | - | local whereW, _ = math.modf(w / 2) |
67 | + | return where |
68 | - | local whereT, _ = math.modf(len / 2) |
68 | + | end |
69 | - | local where = whereW - whereT + 1 |
69 | + | |
70 | - | return where |
70 | + | local function centerY(lines) |
71 | - | end |
71 | + | local whereH, _ = math.modf(h / 2) |
72 | - | |
72 | + | local whereT, _ = math.modf(lines / 2) |
73 | - | local function centerY(lines) |
73 | + | local where = whereH - whereT + 1 |
74 | - | local whereH, _ = math.modf(h / 2) |
74 | + | return where |
75 | - | local whereT, _ = math.modf(lines / 2) |
75 | + | end |
76 | - | local where = whereH - whereT + 1 |
76 | + | |
77 | - | return where |
77 | + | local t_correction = tz * 3600 |
78 | - | end |
78 | + | |
79 | - | |
79 | + | local function getTime() |
80 | - | local t_correction = tz * 3600 |
80 | + | local file = io.open('/tmp/clock.dt', 'w') |
81 | - | |
81 | + | file:write('') |
82 | - | local function getTime() |
82 | + | file:close() |
83 | - | local file = io.open('/tmp/clock.dt', 'w') |
83 | + | local lastmod = tonumber(string.sub(fs.lastModified('/tmp/clock.dt'), 1, -4)) + t_correction |
84 | - | file:write('') |
84 | + | |
85 | - | file:close() |
85 | + | local year = os.date('%Y', lastmod) |
86 | - | local lastmod = tonumber(string.sub(fs.lastModified('/tmp/clock.dt'), 1, -4)) + t_correction |
86 | + | local month = os.date('%m', lastmod) |
87 | - | |
87 | + | local day = os.date('%d', lastmod) |
88 | - | local year = os.date('%Y', lastmod) |
88 | + | local weekday = os.date('%A', lastmod) |
89 | - | local month = os.date('%m', lastmod) |
89 | + | local hour = os.date('%H', lastmod) |
90 | - | local day = os.date('%d', lastmod) |
90 | + | local minute = os.date('%M', lastmod) |
91 | - | local weekday = os.date('%A', lastmod) |
91 | + | local sec = os.date('%S', lastmod) |
92 | - | local hour = os.date('%H', lastmod) |
92 | + | return year, month, day, weekday, hour, minute, sec |
93 | - | local minute = os.date('%M', lastmod) |
93 | + | end |
94 | - | local sec = os.date('%S', lastmod) |
94 | + | |
95 | - | return year, month, day, weekday, hour, minute, sec |
95 | + | local function sn(num) |
96 | - | end |
96 | + | -- SplitNumber |
97 | - | |
97 | + | local n1, n2 |
98 | - | local function sn(num) |
98 | + | if num >= 10 then |
99 | - | -- SplitNumber |
99 | + | n1, n2 = tostring(num):match("(%d)(%d)") |
100 | - | local n1, n2 |
100 | + | n1, n2 = tonumber(n1), tonumber(n2) |
101 | - | if num >= 10 then |
101 | + | else |
102 | - | n1, n2 = tostring(num):match("(%d)(%d)") |
102 | + | n1, n2 = 0, num |
103 | - | n1, n2 = tonumber(n1), tonumber(n2) |
103 | + | end |
104 | - | else |
104 | + | return n1, n2 |
105 | - | n1, n2 = 0, num |
105 | + | end |
106 | - | end |
106 | + | |
107 | - | return n1, n2 |
107 | + | local function drawNumbers(hh, mm, ss) |
108 | - | end |
108 | + | local firstLine = centerY(5) |
109 | - | |
109 | + | local n1, n2, n3, n4, n5, n6 |
110 | - | local function drawNumbers(hh, mm, ss) |
110 | + | n1, n2 = sn(hh) |
111 | - | local firstLine = centerY(5) |
111 | + | n3, n4 = sn(mm) |
112 | - | local n1, n2, n3, n4, n5, n6 |
112 | + | if ss ~= nil then |
113 | - | n1, n2 = sn(hh) |
113 | + | n5, n6 = sn(ss) |
114 | - | n3, n4 = sn(mm) |
114 | + | end |
115 | - | if ss ~= nil then |
115 | + | --print(n1, n2, n3, n4, n5, n6, type(n1)) |
116 | - | n5, n6 = sn(ss) |
116 | + | for i = 1, 5, 1 do |
117 | - | end |
117 | + | local sep |
118 | - | --print(n1, n2, n3, n4, n5, n6, type(n1)) |
118 | + | if i == 2 or i == 4 then |
119 | - | for i = 1, 5, 1 do |
119 | + | sep = " . " |
120 | - | local sep |
120 | + | else |
121 | - | if i == 2 or i == 4 then |
121 | + | sep = " " |
122 | - | sep = " . " |
122 | + | end |
123 | - | else |
123 | + | local lineToDraw = "" |
124 | - | sep = " " |
124 | + | if ss ~= nil then |
125 | - | end |
125 | + | lineToDraw = nums[n1][i] .. " " .. nums[n2][i] .. sep .. nums[n3][i] .. " " .. nums[n4][i] .. sep .. nums[n5][i] .. " " .. nums[n6][i] |
126 | - | local lineToDraw = "" |
126 | + | else |
127 | - | if ss ~= nil then |
127 | + | lineToDraw = nums[n1][i] .. " " .. nums[n2][i] .. sep .. nums[n3][i] .. " " .. nums[n4][i] |
128 | - | lineToDraw = nums[n1][i] .. " " .. nums[n2][i] .. sep .. nums[n3][i] .. " " .. nums[n4][i] .. sep .. nums[n5][i] .. " " .. nums[n6][i] |
128 | + | end |
129 | - | else |
129 | + | gpu.set(centerX(lineToDraw), firstLine + i - 1, lineToDraw) |
130 | - | lineToDraw = nums[n1][i] .. " " .. nums[n2][i] .. sep .. nums[n3][i] .. " " .. nums[n4][i] |
130 | + | end |
131 | - | end |
131 | + | end |
132 | - | gpu.set(centerX(lineToDraw), firstLine + i - 1, lineToDraw) |
132 | + | |
133 | - | end |
133 | + | local function setDaytimeColor(hh, mm) |
134 | - | end |
134 | + | local daytime |
135 | - | |
135 | + | if (hh == 19 and mm >= 30) or (hh > 19 and hh < 22) then |
136 | - | local function setDaytimeColor(hh, mm) |
136 | + | daytime = 4 |
137 | - | local daytime |
137 | + | gpu.setForeground(EVENING) |
138 | - | if (hh == 19 and mm >= 30) or (hh > 19 and hh < 22) then |
138 | + | elseif hh >= 22 or hh < 6 then |
139 | - | daytime = 4 |
139 | + | daytime = 1 |
140 | - | gpu.setForeground(EVENING) |
140 | + | gpu.setForeground(NIGHT) |
141 | - | elseif hh >= 22 or hh < 6 then |
141 | + | elseif hh >= 6 and hh < 12 then |
142 | - | daytime = 1 |
142 | + | daytime = 2 |
143 | - | gpu.setForeground(NIGHT) |
143 | + | gpu.setForeground(MORNING) |
144 | - | elseif hh >= 6 and hh < 12 then |
144 | + | elseif (hh >= 12 and hh < 19) or (hh == 19 and mm < 30) then |
145 | - | daytime = 2 |
145 | + | daytime = 3 |
146 | - | gpu.setForeground(MORNING) |
146 | + | gpu.setForeground(DAY) |
147 | - | elseif (hh >= 12 and hh < 19) or (hh == 19 and mm < 30) then |
147 | + | end |
148 | - | daytime = 3 |
148 | + | return daytime |
149 | - | gpu.setForeground(DAY) |
149 | + | end |
150 | - | end |
150 | + | |
151 | - | return daytime |
151 | + | local function drawMT() |
152 | - | end |
152 | + | local year, month, day, hh, mm = os.date():match("(%d+)/(%d+)/(%d+)%s(%d+):(%d+):%d+") |
153 | - | |
153 | + | hh, mm = tonumber(hh), tonumber(mm) |
154 | - | local function drawMT() |
154 | + | gpu.fill(1, 1, w, h, " ") |
155 | - | local year, month, day, hh, mm = os.date():match("(%d+)/(%d+)/(%d+)%s(%d+):(%d+):%d+") |
155 | + | drawNumbers(hh, mm) |
156 | - | hh, mm = tonumber(hh), tonumber(mm) |
156 | + | if SWDTMMT then |
157 | - | gpu.fill(1, 1, w, h, " ") |
157 | + | local dtm = setDaytimeColor(hh, mm) |
158 | - | drawNumbers(hh, mm) |
158 | + | gpu.set(centerX(dts[dtm]), centerY(5) - 1, dts[dtm]) |
159 | - | if SWDTMMT then |
159 | + | end |
160 | - | local dtm = setDaytimeColor(hh, mm) |
160 | + | gpu.setForeground(MT_FG) |
161 | - | gpu.set(centerX(dts[dtm]), centerY(5) - 1, dts[dtm]) |
161 | + | if SWDATEMT then |
162 | - | end |
162 | + | gpu.set(centerX(year .. "/" .. month .. "/" .. day), centerY(1) + 3, year .. "/" .. month .. "/" .. day) |
163 | - | gpu.setForeground(MT_FG) |
163 | + | end |
164 | - | if SWDATEMT then |
164 | + | end |
165 | - | gpu.set(centerX(year .. "/" .. month .. "/" .. day), centerY(1) + 3, year .. "/" .. month .. "/" .. day) |
165 | + | |
166 | - | end |
166 | + | local function drawRT() |
167 | - | end |
167 | + | local year, month, day, wd, hh, mm, ss = getTime() |
168 | - | |
168 | + | gpu.fill(1, 1, w, h, " ") |
169 | - | local function drawRT() |
169 | + | hh, mm, ss = tonumber(hh), tonumber(mm), tonumber(ss) |
170 | - | local year, month, day, wd, hh, mm, ss = getTime() |
170 | + | if not SHOWSECS then |
171 | - | gpu.fill(1, 1, w, h, " ") |
171 | + | ss = nil |
172 | - | hh, mm, ss = tonumber(hh), tonumber(mm), tonumber(ss) |
172 | + | end |
173 | - | if not SHOWSECS then |
173 | + | drawNumbers(hh, mm, ss) |
174 | - | ss = nil |
174 | + | if SWDTMRT then |
175 | - | end |
175 | + | local dtm = setDaytimeColor(hh, mm) |
176 | - | drawNumbers(hh, mm, ss) |
176 | + | gpu.set(centerX(dts[dtm]), centerY(5) - 1, dts[dtm]) |
177 | - | if SWDTMRT then |
177 | + | end |
178 | - | local dtm = setDaytimeColor(hh, mm) |
178 | + | gpu.setForeground(RT_FG) |
179 | - | gpu.set(centerX(dts[dtm]), centerY(5) - 1, dts[dtm]) |
179 | + | local infoLine = wd .. ", " .. year .. "/" .. month .. "/" .. day .. "::GMT" .. TIMEZONE |
180 | - | end |
180 | + | if SWDATERT then |
181 | - | gpu.setForeground(RT_FG) |
181 | + | gpu.set(centerX(infoLine), centerY(1) + 3, infoLine) |
182 | - | local infoLine = wd .. ", " .. year .. "/" .. month .. "/" .. day .. "::GMT" .. TIMEZONE |
182 | + | end |
183 | - | if SWDATERT then |
183 | + | end |
184 | - | gpu.set(centerX(infoLine), centerY(1) + 3, infoLine) |
184 | + | |
185 | - | end |
185 | + | local function cbFunc() |
186 | - | end |
186 | + | if mode == true then mode = false gpu.setBackground(RT_BG) gpu.setForeground(RT_FG) else mode = true gpu.setBackground(MT_BG) gpu.setForeground(MT_FG) end |
187 | - | |
187 | + | end |
188 | - | local function cbFunc() |
188 | + | |
189 | - | if mode == true then mode = false gpu.setBackground(RT_BG) gpu.setForeground(RT_FG) else mode = true gpu.setBackground(MT_BG) gpu.setForeground(MT_FG) end |
189 | + | local function checkKey(name, addr, key1, key2) |
190 | - | end |
190 | + | if key1 == KEY1 and key2 == KEY2 then |
191 | - | |
191 | + | noExit = false |
192 | - | local function checkKey(name, addr, key1, key2) |
192 | + | end |
193 | - | if key1 == KEY1 and key2 == KEY2 then |
193 | + | end |
194 | - | noExit = false |
194 | + | |
195 | - | end |
195 | + | gpu.fill(1, 1, w, h, " ") |
196 | - | end |
196 | + | if TOUCH then |
197 | - | |
197 | + | event.listen("touch", cbFunc) |
198 | - | gpu.fill(1, 1, w, h, " ") |
198 | + | end |
199 | - | if TOUCH then |
199 | + | if REDSTONE then |
200 | - | event.listen("touch", cbFunc) |
200 | + | event.listen("redstone_changed", cbFunc) |
201 | - | end |
201 | + | end |
202 | - | if REDSTONE then |
202 | + | event.listen("key_down", checkKey) |
203 | - | event.listen("redstone_changed", cbFunc) |
203 | + | term.setCursor(1, 1) |
204 | - | end |
204 | + | while noExit do |
205 | - | event.listen("key_down", checkKey) |
205 | + | if mode == true then |
206 | - | term.setCursor(1, 1) |
206 | + | drawMT() |
207 | - | while noExit do |
207 | + | else |
208 | - | if mode == true then |
208 | + | drawRT() |
209 | - | drawMT() |
209 | + | end |
210 | - | else |
210 | + | os.sleep(1) |
211 | - | drawRT() |
211 | + | end |
212 | - | end |
212 | + | gpu.setForeground(0xFFFFFF) |
213 | - | os.sleep(1) |
213 | + | gpu.setBackground(0x000000) |
214 | - | end |
214 | + | gpu.setResolution(oldw, oldh) |
215 | - | gpu.setForeground(0xFFFFFF) |
215 | + |