Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made alarms a separate yml file. Also made the app read the alarm fil…

…e every time it checks, in order to make the alarms dynamically configurable.
  • Loading branch information...
commit 4179991823b4dc5743328523a31b410ebd5583c5 1 parent dd3a2ce
@ndbroadbent authored
View
1  .gitignore
@@ -1,2 +1,3 @@
config.yml
+alarms.yml
View
21 alarms.yml.sample
@@ -0,0 +1,21 @@
+---
+-
+ time: "07:30"
+ days_of_week: # monday is day 1
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ station: "globaltags/jazz piano"
+ action: play
+-
+ time: "08:30"
+ days_of_week:
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ action: pause
+
View
21 config.yml.sample
@@ -2,24 +2,3 @@
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
49 shell-fm_lcd_console.rb
@@ -15,7 +15,6 @@
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
@@ -197,28 +196,32 @@ def main_widgets
sleep Update_delay * 3
while true
time = hk_time
- Alarms.each do |alarm|
- 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") if @status == :playing
- when "stop"
- shellfmcmd("volume 0")
- # If station is paused, we must unpause it first.
- shellfmcmd("pause") if @status == :paused
- shellfmcmd("stop")
- shellfmcmd("volume 100") # Reset volume to 100%
+ # Load the alarms file each minute. This is the easiest way to dynamically configure them
+ # via the shellfm sinatra app.
+ if alarms = YAML.load_file(File.join(File.dirname(__FILE__), "alarms.yml"))
+ alarms.each do |alarm|
+ 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") if @status == :playing
+ when "stop"
+ shellfmcmd("volume 0")
+ # If station is paused, we must unpause it first.
+ shellfmcmd("pause") if @status == :paused
+ shellfmcmd("stop")
+ shellfmcmd("volume 100") # Reset volume to 100%
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.