This commit is contained in:
Martin Bauer 2021-12-28 11:42:39 +01:00
parent 59060d6636
commit 32b1c54fbc
2 changed files with 26 additions and 20 deletions

View File

@ -110,6 +110,7 @@ class Controller:
def handle_rfid_event(self, tagid): def handle_rfid_event(self, tagid):
if tagid == bytes.fromhex("0000000000"): if tagid == bytes.fromhex("0000000000"):
if self.audio_player.is_playing(): if self.audio_player.is_playing():
print("Got 000 rfid -> playing off animation")
self._run_off_animation() self._run_off_animation()
self.audio_player.pause() self.audio_player.pause()
self.mmstate.figure_removed() self.mmstate.figure_removed()
@ -142,10 +143,13 @@ class Controller:
elif message.direction == 1: elif message.direction == 1:
self.audio_player.change_volume(-volume_increment) self.audio_player.change_volume(-volume_increment)
elif isinstance(message, ButtonEvent): elif isinstance(message, ButtonEvent):
if message.button == "left" and message.event == "pressed": btn = message.button
self.audio_player.previous() if btn == "left" and message.event == "pressed" and self.audio_player.is_playing():
elif message.button == "right" and message.event == "pressed": res = self.audio_player.previous()
self.audio_player.next() print(f"Prev {res}")
elif btn == "right" and message.event == "pressed" and self.audio_player.is_playing():
res = self.audio_player.nex()
print(f"Next {res}")
elif message.button == "rotary" and message.event == "pressed": elif message.button == "rotary" and message.event == "pressed":
hass_service(self.hass, "light", "toggle", entity_id="light.kinderzimmer_fluter") hass_service(self.hass, "light", "toggle", entity_id="light.kinderzimmer_fluter")
elif isinstance(message, TouchButtonPress): elif isinstance(message, TouchButtonPress):
@ -174,14 +178,6 @@ class Controller:
"turn_on", "turn_on",
entity_id="light.kinderzimmer_fluter", entity_id="light.kinderzimmer_fluter",
**colors[message.touch_button]) **colors[message.touch_button])
#if message.touch_button == TouchButton.RIGHT_FOOT:
# asyncio.create_task(
# self.hass.call_service("switch", "toggle", {"entity_id": "switch.tasmota06"}))
# asyncio.create_task(
# self.hass.call_service("light", "turn_on", {"entity_id": "light.arbeitszimmer_fluter"}))
#elif message.touch_button == TouchButton.LEFT_FOOT:
# asyncio.create_task(
# self.hass.call_service("light", "turn_off", {"entity_id": "light.arbeitszimmer_fluter"}))
elif isinstance(message, TouchButtonRelease): elif isinstance(message, TouchButtonRelease):
figure = self.mmstate.current_figure figure = self.mmstate.current_figure
@ -216,6 +212,7 @@ class Controller:
self.mmstate.mouse_led_effect(mouse_eff) self.mmstate.mouse_led_effect(mouse_eff)
def _run_off_animation(self): def _run_off_animation(self):
print("Running off animation")
ring_eff = EffectReverseSwipe() ring_eff = EffectReverseSwipe()
self.mmstate.led_ring_effect(ring_eff) self.mmstate.led_ring_effect(ring_eff)

View File

@ -77,10 +77,10 @@ class AudioPlayer:
evm = self.media_player.event_manager() evm = self.media_player.event_manager()
evm.event_attach(vlc.EventType.MediaPlayerStopped, self._callback) evm.event_attach(vlc.EventType.MediaPlayerStopped, self._callback)
evm.event_attach(vlc.EventType.MediaListEndReached, self._callback)
evm2 = self.media_list_player.event_manager() evm2 = self.media_list_player.event_manager()
evm2.event_attach(vlc.EventType.MediaListEndReached, self._callback) evm2.event_attach(vlc.EventType.MediaListPlayerPlayed, self._callback)
evm2.event_attach(vlc.EventType.MediaListPlayerStopped, self._callback)
self.on_playlist_end_callback = None self.on_playlist_end_callback = None
@ -91,16 +91,25 @@ class AudioPlayer:
result = vlc.MediaList() result = vlc.MediaList()
for e in files: for e in files:
result.add_media(self.instance.media_new(e)) result.add_media(self.instance.media_new(e))
evm = result.event_manager()
evm.event_attach(vlc.EventType.MediaListEndReached,
lambda e: print("Ml CB", str(vlc.EventType(e.type))))
evm.event_attach(vlc.EventType.MediaListItemAdded,
lambda e: print("Ml ia CB", str(vlc.EventType(e.type))))
return result return result
def set_playlist(self, media_list): def set_playlist(self, media_list):
self.media_list_player.set_media_list(media_list) self.media_list_player.set_media_list(media_list)
print("Setting media list of length ", media_list.count())
self.media_list_player.set_playback_mode(vlc.PlaybackMode.default)
def next(self): def next(self):
self.media_list_player.next() return self.media_list_player.next()
def previous(self): def previous(self):
self.media_list_player.previous() return self.media_list_player.previous()
def play(self): def play(self):
self.media_list_player.play() self.media_list_player.play()
@ -115,10 +124,11 @@ class AudioPlayer:
self.media_list_player.pause() self.media_list_player.pause()
def _callback(self, event, *args, **kwargs): def _callback(self, event, *args, **kwargs):
eventStr = str(vlc.EventType(event.type))
if True: # event.type == vlc.EventType.MediaPlayerEndReached: print(f"Got vlc event type {event.type} {eventStr} , event {event}")
#print("End reached") if event.type == vlc.EventType.MediaPlayerStopped:
if self.on_playlist_end_callback: if self.on_playlist_end_callback:
print("Calling playlist end cb")
self.on_playlist_end_callback() self.on_playlist_end_callback()
#print("Callback from VLC", event, args, kwargs) #print("Callback from VLC", event, args, kwargs)
#print(event.meta_type, event.obj, event.type) #print(event.meta_type, event.obj, event.type)
@ -128,7 +138,6 @@ class AudioPlayer:
volume = self.volume_min volume = self.volume_min
if self.volume_max and volume > self.volume_max: if self.volume_max and volume > self.volume_max:
volume = self.volume_max volume = self.volume_max
print("volume", volume)
self.media_player.audio_set_volume(volume) self.media_player.audio_set_volume(volume)
def set_volume_limits(self, vmin, vmax): def set_volume_limits(self, vmin, vmax):