Skip to content

Commit

Permalink
make sparkle use less flash memory
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Dec 31, 2023
1 parent e37a5ed commit 0283b3b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions functions/sparkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int SPARK_CHANCE_PROMILLE = 300, int SPARK_INTENSITY = 1024>
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;
Expand All @@ -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;
}
}
}
Expand All @@ -55,4 +54,12 @@ class SparkleF {
uint32_t last_update_;
};

template<int SPARK_CHANCE_PROMILLE = 300, int SPARK_INTENSITY = 1024>
class SparkleF : public SparkleBase {
public:
void run(BladeBase* blade) {
SparkleBase::run(blade, SPARK_CHANCE_PROMILLE, SPARK_INTENSITY);
}
};

#endif

0 comments on commit 0283b3b

Please sign in to comment.