From 1c406f8b4ebf825d37123420275dc89b42886663 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Wed, 15 Dec 2021 23:14:59 +0100 Subject: [PATCH] volume control --- espmusicmouse/host_driver/main.py | 19 +++++++++++++++---- espmusicmouse/host_driver/player.py | 9 +++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/espmusicmouse/host_driver/main.py b/espmusicmouse/host_driver/main.py index f4ab814..1d149ca 100644 --- a/espmusicmouse/host_driver/main.py +++ b/espmusicmouse/host_driver/main.py @@ -3,7 +3,7 @@ import serial_asyncio from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig, EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig, EffectSwipeAndChange) -from host_driver import MusicMouseProtocol, RfidTokenRead +from host_driver import MusicMouseProtocol, RfidTokenRead, RotaryEncoderEvent from player import AudioPlayer from glob import glob import os @@ -16,6 +16,9 @@ rfid_token_map = { bytes.fromhex("88041174e9"): "elefant", bytes.fromhex("8804ce7230"): "fuchs", bytes.fromhex("88040d71f0"): "eule", + bytes.fromhex("88043c6ede"): "omnom", + bytes.fromhex("88040b78ff"): "eichhoernchen", + bytes.fromhex("8804bc7444"): "hund", } playlists = { @@ -52,7 +55,7 @@ def on_firmware_msg(protocol, message): eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0)) protocol.send_message(eff) audio_player.pause() - if isinstance(message, RfidTokenRead) and message.id in rfid_token_map: + elif isinstance(message, RfidTokenRead) and message.id in rfid_token_map: eff = EffectSwipeAndChange() eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0) figure = rfid_token_map[message.id] @@ -64,8 +67,16 @@ def on_firmware_msg(protocol, message): eff.swipe.bell_curve_width_in_leds = 6 protocol.send_message(eff) - audio_player.set_playlist(playlists[figure]) - audio_player.play_from_start() + print(figure) + if figure in playlists: + audio_player.set_playlist(playlists[figure]) + audio_player.play_from_start() + elif isinstance(message, RotaryEncoderEvent): + if audio_player.is_playing(): + if message.direction == 2: + audio_player.change_volume(2) + elif message.direction == 1: + audio_player.change_volume(-2) loop = asyncio.get_event_loop() diff --git a/espmusicmouse/host_driver/player.py b/espmusicmouse/host_driver/player.py index 12a7f4b..c8db800 100644 --- a/espmusicmouse/host_driver/player.py +++ b/espmusicmouse/host_driver/player.py @@ -113,3 +113,12 @@ class AudioPlayer: self.on_playlist_end_callback() #print("Callback from VLC", event, args, kwargs) #print(event.meta_type, event.obj, event.type) + + def change_volume(self, amount=1): + vol = self.media_player.audio_get_volume() + amount + print("volume", vol) + if vol > 100: + vol = 100 + if vol < 0: + vol = 0 + self.media_player.audio_set_volume(vol)