|
|
|
@ -2,11 +2,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import glob |
|
|
|
import glob |
|
|
|
|
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
from lib.powermate import powermate |
|
|
|
from lib.powermate import powermate |
|
|
|
from lib.python_pulse_control.pulsectl import pulsectl |
|
|
|
from lib.python_pulse_control.pulsectl import pulsectl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RETRY_ATTEMPTS = 10 |
|
|
|
INCREASE_AMOUNT = 0.01 |
|
|
|
INCREASE_AMOUNT = 0.01 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -17,8 +19,6 @@ class PowerMate(powermate.PowerMateBase): |
|
|
|
super().__init__(path) |
|
|
|
super().__init__(path) |
|
|
|
|
|
|
|
|
|
|
|
def rotate(self, rotation): |
|
|
|
def rotate(self, rotation): |
|
|
|
#print(rotation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rotation > 0): |
|
|
|
if (rotation > 0): |
|
|
|
self.change_vol(INCREASE_AMOUNT) |
|
|
|
self.change_vol(INCREASE_AMOUNT) |
|
|
|
else: |
|
|
|
else: |
|
|
|
@ -26,10 +26,36 @@ class PowerMate(powermate.PowerMateBase): |
|
|
|
|
|
|
|
|
|
|
|
def change_vol(self, vol): |
|
|
|
def change_vol(self, vol): |
|
|
|
for sink in self.pulse.sink_list(): |
|
|
|
for sink in self.pulse.sink_list(): |
|
|
|
#print(sink) |
|
|
|
|
|
|
|
self.pulse.volume_change_all_chans(sink, vol) |
|
|
|
self.pulse.volume_change_all_chans(sink, vol) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start(): |
|
|
|
|
|
|
|
for i in range(1, RETRY_ATTEMPTS + 1): |
|
|
|
|
|
|
|
path = '' |
|
|
|
|
|
|
|
powermates = glob.glob('/dev/input/by-id/*PowerMate*') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(powermates) > 0 : |
|
|
|
|
|
|
|
path = powermates[0] |
|
|
|
|
|
|
|
print(f'found powermate at {path}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if path: |
|
|
|
|
|
|
|
pm = PowerMate(path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
pm.run() |
|
|
|
|
|
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
print(f'caught exception from AsyncFileEventDispatcher.run(): {e}') |
|
|
|
|
|
|
|
print('attempting restart') |
|
|
|
|
|
|
|
time.sleep(5) # NOTE: give time to enumerate USB after suspend |
|
|
|
|
|
|
|
start() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
elif i == 1: |
|
|
|
|
|
|
|
print(f'waiting up to {RETRY_ATTEMPTS}s for powermate') |
|
|
|
|
|
|
|
elif i == RETRY_ATTEMPTS: |
|
|
|
|
|
|
|
print(f'giving up looking for powermate after {RETRY_ATTEMPTS}s') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
pm = PowerMate(glob.glob('/dev/input/by-id/*PowerMate*')[0]) |
|
|
|
start() |
|
|
|
pm.run() |
|
|
|
|
|
|
|
|