Skip to content

Commit

Permalink
Fixed trigger logic for all cases of paused/stopped etc. Quite tricky.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Nov 21, 2010
1 parent 268e420 commit 023ebe1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shell-fm_lcd_console.rb
Expand Up @@ -183,18 +183,26 @@ def write_static_icons


# Thread for alarms (trigger actions at configured times.) # Thread for alarms (trigger actions at configured times.)
alarm_thread = Thread.new { alarm_thread = Thread.new {
# Wait for status to initialize
sleep Update_delay * 3
while true while true
time = Time.now time = Time.now
Alarms.each do |alarm| Alarms.each do |alarm|
if alarm["days_of_week"].include?(t.wday) if alarm["days_of_week"].include?(time.wday)
alarm = DateTime.parse(alarm["time"]) alarm_time = DateTime.parse(alarm["time"])
if alarm.hour == time.hour && alarm.min == time.min if alarm_time.hour == time.hour && alarm_time.min == time.min
# Alarm matches, trigger action. # Alarm matches, trigger action.
case alarm["action"] case alarm["action"]
when "play" 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("play lastfm://#{alarm["station"]}")
shellfmcmd("skip") unless @status == :stopped # skip 'delay' unless status is stopped
shellfmcmd("volume 100") # Reset volume to 100%
when "pause" when "pause"
shellfmcmd("pause") shellfmcmd("pause") if @status == :playing
end end
end end
end end
Expand Down

0 comments on commit 023ebe1

Please sign in to comment.