mirror of
https://github.com/gunner47/GyverLamp.git
synced 2025-08-07 09:00:30 +03:00
Оптимизация использования памяти
This commit is contained in:
@@ -17,30 +17,30 @@ class FavoritesManager
|
||||
static void SetStatus(char* statusText) // помещает в statusText состояние режима работы избранных эффектов
|
||||
{
|
||||
char buff[6];
|
||||
statusText = "FAV ";
|
||||
strcpy_P(statusText, PSTR("FAV "));
|
||||
|
||||
statusText = strcat(statusText, FavoritesRunning ? "1" : "0");
|
||||
statusText = strcat(statusText, " ");
|
||||
strcat_P(statusText, FavoritesRunning ? PSTR("1") : PSTR("0"));
|
||||
strcat_P(statusText, PSTR(" "));
|
||||
|
||||
itoa(Interval, buff, 10);
|
||||
statusText = strcat(statusText, buff);
|
||||
statusText = strcat(statusText, " ");
|
||||
strcat(statusText, buff);
|
||||
strcat_P(statusText, PSTR(" "));
|
||||
buff[0] = '\0';
|
||||
|
||||
itoa(Dispersion, buff, 10);
|
||||
statusText = strcat(statusText, buff);
|
||||
statusText = strcat(statusText, " ");
|
||||
strcat(statusText, buff);
|
||||
strcat_P(statusText, PSTR(" "));
|
||||
buff[0] = '\0';
|
||||
|
||||
for (uint8_t i = 0; i < MODE_AMOUNT; i++)
|
||||
{
|
||||
itoa((uint8_t)FavoriteModes[i], buff, 10);
|
||||
statusText = strcat(statusText, buff);
|
||||
if (i < MODE_AMOUNT - 1) statusText = strcat(statusText, " ");
|
||||
strcat(statusText, buff);
|
||||
if (i < MODE_AMOUNT - 1) strcat_P(statusText, PSTR(" "));
|
||||
buff[0] = '\0';
|
||||
}
|
||||
|
||||
statusText = strcat(statusText, "\0");
|
||||
statusText += '\0';
|
||||
}
|
||||
|
||||
static void ConfigureFavorites(const char* statusText) // принимает statusText, парсит его и инициализирует свойства класса значениями из statusText'а
|
||||
|
@@ -168,7 +168,7 @@ void setup()
|
||||
#endif
|
||||
|
||||
// ЛЕНТА
|
||||
FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)/*.setCorrection( TypicalLEDStrip )*/;
|
||||
FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)/*.setCorrection(TypicalLEDStrip)*/;
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
if (CURRENT_LIMIT > 0) FastLED.setMaxPowerInVoltsAndMilliamps(5, CURRENT_LIMIT);
|
||||
FastLED.clear();
|
||||
|
@@ -4,6 +4,7 @@ bool brightDirection;
|
||||
void buttonTick()
|
||||
{
|
||||
touch.tick();
|
||||
|
||||
if (touch.isSingle())
|
||||
{
|
||||
if (dawnFlag)
|
||||
|
@@ -662,6 +662,39 @@ void whiteColorRoutine()
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- экспериментальный эффект -------------
|
||||
// ------------- белый свет (уменьшение яркости по горизинтали от центра вверх и вниз; масштаб - ширина центральной полосы максимальной яркости; яркость - общая яркость -------------
|
||||
#define MINIMUM_BRIGHTNES (90U) // минимальная яркость (ниже матрица мерцает)
|
||||
void whiteColorRoutine2()
|
||||
{
|
||||
if (loadingFlag)
|
||||
{
|
||||
Serial.println("Отрисовка");
|
||||
loadingFlag = false;
|
||||
FastLED.clear();
|
||||
delay(1);
|
||||
|
||||
uint8_t centerY = max((uint8_t)round(HEIGHT / 2.0F) - 1, 0);
|
||||
uint8_t bottomOffset = (uint8_t)(!(HEIGHT & 1) && (HEIGHT > 1)); // если высота матрицы чётная, линий с максимальной яркостью две, а линии с угасающей яркостью снизу будут смещены на один ряд
|
||||
for (int16_t y = centerY; y >= 0; y--)
|
||||
{
|
||||
CRGB color = CHSV(100, 1,
|
||||
constrain(uint8_t( // определяем яркость
|
||||
modes[EFF_WHITE_COLOR].Brightness * (y + 1) / (centerY + 1) + // влияние координаты Y на яркость (плавное затухаие вверх и вниз)
|
||||
modes[EFF_WHITE_COLOR].Brightness * modes[EFF_WHITE_COLOR].Scale / 100), // влияние масштаба на яркость
|
||||
MINIMUM_BRIGHTNES,
|
||||
max((uint8_t)MINIMUM_BRIGHTNES, (uint8_t)modes[EFF_WHITE_COLOR].Brightness)
|
||||
));
|
||||
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
{
|
||||
drawPixelXY(x, y, color); // при чётной высоте матрицы максимально яркими отрисуются 2 центральных горизонтальных полосы
|
||||
drawPixelXY(x, max((uint8_t)(HEIGHT - 1) - (y + 1) + bottomOffset, 0), color); // при нечётной - одна, но дважды
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* устарело
|
||||
void lightersRoutine()
|
||||
|
@@ -45,6 +45,7 @@ void parseUDP()
|
||||
memcpy(buff, &inputBuffer[3], strlen(inputBuffer)); // взять подстроку, состоящую последних символов строки inputBuffer, начиная с символа 4
|
||||
modes[currentMode].Brightness = constrain(atoi(buff), 1, 255);
|
||||
FastLED.setBrightness(modes[currentMode].Brightness);
|
||||
loadingFlag = true;
|
||||
settChanged = true;
|
||||
eepromTimeout = millis();
|
||||
sendCurrent();
|
||||
@@ -158,14 +159,13 @@ void parseUDP()
|
||||
|
||||
else if (!strncmp_P(inputBuffer, PSTR("FAV_GET"), 7))
|
||||
{
|
||||
sendFavorites();
|
||||
FavoritesManager::SetStatus(inputBuffer);
|
||||
}
|
||||
|
||||
else if (!strncmp_P(inputBuffer, PSTR("FAV_SET"), 7))
|
||||
{
|
||||
FavoritesManager::ConfigureFavorites(inputBuffer);
|
||||
//FavoritesManager::SetStatus(inputBuffer);
|
||||
sendFavorites();
|
||||
FavoritesManager::SetStatus(inputBuffer);
|
||||
settChanged = true;
|
||||
eepromTimeout = millis();
|
||||
}
|
||||
@@ -263,16 +263,3 @@ void sendTimer()
|
||||
TimerManager::TimerOption,
|
||||
(TimerManager::TimerRunning ? (uint16_t)floor((TimerManager::TimeToFire - millis()) / 1000) : 0));
|
||||
}
|
||||
|
||||
void sendFavorites()
|
||||
{
|
||||
sprintf_P(inputBuffer, PSTR("FAV %u %u %u"),
|
||||
FavoritesManager::FavoritesRunning,
|
||||
FavoritesManager::Interval,
|
||||
FavoritesManager::Dispersion);
|
||||
|
||||
for (uint8_t i = 0; i < MODE_AMOUNT; i++)
|
||||
{
|
||||
sprintf_P(inputBuffer, PSTR("%s %u"), inputBuffer, FavoritesManager::FavoriteModes[i]);
|
||||
}
|
||||
}
|
||||
|
@@ -3,16 +3,17 @@
|
||||
// залить все
|
||||
void fillAll(CRGB color)
|
||||
{
|
||||
for (int32_t i = 0; i < NUM_LEDS; i++) {
|
||||
for (int32_t i = 0; i < NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
// функция отрисовки точки по координатам X Y
|
||||
void drawPixelXY(int8_t x, int8_t y, CRGB color)
|
||||
void drawPixelXY(uint8_t x, uint8_t y, CRGB color)
|
||||
{
|
||||
if (x < 0 || x > WIDTH - 1 || y < 0 || y > HEIGHT - 1) return;
|
||||
int32_t thisPixel = getPixelNumber(x, y) * SEGMENTS;
|
||||
uint32_t thisPixel = getPixelNumber(x, y) * SEGMENTS;
|
||||
for (uint8_t i = 0; i < SEGMENTS; i++)
|
||||
{
|
||||
leds[thisPixel + i] = color;
|
||||
@@ -28,7 +29,7 @@ uint32_t getPixColor(uint32_t thisSegm)
|
||||
}
|
||||
|
||||
// функция получения цвета пикселя в матрице по его координатам
|
||||
uint32_t getPixColorXY(int8_t x, int8_t y)
|
||||
uint32_t getPixColorXY(uint8_t x, uint8_t y)
|
||||
{
|
||||
return getPixColor(getPixelNumber(x, y));
|
||||
}
|
||||
@@ -83,7 +84,7 @@ uint32_t getPixColorXY(int8_t x, int8_t y)
|
||||
#endif
|
||||
|
||||
// получить номер пикселя в ленте по координатам
|
||||
uint16_t getPixelNumber(int8_t x, int8_t y)
|
||||
uint16_t getPixelNumber(uint8_t x, uint8_t y)
|
||||
{
|
||||
if ((THIS_Y % 2 == 0) || MATRIX_TYPE) // если чётная строка
|
||||
{
|
||||
|
Reference in New Issue
Block a user