put volume in stateFile
This commit is contained in:
parent
d8c897db5c
commit
88a495defa
|
@ -1 +1,2 @@
|
||||||
state: disarmed
|
state: disarmed
|
||||||
|
volume: 100
|
||||||
|
|
10
listeners.py
10
listeners.py
|
@ -36,7 +36,7 @@ class KeypadListener:
|
||||||
82: '0'
|
82: '0'
|
||||||
}
|
}
|
||||||
|
|
||||||
soundLib = stateMachine.soundLib
|
self._soundLib = soundLib = stateMachine.soundLib
|
||||||
|
|
||||||
numKeySound = soundLib.soundEffects['numKey']
|
numKeySound = soundLib.soundEffects['numKey']
|
||||||
ctrlKeySound = soundLib.soundEffects['ctrlKey']
|
ctrlKeySound = soundLib.soundEffects['ctrlKey']
|
||||||
|
@ -56,7 +56,7 @@ class KeypadListener:
|
||||||
else:
|
else:
|
||||||
self.resetBuffer()
|
self.resetBuffer()
|
||||||
wrongPassSound.play()
|
wrongPassSound.play()
|
||||||
|
|
||||||
def getInput():
|
def getInput():
|
||||||
while 1:
|
while 1:
|
||||||
select([self._dev], [], [])
|
select([self._dev], [], [])
|
||||||
|
@ -115,7 +115,7 @@ class KeypadListener:
|
||||||
soundLib.mute()
|
soundLib.mute()
|
||||||
|
|
||||||
ctrlKeySound.play()
|
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._listener = ExceptionThread(target=getInput, daemon=True)
|
||||||
self._clearBuffer()
|
self._clearBuffer()
|
||||||
|
@ -127,6 +127,7 @@ class KeypadListener:
|
||||||
|
|
||||||
self._dev = InputDevice(devPath)
|
self._dev = InputDevice(devPath)
|
||||||
self._dev.grab()
|
self._dev.grab()
|
||||||
|
self._setLED()
|
||||||
|
|
||||||
self._listener.start()
|
self._listener.start()
|
||||||
logger.debug('Started keypad listener')
|
logger.debug('Started keypad listener')
|
||||||
|
@ -159,6 +160,9 @@ class KeypadListener:
|
||||||
def _clearBuffer(self):
|
def _clearBuffer(self):
|
||||||
self._buf = ''
|
self._buf = ''
|
||||||
|
|
||||||
|
def _setLED(self):
|
||||||
|
self._dev.set_led(ecodes.LED_NUML, 0 if self._soundLib.volume > 0 else 1)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
Implements all sound functionality
|
Implements all sound functionality
|
||||||
'''
|
'''
|
||||||
import logging, os, hashlib, queue, time, psutil
|
import logging, os, hashlib, queue, time, psutil
|
||||||
|
from config import stateFile
|
||||||
from threading import Event, RLock
|
from threading import Event, RLock
|
||||||
from exceptionThreading import ExceptionThread, async
|
from exceptionThreading import ExceptionThread, async
|
||||||
from pygame import mixer
|
from pygame import mixer
|
||||||
|
@ -112,7 +113,7 @@ class SoundLib:
|
||||||
self._ttsSounds = TTSCache(psutil.virtual_memory().total * 0.001)
|
self._ttsSounds = TTSCache(psutil.virtual_memory().total * 0.001)
|
||||||
self._lock = RLock()
|
self._lock = RLock()
|
||||||
|
|
||||||
self.volume = 100
|
self.volume = stateFile['volume']
|
||||||
self._applyVolumesToSounds(self.volume)
|
self._applyVolumesToSounds(self.volume)
|
||||||
|
|
||||||
self._ttsQueue = queue.Queue()
|
self._ttsQueue = queue.Queue()
|
||||||
|
@ -174,6 +175,7 @@ class SoundLib:
|
||||||
def _applyVolumesToSounds(self, volume):
|
def _applyVolumesToSounds(self, volume):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self.volume = volume
|
self.volume = volume
|
||||||
|
stateFile['volume'] = volume
|
||||||
v = volume/100
|
v = volume/100
|
||||||
s = self.soundEffects
|
s = self.soundEffects
|
||||||
for name, sound in s.items():
|
for name, sound in s.items():
|
||||||
|
|
Loading…
Reference in New Issue