Permalink
Browse files

Added alarms to app. Can configure shell.fm to play/pause a given sta…

…tion at certain times for certain days of the week
  • Loading branch information...
1 parent bad1fc4 commit 268e42092e376eba0398b3c136417e7eedbf6cb9 @ndbroadbent committed Nov 21, 2010
Showing with 57 additions and 0 deletions.
  1. +21 −0 config.yml.sample
  2. +36 −0 shell-fm_lcd_console.rb
View
@@ -2,3 +2,24 @@
host: localhost # (shellfm host)
port: 54311 # (Port to control shell-fm on.)
+alarms:
+ -
+ days_of_week: # monday is day 1
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ time: "07:30"
+ station: "globaltags/jazz piano"
+ action: play
+ -
+ days_of_week:
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ time: "08:30"
+ action: pause
+
View
@@ -15,6 +15,7 @@
config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
Host = config["host"]
Port = config["port"]
+Alarms = config["alarms"]
Update_delay = 3.0 # Delay between shell.fm refreshes.
Scroll_delay = 0.5 # speed of artist and title scrolling
@@ -36,6 +37,16 @@ def shellfm_info
# On error, return false
return false
end
+# Sends a cmd to the shellfm network interface.
+def shellfmcmd(cmd)
+ t = TCPSocket.new(Host, Port)
+ t.print cmd + "\n"
+ info = t.gets(nil)
+ t.close
+ return true
+ rescue
+ false
+end
def display_widget(widget)
$p.message widget.render, widget.pos
@@ -170,6 +181,31 @@ def write_static_icons
end
}
+# Thread for alarms (trigger actions at configured times.)
+alarm_thread = Thread.new {
+ while true
+ time = Time.now
+ Alarms.each do |alarm|
+ if alarm["days_of_week"].include?(t.wday)
+ alarm = DateTime.parse(alarm["time"])
+ if alarm.hour == time.hour && alarm.min == time.min
+ # Alarm matches, trigger action.
+ case alarm["action"]
+ when "play"
+ shellfmcmd("play lastfm://#{alarm["station"]}")
+ when "pause"
+ shellfmcmd("pause")
+ end
+ end
+ end
+ end
+ # Wait until the next minute, then loop.
+ while Time.now.min == time.min
+ sleep 5
+ end
+ end
+}
+
# Loop to refresh widgets when needed. Also control backlight.
while true
case @status

0 comments on commit 268e420

Please sign in to comment.