put volume in stateFile

This commit is contained in:
petrucci4prez 2017-06-24 01:11:44 -04:00
parent d8c897db5c
commit 88a495defa
3 changed files with 11 additions and 4 deletions

View File

@ -1 +1,2 @@
state: disarmed
volume: 100

View File

@ -36,7 +36,7 @@ class KeypadListener:
82: '0'
}
soundLib = stateMachine.soundLib
self._soundLib = soundLib = stateMachine.soundLib
numKeySound = soundLib.soundEffects['numKey']
ctrlKeySound = soundLib.soundEffects['ctrlKey']
@ -56,7 +56,7 @@ class KeypadListener:
else:
self.resetBuffer()
wrongPassSound.play()
def getInput():
while 1:
select([self._dev], [], [])
@ -115,7 +115,7 @@ class KeypadListener:
soundLib.mute()
ctrlKeySound.play()
self._dev.set_led(ecodes.LED_NUML, 0 if soundLib.volume > 0 else 1)
self._setLED()
self._listener = ExceptionThread(target=getInput, daemon=True)
self._clearBuffer()
@ -127,6 +127,7 @@ class KeypadListener:
self._dev = InputDevice(devPath)
self._dev.grab()
self._setLED()
self._listener.start()
logger.debug('Started keypad listener')
@ -159,6 +160,9 @@ class KeypadListener:
def _clearBuffer(self):
self._buf = ''
def _setLED(self):
self._dev.set_led(ecodes.LED_NUML, 0 if self._soundLib.volume > 0 else 1)
def __del__(self):
self.stop()

View File

@ -2,6 +2,7 @@
Implements all sound functionality
'''
import logging, os, hashlib, queue, time, psutil
from config import stateFile
from threading import Event, RLock
from exceptionThreading import ExceptionThread, async
from pygame import mixer
@ -112,7 +113,7 @@ class SoundLib:
self._ttsSounds = TTSCache(psutil.virtual_memory().total * 0.001)
self._lock = RLock()
self.volume = 100
self.volume = stateFile['volume']
self._applyVolumesToSounds(self.volume)
self._ttsQueue = queue.Queue()
@ -174,6 +175,7 @@ class SoundLib:
def _applyVolumesToSounds(self, volume):
with self._lock:
self.volume = volume
stateFile['volume'] = volume
v = volume/100
s = self.soundEffects
for name, sound in s.items():