Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refresh motd every new day at 00:00

  • Loading branch information...
commit 7c880706220b6b0c47610f89148cd03ce44fe0e9 1 parent c305ff7
@ndbroadbent authored
Showing with 22 additions and 13 deletions.
  1. +22 −13 octopus_sinatra.rb
View
35 octopus_sinatra.rb
@@ -41,6 +41,18 @@ def relative(filename)
$lcdTimeThread = nil
+# A custom default message, based on the current date
+def motd
+ time = hk_time
+ return case [time.day, time.month]
+ when [25, 12] then " Merry Christmas! "
+ when easter(time.year) then " Jesus is Alive! "
+ when [5, 10] then " Happy B'day Masha! "
+ when [3, 6] then "Happy B'day Nathan! "
+ else " Octopus & Internet " # else, default message
+ end
+end
+
def lcd_message(str, s_pos=21, e_pos=40, timeout=true)
# Kill 'clock' thread before writing message.
if $lcdTimeThread
@@ -56,23 +68,19 @@ def lcd_message(str, s_pos=21, e_pos=40, timeout=true)
def lcd_default # Default lcd display
lcd_message "Flat 10C -=- ", 1, 20, false
-
- time = hk_time
- motd = case [time.day, time.month]
- when [25, 12] then " Merry Christmas! "
- when easter(time.year) then " Jesus is Alive! "
- when [5, 10] then " Happy B'day Masha! "
- when [3, 6] then "Happy B'day Nathan! "
- else " Octopus & Internet " # else, default message
- end
lcd_message motd, 21, 40, false
$lcdTimeThread = Thread.new {
while true
- $dsp420.write hk_time_lcd_fmt(":"), 14, 20, false
+ time = hk_time
+ $dsp420.write lcd_time_fmt(time, ":"), 14, 20, false
sleep 1
- $dsp420.write hk_time_lcd_fmt(" "), 14, 20, false
+ $dsp420.write lcd_time_fmt(time, " "), 14, 20, false
sleep 1
+ # If its the start of a new day, refresh the message.
+ if time.hour == 0 and time.min == 0 and time.sec < 3
+ lcd_message motd, 21, 40, false
+ end
end
}
end
@@ -85,6 +93,8 @@ def easter(year)
[day, month]
end
+
+
def unlock_door_action
Thread.new do
$k8055.set_digital SwitchChannel, false
@@ -131,8 +141,7 @@ def hk_time_fmt
hk_time.strftime("%Y-%m-%d %H:%M:%S")
end
-def hk_time_lcd_fmt(separator=":")
- time = hk_time
+def lcd_time_fmt(time = hk_time, separator = ":")
hour, minute = time.hour, time.min
hour, suffix = hour >= 12 ? [hour - 12, "pm"] : [hour, "am"]
hour = 12 if hour == 0
Please sign in to comment.
Something went wrong with that request. Please try again.