msgs for button background leds

This commit is contained in:
Martin Bauer 2021-12-20 21:32:05 +01:00
parent 74118fbeb7
commit 9a68619293
4 changed files with 56 additions and 23 deletions

View File

@ -15,13 +15,6 @@ class MessageFwToHost(Enum):
TOUCH_BUTTON_RELEASE = 3
class MessageHostToFw(Enum):
LED_WHEEL_EFFECT_STATIC = 0
LED_WHEEL_EFFECT_ALEXA_SWIPE = 1
LED_WHEEL_EFFECT_CIRCULAR = 2
LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 3
class TouchButton(Enum):
LEFT_FOOT = 0
RIGHT_FOOT = 1
@ -46,6 +39,9 @@ mouse_led_effect_to_message_id = {
EffectReverseSwipe: 10,
}
PREV_BUTTON_LED_MSG = 20
NEXT_BUTTON_LED_MSG = 21
class RfidTokenRead:
def __init__(self, id: bytes):
@ -135,6 +131,16 @@ class MusicMouseProtocol(asyncio.Protocol):
mouse_led_effect_to_message_id[type(effect_cfg)], len(msg_content))
self.transport.write(header + msg_content)
def button_background_led_prev(self, val):
msg_content = struct.pack("<f", val)
header = struct.pack("<IBH", MAGIC_TOKEN_HOST_TO_FW, PREV_BUTTON_LED_MSG, len(msg_content))
self.transport.write(header + msg_content)
def button_background_led_next(self, val):
msg_content = struct.pack("<f", val)
header = struct.pack("<IBH", MAGIC_TOKEN_HOST_TO_FW, NEXT_BUTTON_LED_MSG, len(msg_content))
self.transport.write(header + msg_content)
def data_received(self, data):
self.in_buff += data
self._parse_message()

View File

@ -63,11 +63,18 @@ mouse_leds = {
}
def run_off_animation(protocol):
ring_eff = EffectReverseSwipe()
mouse_eff = EffectReverseSwipe()
mouse_eff.startPosition = 6 / 45 * 360
protocol.led_ring_effect(ring_eff)
protocol.mouse_led_effect(mouse_eff)
protocol.button_background_led_prev(0)
protocol.button_background_led_next(0)
def on_music_end_callback(protocol):
eff = EffectAlexaSwipeConfig()
eff.forward = False
protocol.led_ring_effect(eff)
protocol.mouse_led_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
run_off_animation(protocol)
def on_rfid(protocol, tagid):
@ -76,16 +83,11 @@ def on_rfid(protocol, tagid):
if tagid == bytes.fromhex("0000000000"):
# Off
if audio_player.is_playing():
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(mouse_eff)
run_off_animation(protocol)
audio_player.pause()
#else:
# protocol.led_ring_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
# protocol.mouse_led_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
last_figure = current_figure
else:
figure = rfid_token_map[tagid]
@ -101,8 +103,12 @@ def on_rfid(protocol, tagid):
mouse_eff = EffectStaticConfig(ccfg.background)
mouse_eff = deepcopy(ring_eff)
mouse_eff.swipe.start_position = 6 / 45 * 360
mouse_eff.swipe.bell_curve_width_in_leds = 16
protocol.mouse_led_effect(mouse_eff)
protocol.button_background_led_prev(0.3)
protocol.button_background_led_next(0.3)
if figure in playlists:
audio_player.set_playlist(playlists[figure])
if last_figure == current_figure:

View File

@ -108,6 +108,9 @@ enum class MessageHostToFw : uint8_t
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 8,
MOUSE_LED_EFFECT_SWIPE_AND_CHANGE = 9,
MOUSE_LED_EFFECT_REVERSE_SWIPE = 10,
PREV_BUTTON_LED = 20,
NEXT_BUTTON_LED = 21,
};
template <>
@ -155,7 +158,7 @@ void sendMessageToHost(const TMessage &msg)
}
template <typename LedTask1, typename LedTask2>
inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *ledTaskMouse)
inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *ledTaskMouse, uint8_t ledChannelLeft, uint8_t ledChannelRight)
{
if (Serial.available() < sizeof(MAGIC_TOKEN_FW_TO_HOST) + sizeof(MessageHostToFw) + sizeof(uint16_t))
return;
@ -235,6 +238,16 @@ inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *le
auto cfg = reinterpret_cast<EffectReverseSwipeConfig *>(msgBuffer);
ledTaskMouse->startEffect(*cfg);
}
else if (msgType == MessageHostToFw::PREV_BUTTON_LED)
{
float *val = reinterpret_cast<float *>(msgBuffer);
ledcWrite(ledChannelLeft, uint32_t(255 * (*val)));
}
else if (msgType == MessageHostToFw::NEXT_BUTTON_LED)
{
float *val = reinterpret_cast<float *>(msgBuffer);
ledcWrite(ledChannelRight, uint32_t(255 * (*val)));
}
else
Serial.println("Unknown message type");
}

View File

@ -74,6 +74,8 @@ constexpr int BUTTON_LEFT_PIN = 14;
constexpr int ROTARY_PRESS_PIN = 13;
constexpr int BUTTON_RIGHT_LED_PIN = 33;
constexpr int BUTTON_LEFT_LED_PIN = 12;
constexpr int PWM_FREQ = 5000;
constexpr int PWM_RESOLUTION = 8;
using ace_button::AceButton;
AceButton buttonLeft(BUTTON_LEFT_PIN);
@ -104,6 +106,12 @@ void setupButtons()
buttonLeft.setEventHandler(handleButtonEvent);
buttonRight.setEventHandler(handleButtonEvent);
buttonRotary.setEventHandler(handleButtonEvent);
ledcSetup(0, PWM_FREQ, PWM_RESOLUTION);
ledcAttachPin(BUTTON_LEFT_LED_PIN, 0);
ledcSetup(1, PWM_FREQ, PWM_RESOLUTION);
ledcAttachPin(BUTTON_RIGHT_LED_PIN, 1);
}
void handleButtons()
@ -201,7 +209,7 @@ void setup()
void loop()
{
handleIncomingMessagesFromHost(&ledTaskCircle, &ledTaskMouse);
handleIncomingMessagesFromHost(&ledTaskCircle, &ledTaskMouse, 0, 1);
handleTouchInputs();
handleRotaryEncoder();
handleButtons();