Skip to content

Commit

Permalink
Merge pull request #26 from deckerego/volume
Browse files Browse the repository at this point in the history
Volume
  • Loading branch information
deckerego authored Feb 15, 2017
2 parents bf4342e + cf8b9e2 commit d2c94d5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Tue, 07 Feb 2017 22:15:00 -0500
20 changes: 20 additions & 0 deletions lib/hackclock/runapp/Libs/GStreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down
2 changes: 2 additions & 0 deletions srv/hackclock/views/blocks/editor.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
% end
<block type="is_playing"></block>
<block type="audio_stop"></block>
<block type="volume_up"></block>
<block type="volume_down"></block>
</category>
<category name="Buttons &amp; Switches" colour="270">
<block type="when_pressed"></block>
Expand Down
60 changes: 60 additions & 0 deletions srv/hackclock/views/blocks/js/blocks/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
10 changes: 10 additions & 0 deletions srv/hackclock/views/blocks/js/generators/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions tests/max_volume.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d2c94d5

Please sign in to comment.