From 0283b3b956e40bbd0e603152d4ec7f4852f99b37 Mon Sep 17 00:00:00 2001 From: profezzorn Date: Sun, 31 Dec 2023 08:54:38 +0000 Subject: [PATCH] make sparkle use less flash memory --- functions/sparkle.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/functions/sparkle.h b/functions/sparkle.h index 3e78aaf40..a877cd8eb 100644 --- a/functions/sparkle.h +++ b/functions/sparkle.h @@ -8,14 +8,13 @@ // SPARK_CHANCE_PROMILLE decides how often a spark is generated, defaults to 300 (30%) // SPARK_INTENSITY specifies how intens the spark is, defaults to 1024 -template -class SparkleF { +class SparkleBase { public: - ~SparkleF() { + ~SparkleBase() { delete[] sparks_; } - void run(BladeBase* blade) { + void run(BladeBase* blade, int spark_chance_promille, int spark_intensity) { uint32_t m = millis(); if (!sparks_) { size_t N = blade->num_leds() + 4; @@ -42,8 +41,8 @@ class SparkleF { } sparks_[N] = fifo[0]; sparks_[N+1] = fifo[1]; - if (random(1000) < SPARK_CHANCE_PROMILLE) { - sparks_[random(blade->num_leds())+2] += SPARK_INTENSITY; + if (random(1000) < spark_chance_promille) { + sparks_[random(blade->num_leds())+2] += spark_intensity; } } } @@ -55,4 +54,12 @@ class SparkleF { uint32_t last_update_; }; +template +class SparkleF : public SparkleBase { +public: + void run(BladeBase* blade) { + SparkleBase::run(blade, SPARK_CHANCE_PROMILLE, SPARK_INTENSITY); + } +}; + #endif