Skip to content

Commit

Permalink
mpdへの接続を毎回実行することに
Browse files Browse the repository at this point in the history
繋ぎっぱなしだとエラーが多発したため
  • Loading branch information
senyoltw committed Dec 12, 2018
1 parent 3395ec7 commit 9e7d5cc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mpd_powermate.py
Expand Up @@ -29,12 +29,14 @@ def short_press(self):
self._pulsing = not self._pulsing
print(self._pulsing)

client = connectMPD()
if client.status()["state"] == "play":
client.pause()
print('Audio pause!')
else:
client.play()
print('Audio play!')
client.close()

if self._pulsing:
return LedEvent.pulse()
Expand All @@ -49,18 +51,22 @@ def rotate(self, rotation):
self._brightness = max(0, min(MAX_BRIGHTNESS, self._brightness + rotation))
self._pulsing = False

client = connectMPD()
cur_vol = int(client.status()["volume"])
client.setvol(cur_vol + rotation)
client.close()

return LedEvent(brightness=self._brightness)

def push_rotate(self, rotation):
print('Push rotate {}!'.format(rotation))

client = connectMPD()
if rotation == 1:
client.next()
else:
client.previous()
client.close()
sleep(0.5)

if __name__ == '__main__':
Expand All @@ -69,10 +75,9 @@ def push_rotate(self, rotation):
while not client:
client = connectMPD()
if not client:
time.sleep(2)
sleep(2)

print 'Ready: Powermate controler'

pm = ExamplePowerMate(glob.glob('/dev/input/by-id/*PowerMate*')[0])
pm.run()
client.close()

0 comments on commit 9e7d5cc

Please sign in to comment.