Firmware cleanup

This commit is contained in:
Martin Bauer
2021-11-27 21:18:54 +01:00
parent 11db5763eb
commit 4fbd7f0f1b
12 changed files with 242 additions and 142 deletions

View File

@@ -2,12 +2,11 @@
#include "effects/Static.h"
#include "effects/AlexaSwipe.h"
#include "effects/RandomTwoColorInterpolation.h"
#include "effects/SwipeAndChange.h"
#include "Arduino.h"
#include <cstdint>
#pragma pack(push, 1)
constexpr uint32_t MAGIC_TOKEN_HOST_TO_FW = 0x1d6379e3;
constexpr uint32_t MAGIC_TOKEN_FW_TO_HOST = 0x10c65631;
@@ -41,7 +40,8 @@ enum class MessageHostToFw : uint8_t
LED_WHEEL_EFFECT_STATIC = 0,
LED_WHEEL_EFFECT_ALEXA_SWIPE = 1,
LED_WHEEL_EFFECT_CIRCULAR = 2,
LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 3
LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION = 3,
LED_WHEEL_EFFECT_SWIPE_AND_CHANGE = 4
};
template <>
@@ -68,7 +68,11 @@ struct ClassToMessageType<EffectRandomTwoColorInterpolationConfig>
static constexpr auto msgType = MessageHostToFw::LED_WHEEL_EFFECT_RANDOM_TWO_COLOR_INTERPOLATION;
};
#pragma pack(pop)
template <>
struct ClassToMessageType<EffectSwipeAndChangeConfig>
{
static constexpr auto msgType = MessageHostToFw::LED_WHEEL_EFFECT_SWIPE_AND_CHANGE;
};
//----------------------------------------------------------------------------------------------------
@@ -111,13 +115,11 @@ inline void handleIncomingMessagesFromHost(LedTask *ledTask)
Serial.readBytes(msgBuffer, msgSize);
if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_STATIC)
{
Serial.println("Static color");
auto cfg = reinterpret_cast<EffectStaticConfig *>(msgBuffer);
ledTask->startEffect(*cfg);
}
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_ALEXA_SWIPE)
{
Serial.println("Alexa swipe");
auto cfg = reinterpret_cast<EffectAlexaSwipeConfig *>(msgBuffer);
ledTask->startEffect(*cfg);
}
@@ -131,6 +133,11 @@ inline void handleIncomingMessagesFromHost(LedTask *ledTask)
auto cfg = reinterpret_cast<EffectRandomTwoColorInterpolationConfig *>(msgBuffer);
ledTask->startEffect(*cfg);
}
else if (msgType == MessageHostToFw::LED_WHEEL_EFFECT_SWIPE_AND_CHANGE)
{
auto cfg = reinterpret_cast<EffectSwipeAndChangeConfig *>(msgBuffer);
ledTask->startEffect(*cfg);
}
else
Serial.println("Unknown message type");
}

View File

@@ -75,10 +75,11 @@ void _led_task_func(void *params)
TLedStrip &ledStrip = *(task->ledStrip_);
// clang-format off
if (dispatchEffectId<EffectId::CIRCULAR >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) { Serial.println("Parsed circular");}
else if (dispatchEffectId<EffectId::STATIC >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) { Serial.println("Parsed static");}
else if (dispatchEffectId<EffectId::ALEXA_SWIPE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) { Serial.println("Alexa swipe");}
else if (dispatchEffectId<EffectId::RANDOM_TWO_COLOR_INTERPOLATION>(id, effectFunction, ledStrip, msgBuffer, effectStorage)) { Serial.println("random color ip");}
if (dispatchEffectId<EffectId::CIRCULAR >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
else if (dispatchEffectId<EffectId::STATIC >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
else if (dispatchEffectId<EffectId::ALEXA_SWIPE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
else if (dispatchEffectId<EffectId::RANDOM_TWO_COLOR_INTERPOLATION>(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
else if (dispatchEffectId<EffectId::SWIPE_AND_CHANGE >(id, effectFunction, ledStrip, msgBuffer, effectStorage)) {}
// clang-format on
timeoutMsForEffect = 0;

View File

@@ -15,111 +15,70 @@
#include "TaskLed.h"
MFRC522 rfid; // Instance of the class
// -------------------------------------------------- RFID Reader ----------------------------------------
MFRC522 rfid;
MFRC522::MIFARE_Key key;
//LedStrip led(46, 23);
LedStripRGBW<51> ledStrip;
Esp32DriverRGBW ledDriver;
LedTask<decltype(ledStrip)> ledTask;
bool fox;
void tag_handler(uint8_t *sn)
void tagHandler(uint8_t *sn)
{
// serial number is always 5 bytes long
if (sn != nullptr)
{
Serial.printf("Tag: %#x %#x %#x %#x %#x\n",
sn[0], sn[1], sn[2], sn[3], sn[4]);
sendMessageToHost(MsgRfidTokenRead{{sn[0], sn[1], sn[2], sn[3], sn[4]}});
if (sn[4] == 0x30)
{
Serial.println("Fuchs");
fox = true;
//ledTask.startEffect(EffectCircularConfig{2 * 360, 180, ColorRGBW{0, 0, 255, 0}});
ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, true, ColorRGBW{0, 255, 0, 0}, ColorRGBW{0, 0, 255, 0}});
delay(1000);
ledTask.startEffect(EffectRandomTwoColorInterpolationConfig{6000, true, 6, false, false, rgb2hsv(ColorRGBW{128, 0, 0, 0}),
rgb2hsv(ColorRGBW{0, 0, 128, 0})});
}
if (sn[4] == 0xf0)
{
Serial.println("Eule");
fox = false;
ledTask.startEffect(EffectCircularConfig{360, 180, ColorRGBW{0, 0, 255, 0}});
}
if (sn[4] == 0xe9)
{
Serial.println("Elephant");
fox = true;
ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, true, ColorRGBW{0, 0, 255, 0}, ColorRGBW{0, 200, 255, 0}});
delay(1000);
ledTask.startEffect(EffectRandomTwoColorInterpolationConfig{6000, true, 3, false, false, rgb2hsv(ColorRGBW{0, 0, 255, 0}),
rgb2hsv(ColorRGBW{0, 200, 255, 0})});
}
}
else
{
Serial.println("Nichts");
if (fox)
{
fox = false;
ledTask.startEffect(EffectAlexaSwipeConfig{20, 30, 3 * 360, 3, 180, false, ColorRGBW{0, 255, 0, 0}, ColorRGBW{0, 0, 255, 0}});
}
else
ledTask.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}});
}
//led.transmit();
sendMessageToHost(MsgRfidTokenRead{{0, 0, 0, 0, 0}});
}
QueueHandle_t event_queue;
rotary_encoder_info_t info;
void setup()
void setupRfidReader()
{
Serial.begin(115200);
//led.begin();
ledDriver.begin(23, 0);
const rc522_start_args_t start_args = {
21, // MISO
5, // MOSI
18, // SCK
19, // SDA
VSPI_HOST,
&tag_handler,
&tagHandler,
125, // scan_interval_ms
8 * 1024, // stacksize
4 // task priority
};
rc522_start(start_args);
}
// -------------------------------------------------- Rotary Enc ----------------------------------------
QueueHandle_t eventQueueRotaryEncoder;
rotary_encoder_info_t info;
void setupRotaryEncoder()
{
ESP_ERROR_CHECK(gpio_install_isr_service(0));
ESP_ERROR_CHECK(rotary_encoder_init(&info, GPIO_NUM_26, GPIO_NUM_27));
ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&info, false));
event_queue = rotary_encoder_create_queue();
ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, event_queue));
//button leds
//pinMode(33, OUTPUT);
//digitalWrite(33, HIGH);
//pinMode(12, OUTPUT);
//digitalWrite(12, HIGH);
//// button in
//pinMode(25, INPUT_PULLUP);
//pinMode(14, INPUT_PULLUP);
//pinMode(13, INPUT_PULLUP);
ledTask.begin(ledStrip, ledDriver);
ledTask.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}});
eventQueueRotaryEncoder = rotary_encoder_create_queue();
ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, eventQueueRotaryEncoder));
}
bool btn2state = true;
// -------------------------------------------------- Led circle ----------------------------------------
LedStripRGBW<51> ledStripCircle;
Esp32DriverRGBW ledDriverCircle;
LedTask<decltype(ledStripCircle)> ledTaskCircle;
void setupLedCircle()
{
ledDriverCircle.begin(23, 0);
ledTaskCircle.begin(ledStripCircle, ledDriverCircle);
ledTaskCircle.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}});
}
//-------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
setupRfidReader();
setupRotaryEncoder();
setupLedCircle();
}
void loop()
{
handleIncomingMessagesFromHost(&ledTask);
handleIncomingMessagesFromHost(&ledTaskCircle);
}