msgs for button background leds
This commit is contained in:
parent
74118fbeb7
commit
9a68619293
|
@ -15,13 +15,6 @@ class MessageFwToHost(Enum):
|
||||||
TOUCH_BUTTON_RELEASE = 3
|
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):
|
class TouchButton(Enum):
|
||||||
LEFT_FOOT = 0
|
LEFT_FOOT = 0
|
||||||
RIGHT_FOOT = 1
|
RIGHT_FOOT = 1
|
||||||
|
@ -46,6 +39,9 @@ mouse_led_effect_to_message_id = {
|
||||||
EffectReverseSwipe: 10,
|
EffectReverseSwipe: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PREV_BUTTON_LED_MSG = 20
|
||||||
|
NEXT_BUTTON_LED_MSG = 21
|
||||||
|
|
||||||
|
|
||||||
class RfidTokenRead:
|
class RfidTokenRead:
|
||||||
def __init__(self, id: bytes):
|
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))
|
mouse_led_effect_to_message_id[type(effect_cfg)], len(msg_content))
|
||||||
self.transport.write(header + 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):
|
def data_received(self, data):
|
||||||
self.in_buff += data
|
self.in_buff += data
|
||||||
self._parse_message()
|
self._parse_message()
|
||||||
|
|
|
@ -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):
|
def on_music_end_callback(protocol):
|
||||||
eff = EffectAlexaSwipeConfig()
|
run_off_animation(protocol)
|
||||||
eff.forward = False
|
|
||||||
protocol.led_ring_effect(eff)
|
|
||||||
protocol.mouse_led_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
|
|
||||||
|
|
||||||
|
|
||||||
def on_rfid(protocol, tagid):
|
def on_rfid(protocol, tagid):
|
||||||
|
@ -76,16 +83,11 @@ def on_rfid(protocol, tagid):
|
||||||
if tagid == bytes.fromhex("0000000000"):
|
if tagid == bytes.fromhex("0000000000"):
|
||||||
# Off
|
# Off
|
||||||
if audio_player.is_playing():
|
if audio_player.is_playing():
|
||||||
ring_eff = EffectReverseSwipe()
|
run_off_animation(protocol)
|
||||||
mouse_eff = EffectReverseSwipe()
|
audio_player.pause()
|
||||||
mouse_eff.startPosition = 6 / 45 * 360
|
#else:
|
||||||
else:
|
# protocol.led_ring_effect(EffectStaticConfig(ColorRGBW(0, 0, 0, 0)))
|
||||||
ring_eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0))
|
# protocol.mouse_led_effect(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)
|
|
||||||
audio_player.pause()
|
|
||||||
|
|
||||||
last_figure = current_figure
|
last_figure = current_figure
|
||||||
else:
|
else:
|
||||||
figure = rfid_token_map[tagid]
|
figure = rfid_token_map[tagid]
|
||||||
|
@ -101,8 +103,12 @@ def on_rfid(protocol, tagid):
|
||||||
mouse_eff = EffectStaticConfig(ccfg.background)
|
mouse_eff = EffectStaticConfig(ccfg.background)
|
||||||
mouse_eff = deepcopy(ring_eff)
|
mouse_eff = deepcopy(ring_eff)
|
||||||
mouse_eff.swipe.start_position = 6 / 45 * 360
|
mouse_eff.swipe.start_position = 6 / 45 * 360
|
||||||
|
mouse_eff.swipe.bell_curve_width_in_leds = 16
|
||||||
protocol.mouse_led_effect(mouse_eff)
|
protocol.mouse_led_effect(mouse_eff)
|
||||||
|
|
||||||
|
protocol.button_background_led_prev(0.3)
|
||||||
|
protocol.button_background_led_next(0.3)
|
||||||
|
|
||||||
if figure in playlists:
|
if figure in playlists:
|
||||||
audio_player.set_playlist(playlists[figure])
|
audio_player.set_playlist(playlists[figure])
|
||||||
if last_figure == current_figure:
|
if last_figure == current_figure:
|
||||||
|
|
|
@ -108,6 +108,9 @@ enum class MessageHostToFw : uint8_t
|
||||||
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 8,
|
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 8,
|
||||||
MOUSE_LED_EFFECT_SWIPE_AND_CHANGE = 9,
|
MOUSE_LED_EFFECT_SWIPE_AND_CHANGE = 9,
|
||||||
MOUSE_LED_EFFECT_REVERSE_SWIPE = 10,
|
MOUSE_LED_EFFECT_REVERSE_SWIPE = 10,
|
||||||
|
|
||||||
|
PREV_BUTTON_LED = 20,
|
||||||
|
NEXT_BUTTON_LED = 21,
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -155,7 +158,7 @@ void sendMessageToHost(const TMessage &msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LedTask1, typename LedTask2>
|
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))
|
if (Serial.available() < sizeof(MAGIC_TOKEN_FW_TO_HOST) + sizeof(MessageHostToFw) + sizeof(uint16_t))
|
||||||
return;
|
return;
|
||||||
|
@ -235,6 +238,16 @@ inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *le
|
||||||
auto cfg = reinterpret_cast<EffectReverseSwipeConfig *>(msgBuffer);
|
auto cfg = reinterpret_cast<EffectReverseSwipeConfig *>(msgBuffer);
|
||||||
ledTaskMouse->startEffect(*cfg);
|
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
|
else
|
||||||
Serial.println("Unknown message type");
|
Serial.println("Unknown message type");
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ constexpr int BUTTON_LEFT_PIN = 14;
|
||||||
constexpr int ROTARY_PRESS_PIN = 13;
|
constexpr int ROTARY_PRESS_PIN = 13;
|
||||||
constexpr int BUTTON_RIGHT_LED_PIN = 33;
|
constexpr int BUTTON_RIGHT_LED_PIN = 33;
|
||||||
constexpr int BUTTON_LEFT_LED_PIN = 12;
|
constexpr int BUTTON_LEFT_LED_PIN = 12;
|
||||||
|
constexpr int PWM_FREQ = 5000;
|
||||||
|
constexpr int PWM_RESOLUTION = 8;
|
||||||
|
|
||||||
using ace_button::AceButton;
|
using ace_button::AceButton;
|
||||||
AceButton buttonLeft(BUTTON_LEFT_PIN);
|
AceButton buttonLeft(BUTTON_LEFT_PIN);
|
||||||
|
@ -104,6 +106,12 @@ void setupButtons()
|
||||||
buttonLeft.setEventHandler(handleButtonEvent);
|
buttonLeft.setEventHandler(handleButtonEvent);
|
||||||
buttonRight.setEventHandler(handleButtonEvent);
|
buttonRight.setEventHandler(handleButtonEvent);
|
||||||
buttonRotary.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()
|
void handleButtons()
|
||||||
|
@ -201,7 +209,7 @@ void setup()
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
handleIncomingMessagesFromHost(&ledTaskCircle, &ledTaskMouse);
|
handleIncomingMessagesFromHost(&ledTaskCircle, &ledTaskMouse, 0, 1);
|
||||||
handleTouchInputs();
|
handleTouchInputs();
|
||||||
handleRotaryEncoder();
|
handleRotaryEncoder();
|
||||||
handleButtons();
|
handleButtons();
|
||||||
|
|
Loading…
Reference in New Issue