diff --git a/README.md b/README.md index c9cf9a6..8ce75c9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ I'm assuming that you are starting with the Raspian Minimal Linux distribution. 1. Make sure your Raspberry Pi is up to date with the latest packages & firmware with `sudo apt-get update; sudo apt-get dist-upgrade` 2. Enable I2C by executing `sudo raspi-config` as described in Adafruit's tutorial: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c 3. Add the necessary Python and GStreamer dependencies using the command: `sudo apt-get install wiringpi python-bottle python-requests python-oauth2client python-httplib2 python-setuptools python-pip python-dev python-dateutil python-smbus gstreamer0.10-x gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly python-gst0.10` -4. Install hack-clock via `wget https://github.com/deckerego/hack-clock/releases/download/2.1.4/python-hackclock_2.1.4-1_all.deb; sudo dpkg -i python-hackclock_2.1.4-1_all.deb` +4. Install hack-clock via `wget https://github.com/deckerego/hack-clock/releases/download/2.1.5/python-hackclock_2.1.5-1_all.deb; sudo dpkg -i python-hackclock_2.1.5-1_all.deb` 5. Tweak `/etc/hack-clock.conf` and `/etc/default/hack-clock` to fit your needs (GPIO pins, correct weather station, etc.). A list of observed weather stations is available at http://forecast.weather.gov/stations.php 6. Reboot your Pi to re-load modules and start the IDE web server diff --git a/debian/changelog b/debian/changelog index dc850ac..b0b9a19 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,5 @@ -hackclock (2.1.4-1) stable; urgency=low +hackclock (2.1.5-1) stable; urgency=low - * Added in Alsa + Gst 0.10 as a dependency to hopefully address some fd errors that killed the audio stream + * Added ability to adjust volume -- DeckerEgo Tue, 07 Feb 2017 22:15:00 -0500 diff --git a/lib/hackclock/runapp/Libs/GStreamer.py b/lib/hackclock/runapp/Libs/GStreamer.py index 16c9d5e..68c9f2e 100644 --- a/lib/hackclock/runapp/Libs/GStreamer.py +++ b/lib/hackclock/runapp/Libs/GStreamer.py @@ -17,10 +17,12 @@ class Speaker: __HTTP_PATTERN = re.compile("http[s]*://.*") + __volume = None def __init__(self): self.pl = None self.eventLoop = None + self.__volume = 1.0 gobject.threads_init() def __del__(self): @@ -39,6 +41,7 @@ def play(self): # Create the pipeline self.pl = gst.element_factory_make("playbin2", "player") self.pl.set_state(gst.STATE_READY) + self.pl.set_property('volume', self.__volume) # Create the event bus self.bus = self.pl.get_bus() @@ -70,6 +73,7 @@ def next(self): logger.info("Playing: %s" % track) self.pl.set_state(gst.STATE_READY) self.pl.set_property('uri', track) + self.pl.set_property('volume', self.__volume) self.pl.set_state(gst.STATE_PLAYING) else: self.stop() @@ -78,6 +82,22 @@ def onMessage(self, bus, message): if message.type == gst.MESSAGE_EOS: self.next() + def setVolume(self, level): + if level <= 1.0 and level >= 0.0: + self.__volume = level + + if self.isPlaying() and self.pl: + self.pl.set_property('volume', self.__volume) + else: + logger.warning("Cannot set volume when nothing is playing") + + def volumeUp(self): + self.setVolume(self.__volume + 0.1) + + def volumeDown(self): + self.setVolume(self.__volume - 0.1) + + class GtkEventLoop(threading.Thread): def __init__(self): diff --git a/package.sh b/package.sh index 2fabf0b..76d8778 100755 --- a/package.sh +++ b/package.sh @@ -7,7 +7,7 @@ rm home/pi/hack-clock/backups/blocks_clock.* cd .. echo "Compressing file..." -tar Jcf hackclock_2.1.4.orig.tar.xz hack-clock/ +tar Jcf hackclock_2.1.5.orig.tar.xz hack-clock/ cd hack-clock dpkg-buildpackage -rfakeroot -uc -us diff --git a/setup.py b/setup.py index 0414c84..4961a49 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ def all_files(newroot, oldroot): setup( name='HackClock', - version='2.1.4', + version='2.1.5', description='A hackable alarm clock for the Raspberry Pi', author='DeckerEgo', author_email='john@deckerego.net', diff --git a/srv/hackclock/views/blocks/editor.tpl b/srv/hackclock/views/blocks/editor.tpl index 5af763e..cd178a9 100644 --- a/srv/hackclock/views/blocks/editor.tpl +++ b/srv/hackclock/views/blocks/editor.tpl @@ -125,6 +125,8 @@ % end + + diff --git a/srv/hackclock/views/blocks/js/blocks/audio.js b/srv/hackclock/views/blocks/js/blocks/audio.js index 638949e..1a745fb 100644 --- a/srv/hackclock/views/blocks/js/blocks/audio.js +++ b/srv/hackclock/views/blocks/js/blocks/audio.js @@ -109,6 +109,66 @@ Blockly.Blocks['play_list'] = { } }; +Blockly.Blocks['volume_up'] = { + init: function() { + this.jsonInit({ + "type": "volume_up", + "message0": "Turn Volume Up %1", + "args0": [ + { + "type": "input_value", + "name": "speaker", + "check": "Speaker" + } + ], + "inputsInline": false, + "previousStatement": null, + "nextStatement": null, + "colour": 255, + "tooltip": "Turn up the volume on a speaker", + "helpUrl": "http://hackclock.deckerego.net/" + }); + + var thisBlock = this; + + this.setTooltip(function() { + var parent = thisBlock.getParent(); + return (parent && parent.getInputsInline() && parent.tooltip) || + 'Turn up the volume on a speaker'; + }); + } +}; + +Blockly.Blocks['volume_down'] = { + init: function() { + this.jsonInit({ + "type": "volume_down", + "message0": "Turn Volume Down %1", + "args0": [ + { + "type": "input_value", + "name": "speaker", + "check": "Speaker" + } + ], + "inputsInline": false, + "previousStatement": null, + "nextStatement": null, + "colour": 255, + "tooltip": "Turn down the volume on a speaker", + "helpUrl": "http://hackclock.deckerego.net/" + }); + + var thisBlock = this; + + this.setTooltip(function() { + var parent = thisBlock.getParent(); + return (parent && parent.getInputsInline() && parent.tooltip) || + 'Turn down the volume on a speaker'; + }); + } +}; + Blockly.Blocks['google_music_radio'] = { init: function() { this.jsonInit({ diff --git a/srv/hackclock/views/blocks/js/generators/audio.js b/srv/hackclock/views/blocks/js/generators/audio.js index 0e274d4..9c924a4 100644 --- a/srv/hackclock/views/blocks/js/generators/audio.js +++ b/srv/hackclock/views/blocks/js/generators/audio.js @@ -44,6 +44,16 @@ Blockly.Python['play_list'] = function(block) { return ''+value_speaker+'.playList('+value_songs+')\n'; }; +Blockly.Python['volume_up'] = function(block) { + var value_speaker = Blockly.Python.valueToCode(block, 'speaker', Blockly.Python.ORDER_ATOMIC); + return ''+value_speaker+'.volumeUp()\n'; +}; + +Blockly.Python['volume_down'] = function(block) { + var value_speaker = Blockly.Python.valueToCode(block, 'speaker', Blockly.Python.ORDER_ATOMIC); + return ''+value_speaker+'.volumeDown()\n'; +}; + Blockly.Python['is_playing'] = function(block) { var value_speaker = Blockly.Python.valueToCode(block, 'speaker', Blockly.Python.ORDER_ATOMIC); return [value_speaker + '.isPlaying()', Blockly.Python.ORDER_NONE]; diff --git a/tests/max_volume.sh b/tests/max_volume.sh index 287f5cd..9f893eb 100644 --- a/tests/max_volume.sh +++ b/tests/max_volume.sh @@ -1,5 +1,7 @@ #!/bin/sh rm ~/.asoundrc +alsactl restore -i /etc/asound.conf 0 +alsactl init -i /etc/asound.conf 0 amixer set Master -- 100% speaker-test -c2 -twav