Skip to content

Commit 50fb0c4

Browse files
MicheleCarboneraMicheleCarbonera
authored andcommitted
Set volume at save and init.
1 parent e28761c commit 50fb0c4

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
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)'''

main.py

Lines changed: 4 additions & 2 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()
@@ -41,7 +42,8 @@
4142
fh.setFormatter(formatter)
4243
#logger.addHandler(sh)
4344
logger.addHandler(fh)
44-
45+
##audioext
46+
audioCtrl = AudioCtrl.get_instance()
4547

4648
## (Connexion) Flask app configuration
4749

@@ -157,7 +159,7 @@ def handle_config():
157159
"""
158160
Overwrite configuration file on disk and reload it
159161
"""
160-
print(request.form)
162+
audioCtrl.setVolume(int(request.form['audio_volume_level']))
161163
Config.write(updateDict(app.bot_config, request.form))
162164
app.bot_config = Config.get()
163165
return "ok"

0 commit comments

Comments
 (0)