Merge pull request #4664 from tonhuisman/feature/P128-adjust-to-latest-library-updates

[P128] Adjust to latest updates of NeoPixelBusfx library
This commit is contained in:
TD-er authored and GitHub committed 2023-05-26 20:51:47 +02:00
commit 954b48c54d
4 files changed
+42 -31

No files matched your search

+1
View File
@@ -482,6 +482,7 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = {
// #define P128_USES_RGB
// #define P128_USES_RGBW
// #define P128_USES_BRG
// #define P128_USES_BGR
// #define P128_USES_RBG
// #define P128_ENABLE_FAKETV 1 // Enable(1)/Disable(0) FakeTV effect, disabled by default on ESP8266 (.bin size issue), enabled by default on ESP32
// #define USES_P129 // 74HC165 Input shiftregisters
+3
View File
@@ -7,6 +7,9 @@
// #######################################################################################################
// Changelog:
// 2023-05-13, tonhuisman Add P128_USES_BGR / BGR definitions and support (compile-time)
// Use more global NeoWs2812xMethod, as the library uses best matching hardware features per CPU type
// 2023-05-12, tonhuisman Update for latest NeoPixelBusFx changes (NeoPixelBusLg class, (S/G)etLuminance method)
// 2022-07-20, tonhuisman Make FakeTV compile-time optional, disabled by default on ESP8266, enabled by default on ESP32
// P128_ENABLE_FAKETV can be set to 0/1 in Custom.h
// 2022-07-02, tonhuisman Introduce Max Brightness setting for protecting the hardware and power supply (and the eyes :-))
+26 -26
View File
@@ -9,19 +9,19 @@
P128_data_struct::P128_data_struct(int8_t _gpioPin,
uint16_t _pixelCount,
uint8_t _maxBright)
: gpioPin(_gpioPin), pixelCount(_pixelCount), maxBright(_maxBright)
: gpioPin(_gpioPin), pixelCount(_pixelCount), maxBright(_maxBright)
{
# ifdef ESP8266
Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB<FEATURE, METHOD>(min(pixelCount, static_cast<uint16_t>(ARRAYSIZE)));
# endif // ifdef ESP8266
# ifdef ESP32
Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB<FEATURE, METHOD>(min(pixelCount, static_cast<uint16_t>(ARRAYSIZE)),
_gpioPin);
_gpioPin);
# endif // ifdef ESP32
if (nullptr != Plugin_128_pixels) {
Plugin_128_pixels->Begin(); // This initializes the NeoPixelBus library.
Plugin_128_pixels->SetBrightness(maxBright);
Plugin_128_pixels->SetLuminance(maxBright);
}
}
@@ -146,7 +146,7 @@ bool P128_data_struct::plugin_write(struct EventStruct *event,
else if (equals(subCommand, F("dim"))) {
if ((str3i >= 0) && (str3i <= maxBright)) { // Safety check
success = true;
Plugin_128_pixels->SetBrightness(str3i);
Plugin_128_pixels->SetLuminance(str3i);
}
}
@@ -936,10 +936,10 @@ void P128_data_struct::faketv(void) {
ftv_ng = (uint8_t)pgm_read_byte(&ftv_gamma8[ftv_g8]) * 257;
ftv_nb = (uint8_t)pgm_read_byte(&ftv_gamma8[ftv_b8]) * 257;
ftv_totalTime = HwRandom(12, 125); // Semi-random pixel-to-pixel time
ftv_fadeTime = HwRandom(0, ftv_totalTime); // Pixel-to-pixel transition time
ftv_totalTime = HwRandom(12, 125); // Semi-random pixel-to-pixel time
ftv_fadeTime = HwRandom(0, ftv_totalTime); // Pixel-to-pixel transition time
if (HwRandom(10) < 3) { ftv_fadeTime = 0; } // Force scene cut 30% of time
if (HwRandom(10) < 3) { ftv_fadeTime = 0; } // Force scene cut 30% of time
ftv_holdTime = counter20ms + ftv_totalTime - ftv_fadeTime; // Non-transition time
ftv_startTime = counter20ms;
}
@@ -987,7 +987,7 @@ void P128_data_struct::rainbow(void) {
float progress = (float)counter / (float)fadetime;
if (fadeIn == true) {
Plugin_128_pixels->SetBrightness(progress * maxBright); // Safety check
Plugin_128_pixels->SetLuminance(progress * maxBright); // Safety check
fadeIn = (progress == 1) ? false : true;
}
@@ -1510,40 +1510,40 @@ void P128_data_struct::NeoPixelSendStatus(struct EventStruct *eventSource) {
printToWebJSON = true;
json += '{'; json += '\n'; // 2
json += to_json_object_value(F("plugin"), F("128")); // 12
json += '{'; json += '\n'; // 2
json += to_json_object_value(F("plugin"), F("128")); // 12
json += ','; json += '\n';
json += to_json_object_value(F("mode"), P128_modeType_toString(mode)); // 14..23
json += to_json_object_value(F("mode"), P128_modeType_toString(mode)); // 14..23
json += ','; json += '\n';
json += to_json_object_value(F("lastmode"), P128_modeType_toString(savemode)); // 18..27
json += to_json_object_value(F("lastmode"), P128_modeType_toString(savemode)); // 18..27
json += ','; json += '\n';
json += to_json_object_value(F("fadetime"), toString(fadetime, 0)); // 15..19
json += to_json_object_value(F("fadetime"), toString(fadetime, 0)); // 15..19
json += ','; json += '\n';
json += to_json_object_value(F("fadedelay"), toString(fadedelay, 0)); // 15..19
json += to_json_object_value(F("fadedelay"), toString(fadedelay, 0)); // 15..19
json += ','; json += '\n';
json += to_json_object_value(F("dim"), toString(Plugin_128_pixels->GetBrightness(), 0)); // 8..10
json += to_json_object_value(F("dim"), toString(Plugin_128_pixels->GetLuminance(), 0)); // 8..10
json += ','; json += '\n';
json += to_json_object_value(F("rgb"), colorStr, true); // 15..17
json += to_json_object_value(F("rgb"), colorStr, true); // 15..17
json += ','; json += '\n';
HsbColor hsbColor = HsbColor(RgbColor(rgb.R, rgb.G, rgb.B)); // Calculate only once
HsbColor hsbColor = HsbColor(RgbColor(rgb.R, rgb.G, rgb.B)); // Calculate only once
json += to_json_object_value(F("hue"), toString(hsbColor.H * 360.0f, 0)); // 17
json += to_json_object_value(F("hue"), toString(hsbColor.H * 360.0f, 0)); // 17
json += ','; json += '\n';
json += to_json_object_value(F("saturation"), toString(hsbColor.S * 100.0f, 0)); // 26?
json += to_json_object_value(F("saturation"), toString(hsbColor.S * 100.0f, 0)); // 26?
json += ','; json += '\n';
json += to_json_object_value(F("brightness"), toString(hsbColor.B * 100.0f, 0)); // 26?
json += to_json_object_value(F("brightness"), toString(hsbColor.B * 100.0f, 0)); // 26?
json += ','; json += '\n';
json += to_json_object_value(F("bgcolor"), backgroundcolorStr, true); // 21..23
json += to_json_object_value(F("bgcolor"), backgroundcolorStr, true); // 21..23
json += ','; json += '\n';
json += to_json_object_value(F("count"), toString(count, 0)); // 12..15
json += to_json_object_value(F("count"), toString(count, 0)); // 12..15
json += ','; json += '\n';
json += to_json_object_value(F("speed"), toString(speed, 0)); // 12..14
json += to_json_object_value(F("speed"), toString(speed, 0)); // 12..14
json += ','; json += '\n';
json += to_json_object_value(F("pixelcount"), toString(pixelCount, 0)); // 17..19
json += '\n'; json += '}'; json += '\n'; // 4
json += to_json_object_value(F("pixelcount"), toString(pixelCount, 0)); // 17..19
json += '\n'; json += '}'; json += '\n'; // 4
SendStatus(eventSource, json); // send http response to controller (JSON format)
SendStatus(eventSource, json); // send http response to controller (JSON format)
printToWeb = false;
}
+12 -5
View File
@@ -2209,7 +2209,8 @@ const uint8_t PROGMEM ftv_colors[] = {
0X20, 0XE4, 0X21, 0XA6, 0X29, 0XE7, 0X32, 0X28 };
# endif // if P128_ENABLE_FAKETV
# include <NeoPixelBrightnessBus.h>
# include <NeoPixelBusLg.h>
# include <NeoPixelBus.h>
# include "../../ESPEasy-Globals.h"
# define P128_CONFIG_LED_COUNT PCONFIG(0)
@@ -2218,6 +2219,8 @@ const uint8_t PROGMEM ftv_colors[] = {
# define SPEED_MAX 50
# define ARRAYSIZE 300 // Max LED Count
// # define P128_USES_GRB // Different type of pixel?
// Choose your color order below:
# if defined(P128_USES_GRB)
# define GRB
@@ -2229,6 +2232,8 @@ const uint8_t PROGMEM ftv_colors[] = {
# define RGBW
# elif defined(P128_USES_BRG)
# define BRG
# elif defined(P128_USES_BGR)
# define BGR
# elif defined(P128_USES_RBG)
# define RBG
# else // if defined(P128_USES_GRB)
@@ -2242,9 +2247,9 @@ const uint8_t PROGMEM ftv_colors[] = {
// # define BRG //A three element color in the order of Blue, Red, and then Green.
// # define RBG //A three element color in the order of Red, Blue, and then Green.
# define NEOPIXEL_LIB NeoPixelBrightnessBus // Neopixel library type
# define NEOPIXEL_LIB NeoPixelBusLg // Neopixel library type
# if defined(ESP32)
# define METHOD NeoEsp32Rmt1800KbpsMethod // RMT, user selected pin - use NeoEsp32RmtMethod
# define METHOD NeoWs2812xMethod // RMT, user selected pin - use NeoEsp32RmtMethod (CPU dependent)
# endif // if defined(ESP32)
# if defined(ESP8266)
# define METHOD NeoEsp8266Uart1800KbpsMethod // GPIO2 - use NeoEsp8266Uart0800KbpsMethod for GPIO1(TX)
@@ -2260,6 +2265,8 @@ const uint8_t PROGMEM ftv_colors[] = {
# define FEATURE NeoRgbwFeature
# elif defined BRG
# define FEATURE NeoBrgFeature
# elif defined BGR
# define FEATURE NeoBgrFeature
# elif defined RBG
# define FEATURE NeoRbgFeature
# else // if defined GRB
@@ -2330,9 +2337,9 @@ private:
rgb_s = HtmlColor(0xFF0000);
# endif // if defined(RGBW) || defined(GRBW)
const int8_t gpioPin = -1;
const int8_t gpioPin = -1;
const uint16_t pixelCount = 0;
const uint8_t maxBright = 0;
const uint8_t maxBright = 0;
int16_t fadedelay = 20;