Permalink
Browse files

Fixed trigger logic for all cases of paused/stopped etc. Quite tricky.

  • Loading branch information...
1 parent 268e420 commit 023ebe13a0c05a5a2b934a3c59f7dd8b41bc1fad @ndbroadbent committed Nov 21, 2010
Showing with 12 additions and 4 deletions.
  1. +12 −4 shell-fm_lcd_console.rb
View
16 shell-fm_lcd_console.rb
@@ -183,18 +183,26 @@ def write_static_icons
# Thread for alarms (trigger actions at configured times.)
alarm_thread = Thread.new {
+ # Wait for status to initialize
+ sleep Update_delay * 3
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
+ if alarm["days_of_week"].include?(time.wday)
+ alarm_time = DateTime.parse(alarm["time"])
+ if alarm_time.hour == time.hour && alarm_time.min == time.min
# Alarm matches, trigger action.
case alarm["action"]
when "play"
+ # Volume 0 (because we may have to unpause for a little while)
+ shellfmcmd("volume 0")
+ # If station is paused, we must unpause it first.
+ shellfmcmd("pause") if @status == :paused
shellfmcmd("play lastfm://#{alarm["station"]}")
+ shellfmcmd("skip") unless @status == :stopped # skip 'delay' unless status is stopped
+ shellfmcmd("volume 100") # Reset volume to 100%
when "pause"
- shellfmcmd("pause")
+ shellfmcmd("pause") if @status == :playing
end
end
end

0 comments on commit 023ebe1

Please sign in to comment.