Skip to content

Commit

Permalink
adjust volume
Browse files Browse the repository at this point in the history
  • Loading branch information
isra67 committed Feb 1, 2017
1 parent 7c96c3b commit 0b86dab
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 16 deletions.
4 changes: 2 additions & 2 deletions indoor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sip_p4ssw0rd =
[devices]
sound_device_in =
sound_device_out =
volume = 25
volume = 40

[gui]
btn_call_hangup = HangUp Call
Expand Down Expand Up @@ -49,5 +49,5 @@ inet = dhcp
serial = 0000000066c8dcbe
app_name = Indoor 2.0
app_ver = 2.0.0.0
uptime = 17:24:52.490000
uptime = 21:17:15.730000

4 changes: 2 additions & 2 deletions indoor.kv
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
text: 'C'
font_size: '24dp'
size_hint: .25, 1
on_press: root.callback_set_voice(1)
on_press: root.callback_set_voice(-1)
Button:
id: btnDoor1
text: 'Open Door 1'
Expand All @@ -102,7 +102,7 @@
text: 'S'
font_size: '24dp'
size_hint: .25, 1
on_press: root.callback_set_voice(-1)
on_press: root.callback_set_voice(1)

SetScreen:
name: 'settings'
Expand Down
2 changes: 1 addition & 1 deletion my_lib/settingsjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
'desc': 'Choose for the audio volume value [%]',
'section': 'devices',
'key': 'volume',
'options': ['-100', '-66', '-33', '0', '33', '66', '100']}
'options': ['20', '40', '60', '80', '100']}
])

# SIP settings
Expand Down
73 changes: 62 additions & 11 deletions pjindoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@
BACK_LIGHT = False
BRIGHTNESS = 100
WATCHES = 'analog'
AUDIO_VOLUME = 100

DBUSCONTROL_SCRIPT = './dbuscntrl.sh'
BACK_LIGHT_SCRIPT = './backlight.sh'
UNBLANK_SCRIPT = './unblank.sh'
BRIGHTNESS_SCRIPT = './brightness.sh'
SYSTEMINFO_SCRIPT = './sysinfo.sh'
VOLUMEINFO_SCRIPT = './volumeinfo.sh'
SETVOLUME_SCRIPT = './setvolume.sh'

BUTTON_CALL_ANSWER = '=Answer Call='
BUTTON_CALL_HANGUP = '=HangUp Call='
Expand Down Expand Up @@ -315,7 +318,7 @@ def on_state(self):
current_call = self.call
docall_button_global.color = COLOR_HANGUP_CALL
docall_button_global.text = BUTTON_CALL_HANGUP
mainLayout.findTargetWindow('') #self.call.info().remote_uri)
mainLayout.findTargetWindow('')


def on_media_state(self):
Expand All @@ -325,9 +328,9 @@ def on_media_state(self):
call_slot = self.call.info().conf_slot
pj.Lib.instance().conf_connect(call_slot, 0)
pj.Lib.instance().conf_connect(0, call_slot)
# print "Media is now active"
# else:
# print "Media is inactive"
print "Media is now active"
else:
print "Media is inactive"


def make_call(uri):
Expand Down Expand Up @@ -738,6 +741,7 @@ def callback_btn_door2(self):
def callback_set_options(self):
"start settings"
global procs

self.dbg(self.ids.btnSetOptions.text)
print whoami()

Expand All @@ -750,14 +754,31 @@ def callback_set_options(self):

def callback_set_voice(self, value):
"volume buttons"
if self.ids.btnScreenClock.text == 'C':
if value == -1:
global AUDIO_VOLUME, current_call

self.dbg(whoami() + ': ' + str(value) + self.ids.btnScreenClock.text)

if current_call is None:
# if self.ids.btnScreenClock.text == 'C':
if value == 1:
self.callback_set_options()
else:
Clock.schedule_once(self.return2clock, .2)
# get_info(DBUSCONTROL_SCRIPT + ' ' + DBUS_PLAYERNAME + str(active_display_index) + ' status')
else :
self.dbg('Voice: ' + str(value))
vol = AUDIO_VOLUME + int(value) * 20
if vol > 80: vol = 100
elif vol > 60: vol = 80
elif vol > 40: vol = 60
elif vol > 20: vol = 40
else: vol = 20
AUDIO_VOLUME = vol

self.ids.btnScreenClock.disabled = vol < 40
self.ids.btnSetOptions.disabled = vol > 80

self.dbg('Voice: ' + str(value) + ' >> '+ str(AUDIO_VOLUME))
send_command(SETVOLUME_SCRIPT + ' ' + str(AUDIO_VOLUME))


def on_touch_up(self, touch):
Expand Down Expand Up @@ -816,14 +837,20 @@ def hidePlayers(self):

def setButtons(self, visible):
"set buttons (ScrSaver, Options, Voice+-) to accurate state"
global AUDIO_VOLUME

self.dbg(whoami())

if visible:
self.ids.btnScreenClock.text = '+'
self.ids.btnSetOptions.text = '-'
self.ids.btnScreenClock.text = '-'
self.ids.btnSetOptions.text = '+'
self.ids.btnScreenClock.disabled = AUDIO_VOLUME < 40
self.ids.btnSetOptions.disabled = AUDIO_VOLUME > 80
else:
self.ids.btnScreenClock.text = 'C'
self.ids.btnSetOptions.text = 'S'
self.ids.btnScreenClock.disabled = False
self.ids.btnSetOptions.disabled = False


def findTargetWindow(self, addr):
Expand Down Expand Up @@ -865,6 +892,7 @@ def build(self):
self.use_kivy_settings = False

self.changeInet = False
self.get_volume_value()

return Indoor()

Expand Down Expand Up @@ -900,7 +928,7 @@ def build_config(self, config):
config.setdefaults('devices', {
'sound_device_in': '',
'sound_device_out': '',
'volume': 0 })
'volume': 100 })
config.setdefaults('gui', {
'screen_mode': 0,
'btn_call_none': '',
Expand Down Expand Up @@ -945,6 +973,25 @@ def get_uptime_value(self):
return uptime_string


def get_volume_value(self):
"retrieve current volume level"
global AUDIO_VOLUME

s = get_info(VOLUMEINFO_SCRIPT).split()
vol = int(round(float(s[1]) / (int(s[3]) - int(s[2])) * 100.0))

# available volume steps:
if vol > 80: vol = 100
elif vol > 60: vol = 80
elif vol > 40: vol = 60
elif vol > 20: vol = 40
else: vol = 20
AUDIO_VOLUME = vol
print s, vol

return vol


def build_settings(self, settings):
"display settings screen"
global config
Expand All @@ -963,6 +1010,7 @@ def build_settings(self, settings):
config.set('system', 'dns', s[8])

config.set('about', 'uptime', self.get_uptime_value())
config.set('devices', 'volume', AUDIO_VOLUME)

# enable|disable change parameters
vDhcp = config.get('system', 'inet') in 'dhcp'
Expand Down Expand Up @@ -1000,7 +1048,7 @@ def build_settings(self, settings):

def on_config_change(self, config, section, key, value):
"config item changed"
global SCREEN_SAVER, BACK_LIGHT, BRIGHTNESS, WATCHES
global SCREEN_SAVER, BACK_LIGHT, BRIGHTNESS, WATCHES, VOLUME

token = (section, key)
print whoami(),':', section, key, value
Expand All @@ -1027,6 +1075,9 @@ def on_config_change(self, config, section, key, value):
elif token == ('command', 'watches'):
if value in 'analog': WATCHES = value
else: WATCHES = 'digital'
elif token == ('devices', 'volume'):
AUDIO_VOLUME = value
send_command(SETVOLUME_SCRIPT + ' ' + str(AUDIO_VOLUME))
elif section in 'system' and (key in ['ipaddress', 'netmask', 'broadcast', 'gateway', 'network', 'dns']):
if config.get('system', 'inet') in 'dhcp':
print 'disable changes', config.get(section, key), self.config.get(section, key)
Expand Down
4 changes: 4 additions & 0 deletions setvolume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash
VOLUMEID=`amixer controls | grep "PCM Playback Volume" | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}' | sed 's/numid=//'`

amixer cset numid=$VOLUMEID $1%
6 changes: 6 additions & 0 deletions volumeinfo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash
VOLUMEID=`amixer controls | grep "PCM Playback Volume" | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}' | sed 's/numid=//'`
VOLUMEVAL=`amixer cget numid=$VOLUMEID | grep ": values" | sed 's/ : values=//' | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}'`
MINVAL=`amixer cget numid=$VOLUMEID | grep "access" | sed -e 's/,/\n/g' | awk 'NR==4 {print $1}' | sed 's/min=//'`
MAXVAL=`amixer cget numid=$VOLUMEID | grep "access" | sed -e 's/,/\n/g' | awk 'NR==5 {print $1}' | sed 's/max=//'`
echo $VOLUMEID $VOLUMEVAL $MINVAL $MAXVAL

0 comments on commit 0b86dab

Please sign in to comment.