diff --git a/libESTA/fixture/AbstractRGB.cpp b/libESTA/fixture/AbstractRGB.cpp new file mode 100644 index 0000000..9cf36d5 --- /dev/null +++ b/libESTA/fixture/AbstractRGB.cpp @@ -0,0 +1,45 @@ +/* + AbstractRGBA.cpp + + Part of WiFlash_esp32 + + Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "AbstractRGB.h" + +/* + Constructor +*/ +AbstractRGB::AbstractRGB (uint16_t address) + : AbstractFixture(address) +{ +} + +/* + Load data into profile from new DMX +*/ +void AbstractRGB::recvData(DMX::Universe * univ) { + // copy data from universe to profile + std::copy(univ->data()->begin() + address_, + univ->data()->begin() + address_ + sizeof(profile_.dmx), + std::begin(profile_.dmx)); +} diff --git a/libESTA/fixture/AbstractRGB.h b/libESTA/fixture/AbstractRGB.h new file mode 100644 index 0000000..00d448a --- /dev/null +++ b/libESTA/fixture/AbstractRGB.h @@ -0,0 +1,55 @@ +/* + AbstractRGBA.h + + Part of WiFlash_esp32 + + Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#pragma once + +#include +#include "AbstractFixture.h" +#include "../dmx/universe.h" + +using std::uint8_t; +using std::uint16_t; + +union profile_RGB { + uint8_t dmx[3]; + struct { + uint8_t red; + uint8_t green; + uint8_t blue; + } __attribute__((packed)); +}; + +class AbstractRGB + : public AbstractFixture +{ +public: + AbstractRGB(uint16_t address); + + const profile_RGB * profile() {return &profile_;}; + virtual void recvData(DMX::Universe *); // data recieved callback + +protected: + profile_RGB profile_; // dmx data +}; diff --git a/libESTA/fixture/AbstractRgbStrip.cpp b/libESTA/fixture/AbstractRgbStrip.cpp new file mode 100644 index 0000000..40ca322 --- /dev/null +++ b/libESTA/fixture/AbstractRgbStrip.cpp @@ -0,0 +1,43 @@ +/* + AbstractRgbaStrip.cpp + + Part of WiFlash_esp32 + + Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "AbstractRgbStrip.h" + +/* + Constructor +*/ +AbstractRgbStrip::AbstractRgbStrip (uint16_t address, uint8_t pxl_count) + : AbstractFixture(address) +{ + for (int p = 0; p < pxl_count; p++) + pixels_.push_back(new AbstractRGB(address + (p * sizeof(profile_RGB)))); +} + +/* + Load data into profile from new DMX +*/ +void AbstractRgbStrip::recvData(DMX::Universe * univ) { +} diff --git a/libESTA/fixture/AbstractRgbStrip.h b/libESTA/fixture/AbstractRgbStrip.h new file mode 100644 index 0000000..d19ce11 --- /dev/null +++ b/libESTA/fixture/AbstractRgbStrip.h @@ -0,0 +1,45 @@ +/* + AbstractRgbaStrip.h + + Part of WiFlash_esp32 + + Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#pragma once + +#include "AbstractFixture.h" +#include "AbstractRGB.h" +#include "../dmx/universe.h" +#include + +using std::vector; + +class AbstractRgbStrip + : public AbstractFixture +{ +public: + AbstractRgbStrip(uint16_t address, uint8_t pxl_count); + + virtual void recvData(DMX::Universe *); // data recieved callback + +protected: + vector pixels_; +}; diff --git a/libESTA/fixture/EspRgbStrip.cpp b/libESTA/fixture/EspRgbStrip.cpp new file mode 100644 index 0000000..cec077b --- /dev/null +++ b/libESTA/fixture/EspRgbStrip.cpp @@ -0,0 +1,52 @@ +/* + EspRgbaStrip.cpp + + Part of WiFlash_esp32 + + Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "EspRgbStrip.h" + +EspRgbStrip::EspRgbStrip(uint16_t address, uint16_t pxl_count) + : AbstractRgbStrip(address, pxl_count) +{ + +} + +bool EspRgbStrip::begin(uint8_t pin) { + strip_ = new NeoPixelBus(pixels_.size(), pin); + strip_->Begin(); + strip_->Show(); + return true; +} + +/* + Load data into profile from new DMX +*/ +void EspRgbStrip::recvData(DMX::Universe * univ) { + for (int i = 0; i < pixels_.size(); i++) { + pixels_[i]->recvData(univ); + const profile_RGB * profile = pixels_[i]->profile(); + strip_->SetPixelColor(i, RgbColor(profile->red, profile->green, profile->blue)); + } + strip_->Show(); +} diff --git a/libESTA/fixture/EspRgbStrip.h b/libESTA/fixture/EspRgbStrip.h new file mode 100644 index 0000000..b6ac89a --- /dev/null +++ b/libESTA/fixture/EspRgbStrip.h @@ -0,0 +1,45 @@ +/* + EspRgbaStrip.h + + Part of WiFlash_esp32 + + Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include "AbstractRgbStrip.h" +#include + + +class EspRgbStrip + : public AbstractRgbStrip +{ +public: + EspRgbStrip(uint16_t address, uint16_t pxl_count); + + virtual bool begin(uint8_t); // call in setup() + virtual void recvData(DMX::Universe *); // data recieved callback + +private: + NeoPixelBus * strip_; + +}; diff --git a/wiflash_esp32/wiflash_esp32.ino b/wiflash_esp32/wiflash_esp32.ino index c497396..64f37a8 100644 --- a/wiflash_esp32/wiflash_esp32.ino +++ b/wiflash_esp32/wiflash_esp32.ino @@ -36,6 +36,7 @@ #include "src/wiflash_status.h" #include "src/lib/libESTA/sacn/receiver-esp.h" #include "src/lib/libESTA/fixture/EspStrobe.h" +#include "src/lib/libESTA/fixture/EspRgbStrip.h" #include "src/lib/libESTA/fixture/EspRgbaStrip.h" // ESP logging module @@ -45,7 +46,8 @@ static const char* TAG = "WiFlash"; //// device objects EspStrobe * strobe; -EspRgbaStrip * strip; +EspRgbStrip * strip; +//EspRgbaStrip * strip; auto *e131 = new SACN::EspReceiver(); auto *httpd = new AsyncWebServer(80); @@ -195,12 +197,15 @@ void setup() { // pixels if (config::settings.strip_enable) { - strip = new EspRgbaStrip(config::settings.strip_address,config::settings.strip_led_count); + strip = new EspRgbStrip(config::settings.strip_address,config::settings.strip_led_count); +// strip = new EspRgbaStrip(config::settings.strip_address,config::settings.strip_led_count); ESP_LOGI(TAG, "Initializing Pixelmapped LEDs."); strip->begin(config::settings.strip_data_pin); e131->subscribe(config::settings.strip_universe); - e131->universe(config::settings.strip_universe)->onData(std::bind(&EspRgbaStrip::recvData, + e131->universe(config::settings.strip_universe)->onData(std::bind(&EspRgbStrip::recvData, strip, std::placeholders::_1)); +// e131->universe(config::settings.strip_universe)->onData(std::bind(&EspRgbaStrip::recvData, +// strip, std::placeholders::_1)); }