-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowHours.lua
160 lines (142 loc) · 6.73 KB
/
ShowHours.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--[[
ShowHours
Created by K. Rhodus
Version History:
1.0 - Initial Build
]]--
-----------------------------------------------------------------------------------------------------------------------------------------
-- Script Setup --
----------------------------------------------------------------------------------------------------------------------------------------
json = require("rapidjson")
UpdateTime = "12:00" --Move to control
BackupTime = "04:00" --Move to control
-----------------------------------------------------------------------------------------------------------------------------------------
-- Helper Functions --
----------------------------------------------------------------------------------------------------------------------------------------
function debugprint(str)
--print(str) --Uncomment to print debug statements
end
function convTime(timeString)
local hour, min = timeString:match("(%d%d):(%d%d)")
local time = (tonumber(hour)*60)+tonumber(min)
return time
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Notification Setup --
----------------------------------------------------------------------------------------------------------------------------------------
function notRx (name, data)
--print(name,json.encode(data))
if data.Command == "Download" and data.Results.Filename == "SHOWHOURS.json" then
ShowSchedule = json.decode(data.Results.Content)
if ShowSchedule ~= nil then
debugprint(json.encode(ShowSchedule, {pretty=true}))
Evaluate()
CheckTime:Start(60)
Controls.Status.Value = 0
Controls.Status.String = "Downloaded Schedule"
else
--Throw a falt
debugprint("Error Downloading Schedule")
Controls.Status.Value = 2
Controls.Status.String = "Error Downloading Schedule"
end
end
end
ShowMonGit = Notifications.Subscribe("ShowMonGit", notRx) --Move Notification name to control
-----------------------------------------------------------------------------------------------------------------------------------------
-- Get Schedule --
----------------------------------------------------------------------------------------------------------------------------------------
function GetSchedule()
debugprint("Get Schedule")
local temp = {
Command = "Pull",
Args =
{
Filename = "SHOWHOURS.json"
}
}
Notifications.Publish("ShowMonGit", temp)
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Evaluate TOD vs Schedule --
----------------------------------------------------------------------------------------------------------------------------------------
function Evaluate ()
local time = os.date("%H:%M")
local day = tonumber(os.date("%w"))+1
local curTime = convTime(time)
local startTime = convTime(ShowSchedule[day].StartShow)
local ShowStop = convTime(ShowSchedule[day].ShowStop)
local TXStop = convTime(ShowSchedule[day].TXStop)
local AM_Off = convTime(ShowSchedule[day].AM_Off)
local bkTime = convTime(BackupTime)
local upTime = convTime(UpdateTime)
if curTime < AM_Off then
debugprint("OVERNIGHT - NO FM")
Controls.AfterHours.Boolean = true
Controls.FM_Power.Boolean = false
Controls.ShowHours.Boolean = false
Controls.Status.String = "After Show - FM TX Off"
elseif curTime >= startTime and curTime <= ShowStop then
debugprint("ShowTime")
Controls.AfterHours.Boolean = false
Controls.FM_Power.Boolean = true
Controls.ShowHours.Boolean = true
Controls.Status.String = "ShowTime"
elseif curTime > ShowStop and curTime <= TXStop then
debugprint("FM TX After Show")
Controls.AfterHours.Boolean = true
Controls.FM_Power.Boolean = true
Controls.ShowHours.Boolean = false
Controls.Status.String = "After Show - FM TX On"
elseif curTime > TXStop then
debugprint("NIGHT - NO FM")
Controls.AfterHours.Boolean = true
Controls.FM_Power.Boolean = false
Controls.ShowHours.Boolean = false
Controls.Status.String = "After Show - FM TX Off"
else
Controls.AfterHours.Boolean = false
Controls.FM_Power.Boolean = false
Controls.ShowHours.Boolean = false
Controls.Status.String = "Out of Show Hours"
end
if curTime == startTime then
debugprint("TIME MATCH - startTime")
Timer.CallAfter(function() Notifications.Publish("ShowHours", "SHOW START") end, .1)
local temp = "LDPLX Daily Report for ".. os.date("%a %b %d").. "\n Show Starts at: "..ShowSchedule[day].StartShow.. "\n Show Stops at: "..ShowSchedule[day].ShowStop.."\n FM Transmitter turns off at: "..ShowSchedule[day].TXStop.."\n Lights turn off at:"..ShowSchedule[day].AM_Off
Timer.CallAfter(function() Notifications.Publish("ShowAnnc", temp) end, .2)
debugprint("Sending Show Announcement")
elseif curTime == ShowStop then
debugprint("TIME MATCH - ShowStop")
Timer.CallAfter(function() Notifications.Publish("ShowHours", "AFTER SHOW") end, .1)
elseif curTime == TXStop then
debugprint("TIME MATCH - TXStop")
Timer.CallAfter(function() Notifications.Publish("ShowHours", "FM OFF") end, .1)
elseif curTime == upTime then
debugprint("TIME MATCH - upTime")
Timer.CallAfter(function() GetSchedule() end, .1)
end
--[[ --Uncomment once Memory Leak is Discovered
if curTime == bkTime then
--Notifications.Publish("FPPNotify", "Backup")
--print("Backing Up Players")
end
--]]
--Time Debug Printing
debugprint("SHOW TIME CALC")
debugprint(" -Current Time: "..time .. " - ".. curTime)
debugprint(" -Start Time: "..ShowSchedule[day].StartShow .. " - ".. startTime)
debugprint(" -Stop Time: "..ShowSchedule[day].ShowStop .. " - ".. ShowStop)
debugprint(" -TX Stop Time: "..ShowSchedule[day].TXStop .. " - ".. TXStop)
debugprint(" -AM Off Time: "..ShowSchedule[day].AM_Off .. " - ".. AM_Off)
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Update Timer --
----------------------------------------------------------------------------------------------------------------------------------------
CheckTime = Timer.New()
CheckTime.EventHandler = Evaluate
-----------------------------------------------------------------------------------------------------------------------------------------
-- Startup Functions --
----------------------------------------------------------------------------------------------------------------------------------------
GetSchedule()