Metrics now include the current effect's name.

This commit is contained in:
Fabian Schlenz 2019-09-25 18:11:03 +02:00
parent d396b68191
commit 36edb94ff0
25 changed files with 51 additions and 30 deletions

View File

@ -1,5 +1,4 @@
#ifndef Effect_H #pragma once
#define Effect_H
#include "Window.h" #include "Window.h"
#include "config.h" #include "config.h"
@ -11,6 +10,7 @@ protected:
public: public:
virtual ~Effect() {}; virtual ~Effect() {};
virtual void loop() = 0; virtual void loop() = 0;
virtual String get_name() = 0;
boolean supports_window = false; boolean supports_window = false;
virtual boolean can_be_shown_with_clock() { return false; }; virtual boolean can_be_shown_with_clock() { return false; };
virtual boolean clock_as_mask() { return false; }; virtual boolean clock_as_mask() { return false; };
@ -20,4 +20,3 @@ public:
virtual void apply_option(String key, String value) {}; virtual void apply_option(String key, String value) {};
}; };
#endif

View File

@ -5,4 +5,5 @@
class AnalogClockEffect : public Effect { class AnalogClockEffect : public Effect {
public: public:
void loop(); void loop();
String get_name() override { return "analog_clock"; }
}; };

View File

@ -8,6 +8,7 @@
class AnimationEffect : public Effect { class AnimationEffect : public Effect {
private: private:
Animation *animation; Animation *animation;
const char* name;
uint16_t xOffset; uint16_t xOffset;
uint16_t yOffset; uint16_t yOffset;
public: public:
@ -17,4 +18,5 @@ public:
~AnimationEffect(); ~AnimationEffect();
AnimationEffect* setFgColor(uint32_t c); AnimationEffect* setFgColor(uint32_t c);
void loop(); void loop();
String get_name() override;
}; };

View File

@ -1,5 +1,4 @@
#ifndef effect_bell_H #pragma once
#define effect_bell_H
#include "Effect.h" #include "Effect.h"
#include "functions.h" #include "functions.h"
@ -11,6 +10,6 @@ private:
boolean invert = false; boolean invert = false;
public: public:
void loop(); void loop();
String get_name() override { return "bell"; }
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef effect_big_clock_H #pragma once
#define effect_big_clock_H
#include "Effect.h" #include "Effect.h"
@ -13,6 +12,6 @@ private:
public: public:
void loop(); void loop();
String get_name() override { return "big_clock"; }
}; };
#endif

View File

@ -12,5 +12,6 @@ public:
boolean supports_window = true; boolean supports_window = true;
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
void loop(); void loop();
String get_name() override { return "blur2d"; }
}; };

View File

@ -13,4 +13,5 @@ public:
~ClockEffect(); ~ClockEffect();
void loop(); void loop();
void loop(boolean invert, CRGB fg_color, CRGB bg_color); void loop(boolean invert, CRGB fg_color, CRGB bg_color);
String get_name() override { return "clock"; }
}; };

View File

@ -1,5 +1,4 @@
#ifndef effect_confetti_H #pragma once
#define effect_confetti_H
#include "Effect.h" #include "Effect.h"
#include "my_fastled.h" #include "my_fastled.h"
@ -10,11 +9,12 @@ protected:
public: public:
void loop(); void loop();
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
String get_name() override { return "confetti"; }
}; };
class RandomConfettiEffect : public ConfettiEffect { class RandomConfettiEffect : public ConfettiEffect {
protected: protected:
CRGB _getColor() override; CRGB _getColor() override;
String get_name() override { return "random_confetti"; }
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef effect_cycle_H #pragma once
#define effect_cycle_H
#include "Effect.h" #include "Effect.h"
#include "effects.h" #include "effects.h"
@ -16,8 +15,7 @@ public:
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
boolean clock_as_mask(); boolean clock_as_mask();
String get_name() override;
void loop(); void loop();
}; };
#endif

View File

@ -14,4 +14,5 @@ public:
~DvdEffect(); ~DvdEffect();
void loop() override; void loop() override;
bool can_be_shown_with_clock() override; bool can_be_shown_with_clock() override;
String get_name() override { return "dvd"; }
}; };

View File

@ -15,11 +15,13 @@ public:
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
virtual void loop(); virtual void loop();
void draw(); void draw();
String get_name() override { return "single_dynamic"; }
}; };
class MultiDynamicEffect : public SingleDynamicEffect { class MultiDynamicEffect : public SingleDynamicEffect {
public: public:
void loop(); void loop();
String get_name() override { return "multi_dynamic"; }
}; };
class BigDynamicEffect : public Effect { class BigDynamicEffect : public Effect {
@ -29,4 +31,5 @@ public:
void loop(); void loop();
~BigDynamicEffect(); ~BigDynamicEffect();
boolean can_be_shown_with_clock() override; boolean can_be_shown_with_clock() override;
String get_name() override { return "big_dynamic"; }
}; };

View File

@ -16,4 +16,5 @@ public:
FireEffect(); FireEffect();
~FireEffect(); ~FireEffect();
void loop(); void loop();
String get_name() override { return "fire"; }
}; };

View File

@ -57,5 +57,6 @@ public:
boolean supports_window = true; boolean supports_window = true;
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
void loop(); void loop();
String get_name() override { return "firework"; }
}; };

View File

@ -19,4 +19,5 @@ public:
~GolEffect(); ~GolEffect();
void loop(); void loop();
bool can_be_shown_with_clock(); bool can_be_shown_with_clock();
String get_name() override { return "gol"; }
}; };

View File

@ -14,5 +14,6 @@ public:
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
void loop(); void loop();
void apply_option(String key, String value) override; void apply_option(String key, String value) override;
String get_name() override { return "marquee"; }
}; };

View File

@ -56,14 +56,17 @@ public:
MatrixEffect(); MatrixEffect();
virtual ~MatrixEffect(); virtual ~MatrixEffect();
void loop(); void loop();
String get_name() override { return "matrix"; }
}; };
class RainbowMatrixEffect : public MatrixEffect { class RainbowMatrixEffect : public MatrixEffect {
public: public:
RainbowMatrixEffect(); RainbowMatrixEffect();
String get_name() override { return "rainbow_matrix"; }
}; };
class RandomMatrixEffect : public MatrixEffect { class RandomMatrixEffect : public MatrixEffect {
public: public:
RandomMatrixEffect(); RandomMatrixEffect();
String get_name() override { return "random_matrix"; }
}; };

View File

@ -12,4 +12,5 @@ public:
~PixelClockEffect(); ~PixelClockEffect();
void loop(); void loop();
bool can_be_shown_with_clock(); bool can_be_shown_with_clock();
String get_name() override { return "pixel_clock"; }
}; };

View File

@ -1,5 +1,4 @@
#ifndef effect_sinematrix3_H #pragma once
#define effect_sinematrix3_H
#include "prototypes.h" #include "prototypes.h"
#include "functions.h" #include "functions.h"
@ -32,6 +31,6 @@ public:
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
boolean clock_as_mask(); boolean clock_as_mask();
void loop(); void loop();
String get_name() override { return "sinematrix3"; }
}; };
#endif

View File

@ -28,5 +28,6 @@ public:
boolean supports_window = true; boolean supports_window = true;
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
void loop(); void loop();
String get_name() override { return "sines"; }
}; };

View File

@ -1,5 +1,4 @@
#ifndef effect_snake_H #pragma once
#define effect_snake_H
#include "Effect.h" #include "Effect.h"
#include "prototypes.h" #include "prototypes.h"
@ -22,6 +21,5 @@ public:
boolean valid_position(Coords c); boolean valid_position(Coords c);
Coords update_position(Coords c, uint8_t direction); Coords update_position(Coords c, uint8_t direction);
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
String get_name() override { return "snake"; }
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef effect_static_H #pragma once
#define effect_static_H
#include "Effect.h" #include "Effect.h"
#include "my_fastled.h" #include "my_fastled.h"
@ -11,6 +10,6 @@ public:
StaticEffect(CRGB col); StaticEffect(CRGB col);
boolean supports_window = true; boolean supports_window = true;
void loop(); void loop();
String get_name() override { return "static"; }
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef effect_twirl_H #pragma once
#define effect_twirl_H
#include "Effect.h" #include "Effect.h"
#include <Arduino.h> #include <Arduino.h>
@ -14,6 +13,6 @@ public:
void loop(); void loop();
boolean can_be_shown_with_clock() override; boolean can_be_shown_with_clock() override;
boolean clock_as_mask() override; boolean clock_as_mask() override;
String get_name() override { return "twirl"; }
}; };
#endif

View File

@ -2,6 +2,7 @@
#include "functions.h" #include "functions.h"
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) { AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
this->name = name;
this->xOffset = x; this->xOffset = x;
this->yOffset = y; this->yOffset = y;
@ -23,3 +24,9 @@ void AnimationEffect::loop() {
this->animation->drawFrame(); this->animation->drawFrame();
this->animation->advance(); this->animation->advance();
} }
String AnimationEffect::get_name() {
String s = "animation/";
s += this->name;
return s;
}

View File

@ -47,3 +47,9 @@ void CycleEffect::loop() {
} }
} }
} }
String CycleEffect::get_name() {
String s = "cycle/";
s += effect->get_name();
return s;
}

View File

@ -108,7 +108,7 @@ void loop() {
#if defined(MQTT_ENABLE) && defined(MQTT_REPORT_METRICS) #if defined(MQTT_ENABLE) && defined(MQTT_REPORT_METRICS)
EVERY_N_SECONDS(15) { EVERY_N_SECONDS(15) {
char json[120]; char json[120];
snprintf(json, 120, "{\"free_heap\":%u, \"uptime\":%lu, \"fps\":%d, \"time_per_frame\":%lu}", ESP.getFreeHeap(), millis()/1000, FastLED.getFPS(), metrics_frame_time / metrics_frame_count); snprintf(json, 120, "{\"effect\":\"%s\",\"heap\":%u, \"up\":%lu, \"fps\":%d, \"frametime\":%lu}", current_effect->get_name().c_str(), ESP.getFreeHeap(), millis()/1000, FastLED.getFPS(), metrics_frame_time / metrics_frame_count);
mqtt_publish("metrics", json); mqtt_publish("metrics", json);
metrics_frame_count = 0; metrics_frame_count = 0;
metrics_frame_time = 0; metrics_frame_time = 0;