prev/next buttons working
This commit is contained in:
@@ -21,6 +21,7 @@ enum class MessageFwToHost : uint8_t
|
||||
ROTARY_ENCODER = 1,
|
||||
TOUCH_BUTTON_PRESS = 2,
|
||||
TOUCH_BUTTON_RELEASE = 3,
|
||||
BUTTON_EVENT = 4,
|
||||
};
|
||||
|
||||
enum class TouchButton : uint8_t
|
||||
@@ -53,6 +54,12 @@ struct MsgTouchButtonRelease
|
||||
TouchButton button;
|
||||
};
|
||||
|
||||
struct MsgButtonEvent
|
||||
{
|
||||
uint8_t buttonNr;
|
||||
uint8_t eventType;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
template <>
|
||||
@@ -79,6 +86,12 @@ struct ClassToMessageType<MsgTouchButtonRelease>
|
||||
static constexpr auto msgType = MessageFwToHost::TOUCH_BUTTON_RELEASE;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ClassToMessageType<MsgButtonEvent>
|
||||
{
|
||||
static constexpr auto msgType = MessageFwToHost::BUTTON_EVENT;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
enum class MessageHostToFw : uint8_t
|
||||
@@ -87,7 +100,11 @@ enum class MessageHostToFw : uint8_t
|
||||
LED_WHEEL_EFFECT_ALEXA_SWIPE = 1,
|
||||
LED_WHEEL_EFFECT_CIRCULAR = 2,
|
||||
LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 3,
|
||||
LED_WHEEL_EFFECT_SWIPE_AND_CHANGE = 4
|
||||
LED_WHEEL_EFFECT_SWIPE_AND_CHANGE = 4,
|
||||
MOUSE_LED_EFFECT_STATIC = 5,
|
||||
MOUSE_LED_EFFECT_CIRCULAR = 6,
|
||||
MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 7,
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
@@ -134,8 +151,8 @@ void sendMessageToHost(const TMessage &msg)
|
||||
Serial.write((uint8_t *)&msg, sizeof(msg));
|
||||
}
|
||||
|
||||
template <typename LedTask>
|
||||
inline void handleIncomingMessagesFromHost(LedTask *ledTask)
|
||||
template <typename LedTask1, typename LedTask2>
|
||||
inline void handleIncomingMessagesFromHost(LedTask1 *ledTaskCircle, LedTask2 *ledTaskMouse)
|
||||
{
|
||||
if (Serial.available() < sizeof(MAGIC_TOKEN_FW_TO_HOST) + sizeof(MessageHostToFw) + sizeof(uint16_t))
|
||||
return;
|
||||
@@ -162,27 +179,42 @@ inline void handleIncomingMessagesFromHost(LedTask *ledTask)
|
||||
if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_STATIC)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectStaticConfig *>(msgBuffer);
|
||||
ledTask->startEffect(*cfg);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_ALEXA_SWIPE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectAlexaSwipeConfig *>(msgBuffer);
|
||||
ledTask->startEffect(*cfg);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_CIRCULAR)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectCircularConfig *>(msgBuffer);
|
||||
ledTask->startEffect(*cfg);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectRandomTwoColorInterpolationConfig *>(msgBuffer);
|
||||
ledTask->startEffect(*cfg);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_SWIPE_AND_CHANGE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectSwipeAndChangeConfig *>(msgBuffer);
|
||||
ledTask->startEffect(*cfg);
|
||||
ledTaskCircle->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_STATIC)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectStaticConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_CIRCULAR)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectCircularConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else if (msgType == MessageHostToFw::MOUSE_LED_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION)
|
||||
{
|
||||
auto cfg = reinterpret_cast<EffectRandomTwoColorInterpolationConfig *>(msgBuffer);
|
||||
ledTaskMouse->startEffect(*cfg);
|
||||
}
|
||||
else
|
||||
Serial.println("Unknown message type");
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "effects/AlexaSwipe.h"
|
||||
#include "effects/RandomTwoColorInterpolation.h"
|
||||
|
||||
#include "AceButton.h"
|
||||
|
||||
#include "driver/touch_pad.h"
|
||||
|
||||
#include "Messages.h"
|
||||
@@ -67,23 +69,48 @@ void handleRotaryEncoder()
|
||||
|
||||
// -------------------------------------------------- Buttons ----------------------------------------
|
||||
|
||||
constexpr int BUTTON1_PIN = 25;
|
||||
constexpr int BUTTON2_PIN = 14;
|
||||
constexpr int BUTTON_RIGHT_PIN = 25;
|
||||
constexpr int BUTTON_LEFT_PIN = 14;
|
||||
constexpr int ROTARY_PRESS_PIN = 13;
|
||||
constexpr int BUTTON1_LED_PIN = 33;
|
||||
constexpr int BUTTON2_LED_PIN = 12;
|
||||
constexpr int BUTTON_RIGHT_LED_PIN = 33;
|
||||
constexpr int BUTTON_LEFT_LED_PIN = 12;
|
||||
|
||||
using ace_button::AceButton;
|
||||
AceButton buttonLeft(BUTTON_LEFT_PIN);
|
||||
AceButton buttonRight(BUTTON_RIGHT_PIN);
|
||||
AceButton buttonRotary(ROTARY_PRESS_PIN);
|
||||
|
||||
void handleButtonEvent(AceButton *button, uint8_t eventType, uint8_t /*buttonState*/)
|
||||
{
|
||||
uint8_t buttonNr = 0;
|
||||
if (button == &buttonLeft)
|
||||
buttonNr = 1;
|
||||
else if (button == &buttonRight)
|
||||
buttonNr = 2;
|
||||
else if (button == &buttonRotary)
|
||||
buttonNr = 3;
|
||||
sendMessageToHost(MsgButtonEvent{buttonNr, eventType});
|
||||
}
|
||||
|
||||
void setupButtons()
|
||||
{
|
||||
pinMode(BUTTON1_PIN, INPUT_PULLUP);
|
||||
pinMode(BUTTON2_PIN, INPUT_PULLUP);
|
||||
pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP);
|
||||
pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP);
|
||||
pinMode(ROTARY_PRESS_PIN, INPUT_PULLUP);
|
||||
|
||||
pinMode(BUTTON1_LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON2_LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_RIGHT_LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_LEFT_LED_PIN, OUTPUT);
|
||||
|
||||
digitalWrite(BUTTON1_LED_PIN, 1);
|
||||
digitalWrite(BUTTON2_LED_PIN, 1);
|
||||
buttonLeft.setEventHandler(handleButtonEvent);
|
||||
buttonRight.setEventHandler(handleButtonEvent);
|
||||
buttonRotary.setEventHandler(handleButtonEvent);
|
||||
}
|
||||
|
||||
void handleButtons()
|
||||
{
|
||||
buttonLeft.check();
|
||||
buttonRight.check();
|
||||
buttonRotary.check();
|
||||
}
|
||||
|
||||
// -------------------------------------------------- Led circle ------------------------------------------
|
||||
@@ -113,6 +140,7 @@ void setupMouseLeds()
|
||||
}
|
||||
|
||||
// -------------------------------------------------- Touch Buttons ----------------------------------------
|
||||
|
||||
constexpr auto TOUCH_PAD_RIGHT_EAR = TOUCH_PAD_NUM0;
|
||||
constexpr auto TOUCH_PAD_LEFT_EAR = TOUCH_PAD_NUM9;
|
||||
constexpr auto TOUCH_PAD_RIGHT_FOOT = TOUCH_PAD_NUM2;
|
||||
@@ -168,11 +196,13 @@ void setup()
|
||||
setupLedCircle();
|
||||
setupButtons();
|
||||
setupTouchButtons();
|
||||
setupMouseLeds();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleIncomingMessagesFromHost(&ledTaskCircle);
|
||||
handleIncomingMessagesFromHost(&ledTaskCircle, &ledTaskMouse);
|
||||
handleTouchInputs();
|
||||
handleRotaryEncoder();
|
||||
handleButtons();
|
||||
}
|
||||
Reference in New Issue
Block a user