Reverse swipe
This commit is contained in:
@@ -35,12 +35,15 @@ led_ring_effect_to_message_id = {
|
||||
EffectCircularConfig: 2,
|
||||
EffectRandomTwoColorInterpolationConfig: 3,
|
||||
EffectSwipeAndChange: 4,
|
||||
EffectReverseSwipe: 5,
|
||||
}
|
||||
|
||||
mouse_led_effect_to_message_id = {
|
||||
EffectStaticConfig: 5,
|
||||
EffectCircularConfig: 6,
|
||||
EffectRandomTwoColorInterpolationConfig: 7
|
||||
EffectStaticConfig: 6,
|
||||
EffectCircularConfig: 7,
|
||||
EffectRandomTwoColorInterpolationConfig: 8,
|
||||
EffectSwipeAndChange: 9,
|
||||
EffectReverseSwipe: 10,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class EffectStaticConfig:
|
||||
class EffectAlexaSwipeConfig:
|
||||
primary_color_width: float = 20 # in degrees
|
||||
transition_width: float = 30 # in degrees
|
||||
swipe_speed: float = 3 * 360 # in degrees per second
|
||||
swipe_speed: float = 2 * 360 # in degrees per second
|
||||
bell_curve_width_in_leds: float = 3
|
||||
start_position: float = 180 # in degrees
|
||||
forward: bool = True
|
||||
@@ -124,4 +124,17 @@ class EffectSwipeAndChange:
|
||||
return self.swipe.as_bytes() + self.change.as_bytes()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Swipe and Change: \n {str(self.swipe)}\n {str(self.change)}"
|
||||
return f"Swipe and Change: \n {str(self.swipe)}\n {str(self.change)}"
|
||||
|
||||
|
||||
@dataclass
|
||||
class EffectReverseSwipe:
|
||||
swipeSpeed: float = 2 * 360
|
||||
bellCurveWidthInLeds: float = 3
|
||||
startPosition: float = 180
|
||||
|
||||
def as_bytes(self) -> bytes:
|
||||
return struct.pack("<fff", self.swipeSpeed, self.bellCurveWidthInLeds, self.startPosition)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Reverse swipe, speed {self.swipeSpeed}, width in leds {self.bellCurveWidthInLeds}, start position {self.startPosition}"
|
||||
@@ -2,10 +2,11 @@ import asyncio
|
||||
import serial_asyncio
|
||||
from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig,
|
||||
EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig,
|
||||
EffectSwipeAndChange)
|
||||
EffectSwipeAndChange, EffectReverseSwipe)
|
||||
from host_driver import MusicMouseProtocol, RfidTokenRead, RotaryEncoderEvent, ButtonEvent, TouchButton, TouchButtonPress, TouchButtonRelease
|
||||
from player import AudioPlayer
|
||||
from glob import glob
|
||||
from copy import deepcopy
|
||||
import os
|
||||
|
||||
MUSIC_FOLDER = "/home/martin/code/musicmouse/espmusicmouse/host_driver/music"
|
||||
@@ -75,12 +76,14 @@ def on_rfid(protocol, tagid):
|
||||
if tagid == bytes.fromhex("0000000000"):
|
||||
# Off
|
||||
if audio_player.is_playing():
|
||||
ring_eff = EffectAlexaSwipeConfig()
|
||||
ring_eff.forward = False
|
||||
ring_eff = EffectReverseSwipe()
|
||||
mouse_eff = EffectReverseSwipe()
|
||||
mouse_eff.startPosition = 6 / 45 * 360
|
||||
else:
|
||||
ring_eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0))
|
||||
mouse_eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0))
|
||||
protocol.led_ring_effect(ring_eff)
|
||||
protocol.mouse_led_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
|
||||
protocol.mouse_led_effect(mouse_eff)
|
||||
audio_player.pause()
|
||||
|
||||
last_figure = current_figure
|
||||
@@ -96,6 +99,8 @@ def on_rfid(protocol, tagid):
|
||||
protocol.led_ring_effect(ring_eff)
|
||||
|
||||
mouse_eff = EffectStaticConfig(ccfg.background)
|
||||
mouse_eff = deepcopy(ring_eff)
|
||||
mouse_eff.swipe.start_position = 6 / 45 * 360
|
||||
protocol.mouse_led_effect(mouse_eff)
|
||||
|
||||
if figure in playlists:
|
||||
@@ -127,8 +132,17 @@ def on_firmware_msg(protocol: MusicMouseProtocol, message):
|
||||
*mouse_leds[message.touch_button]))
|
||||
elif isinstance(message, TouchButtonRelease):
|
||||
ccfg = color_cfg[current_figure]
|
||||
color = ccfg.background if audio_player.is_playing() else ColorRGBW(0, 0, 0, 0)
|
||||
protocol.mouse_led_effect(EffectStaticConfig(color, *mouse_leds[message.touch_button]))
|
||||
eff_change = EffectRandomTwoColorInterpolationConfig()
|
||||
eff_static = EffectStaticConfig(ColorRGBW(0, 0, 0, 0), *mouse_leds[message.touch_button])
|
||||
if audio_player.is_playing():
|
||||
eff_static.color = ccfg.primary
|
||||
protocol.mouse_led_effect(eff_static)
|
||||
|
||||
if audio_player.is_playing():
|
||||
eff_change.color1 = ccfg.primary
|
||||
eff_change.color2 = ccfg.secondary
|
||||
eff_change.start_with_existing = True
|
||||
protocol.mouse_led_effect(eff_change)
|
||||
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
Reference in New Issue
Block a user