Skip to content

Commit d6870c8

Browse files
MicheleCarboneraMicheleCarbonera
authored andcommitted
Merge branch 'volumeLevelCtrl' into music_ext_sprint_1
2 parents d6c9ac6 + b712797 commit d6870c8

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

audioControls.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# CoderBot, a didactical programmable robot.
2+
# Copyright (C) 2014, 2015 Roberto Previtera <info@coderbot.org>
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; either version 2 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License along
15+
# with this program; if not, write to the Free Software Foundation, Inc.,
16+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
############################################################################
18+
# CoderBot, a didactical programmable robot.
19+
# Copyright (C) 2014, 2015 Roberto Previtera <info@coderbot.org>
20+
#
21+
# MUSICAL EXTENTION for CoderBot
22+
# This extention is develop by:
23+
# Michele Carbonera - miki_992@hotmail.it - m.carbonera@campus.unimib.it - michele.carbonera@unimib.it
24+
# Antonino Tramontana - a.tramontana1@campus.unimib.it
25+
# Copyright (C) 2020
26+
############################################################################
27+
28+
import os
29+
import alsaaudio
30+
31+
class AudioCtrl:
32+
mixer = None
33+
_instance = None
34+
35+
@classmethod
36+
def get_instance(cls):
37+
if cls._instance is None:
38+
cls._instance = AudioCtrl()
39+
return cls._instance
40+
41+
def __init__(self):
42+
self.mixer = alsaaudio.Mixer('PCM', cardindex=1)
43+
#self.mixer = alsaaudio.PCM(device='numid=1', cardindex=1)
44+
45+
def getVolume(self):
46+
print(self.mixer.getvolume())
47+
48+
def setVolume(self,valueVolume):
49+
self.mixer.setvolume(valueVolume)
50+
'''
51+
if __name__ == "__main__":
52+
a = AudioCtrl()
53+
a.setVolume(20)
54+
#a.setVolume(100)'''

coderbot.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"ctrl_hud_image":"",
3636
"load_at_start":"",
3737
"sound_start":"$startup.mp3",
38-
"encoder":"True"
38+
"encoder":"True",
39+
"audio_volume_level":"100"
3940
}

main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from config import Config
3131
from cnn_manager import CNNManager
3232
from event import EventManager
33+
from audioControls import AudioCtrl
3334

3435
# Logging configuration
3536
logger = logging.getLogger()
@@ -59,6 +60,8 @@
5960
app.prog = None
6061
app.shutdown_requested = False
6162

63+
64+
6265
## New API and web application
6366

6467
# API v2 is defined in v2.yml and its methods are in api.py
@@ -155,6 +158,8 @@ def handle_config():
155158
"""
156159
Overwrite configuration file on disk and reload it
157160
"""
161+
audioCtrl = AudioCtrl.get_instance()
162+
audioCtrl.setVolume(int(request.form['audio_volume_level']))
158163
Config.write(updateDict(app.bot_config, request.form))
159164
app.bot_config = Config.get()
160165
return "ok"
@@ -470,6 +475,10 @@ def run_server():
470475
encoder=bool(app.bot_config.get('encoder')))
471476
audio = Audio.get_instance()
472477
audio.say(app.bot_config.get("sound_start"))
478+
479+
audioCtrl = AudioCtrl.get_instance()
480+
audioCtrl.setVolume(int(app.bot_config.get['audio_volume_level']))
481+
473482
try:
474483
cam = Camera.get_instance()
475484
Motion.get_instance()

0 commit comments

Comments
 (0)