Added Effect::start()
and Effect::stop()
to allow effects to reserve memory on start and free it afterwards.
This commit is contained in:
parent
a2fe1461ad
commit
a7d956209a
@ -16,6 +16,8 @@ class Effect {
|
|||||||
void setWindow(Window win) {
|
void setWindow(Window win) {
|
||||||
window = win;
|
window = win;
|
||||||
};
|
};
|
||||||
|
virtual void start() {}
|
||||||
|
virtual void stop() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,6 +10,8 @@ class CycleEffect : public Effect {
|
|||||||
unsigned long effectSince = 0;
|
unsigned long effectSince = 0;
|
||||||
public:
|
public:
|
||||||
void changeEffect();
|
void changeEffect();
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
boolean can_be_shown_with_clock();
|
boolean can_be_shown_with_clock();
|
||||||
boolean clock_as_mask();
|
boolean clock_as_mask();
|
||||||
|
@ -6,10 +6,21 @@ void CycleEffect::changeEffect() {
|
|||||||
int new_id = random8(cycle_effects->size());
|
int new_id = random8(cycle_effects->size());
|
||||||
new_effect = cycle_effects->get(new_id);
|
new_effect = cycle_effects->get(new_id);
|
||||||
} while (&new_effect == &effect);
|
} while (&new_effect == &effect);
|
||||||
|
if (effect) effect->stop();
|
||||||
effect = new_effect;
|
effect = new_effect;
|
||||||
|
effect->start();
|
||||||
effectSince = millis();
|
effectSince = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CycleEffect::start() {
|
||||||
|
if (!effect) changeEffect();
|
||||||
|
else effect->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CycleEffect::stop() {
|
||||||
|
if (effect) effect->stop();
|
||||||
|
}
|
||||||
|
|
||||||
boolean CycleEffect::can_be_shown_with_clock() {
|
boolean CycleEffect::can_be_shown_with_clock() {
|
||||||
return effect->can_be_shown_with_clock();
|
return effect->can_be_shown_with_clock();
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,9 @@ void mqtt_callback(char* complete_topic, byte* pl, unsigned int length) {
|
|||||||
EffectEntry e = effects->get(i);
|
EffectEntry e = effects->get(i);
|
||||||
if (strcmp(e.name, payload)==0) {
|
if (strcmp(e.name, payload)==0) {
|
||||||
//Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect);
|
//Serial.printf("Effect found in mqtt_callback: %p\n", (void *)&e->effect);
|
||||||
|
current_effect->stop();
|
||||||
current_effect = e.effect;
|
current_effect = e.effect;
|
||||||
|
current_effect->start();
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ void setup() {
|
|||||||
ntpClient.begin();
|
ntpClient.begin();
|
||||||
mqtt_setup();
|
mqtt_setup();
|
||||||
LOGln("Core * Setup complete");
|
LOGln("Core * Setup complete");
|
||||||
|
|
||||||
|
current_effect->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
Loading…
Reference in New Issue
Block a user