From 36edb94ff02be8357ac168130cf6b6bf666b64d9 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 25 Sep 2019 18:11:03 +0200 Subject: [PATCH] Metrics now include the current effect's name. --- include/Effect.h | 5 ++--- include/effect_analogclock.h | 1 + include/effect_animation.h | 2 ++ include/effect_bell.h | 5 ++--- include/effect_big_clock.h | 5 ++--- include/effect_blur2d.h | 1 + include/effect_clock.h | 1 + include/effect_confetti.h | 6 +++--- include/effect_cycle.h | 6 ++---- include/effect_dvd.h | 1 + include/effect_dynamic.h | 3 +++ include/effect_fire.h | 1 + include/effect_firework.h | 1 + include/effect_gol.h | 1 + include/effect_marquee.h | 1 + include/effect_matrix.h | 3 +++ include/effect_pixelclock.h | 1 + include/effect_sinematrix3.h | 5 ++--- include/effect_sines.h | 1 + include/effect_snake.h | 6 ++---- include/effect_static.h | 5 ++--- include/effect_twirl.h | 5 ++--- src/effect_animation.cpp | 7 +++++++ src/effect_cycle.cpp | 6 ++++++ src/pitrix.cpp | 2 +- 25 files changed, 51 insertions(+), 30 deletions(-) diff --git a/include/Effect.h b/include/Effect.h index 81c60f7..00fc48f 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -1,5 +1,4 @@ -#ifndef Effect_H -#define Effect_H +#pragma once #include "Window.h" #include "config.h" @@ -11,6 +10,7 @@ protected: public: virtual ~Effect() {}; virtual void loop() = 0; + virtual String get_name() = 0; boolean supports_window = false; virtual boolean can_be_shown_with_clock() { return false; }; virtual boolean clock_as_mask() { return false; }; @@ -20,4 +20,3 @@ public: virtual void apply_option(String key, String value) {}; }; -#endif diff --git a/include/effect_analogclock.h b/include/effect_analogclock.h index 747ac59..b6bb04a 100644 --- a/include/effect_analogclock.h +++ b/include/effect_analogclock.h @@ -5,4 +5,5 @@ class AnalogClockEffect : public Effect { public: void loop(); + String get_name() override { return "analog_clock"; } }; diff --git a/include/effect_animation.h b/include/effect_animation.h index 5f3b0b3..55e208b 100644 --- a/include/effect_animation.h +++ b/include/effect_animation.h @@ -8,6 +8,7 @@ class AnimationEffect : public Effect { private: Animation *animation; + const char* name; uint16_t xOffset; uint16_t yOffset; public: @@ -17,4 +18,5 @@ public: ~AnimationEffect(); AnimationEffect* setFgColor(uint32_t c); void loop(); + String get_name() override; }; diff --git a/include/effect_bell.h b/include/effect_bell.h index d1024cf..7612e5f 100644 --- a/include/effect_bell.h +++ b/include/effect_bell.h @@ -1,5 +1,4 @@ -#ifndef effect_bell_H -#define effect_bell_H +#pragma once #include "Effect.h" #include "functions.h" @@ -11,6 +10,6 @@ private: boolean invert = false; public: void loop(); + String get_name() override { return "bell"; } }; -#endif diff --git a/include/effect_big_clock.h b/include/effect_big_clock.h index 2c5d916..740b0d8 100644 --- a/include/effect_big_clock.h +++ b/include/effect_big_clock.h @@ -1,5 +1,4 @@ -#ifndef effect_big_clock_H -#define effect_big_clock_H +#pragma once #include "Effect.h" @@ -13,6 +12,6 @@ private: public: void loop(); + String get_name() override { return "big_clock"; } }; -#endif diff --git a/include/effect_blur2d.h b/include/effect_blur2d.h index 3ca1895..3f4b038 100644 --- a/include/effect_blur2d.h +++ b/include/effect_blur2d.h @@ -12,5 +12,6 @@ public: boolean supports_window = true; boolean can_be_shown_with_clock(); void loop(); + String get_name() override { return "blur2d"; } }; diff --git a/include/effect_clock.h b/include/effect_clock.h index 1df3d5a..bc37721 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -13,4 +13,5 @@ public: ~ClockEffect(); void loop(); void loop(boolean invert, CRGB fg_color, CRGB bg_color); + String get_name() override { return "clock"; } }; diff --git a/include/effect_confetti.h b/include/effect_confetti.h index cff7210..87392d7 100644 --- a/include/effect_confetti.h +++ b/include/effect_confetti.h @@ -1,5 +1,4 @@ -#ifndef effect_confetti_H -#define effect_confetti_H +#pragma once #include "Effect.h" #include "my_fastled.h" @@ -10,11 +9,12 @@ protected: public: void loop(); boolean can_be_shown_with_clock(); + String get_name() override { return "confetti"; } }; class RandomConfettiEffect : public ConfettiEffect { protected: CRGB _getColor() override; + String get_name() override { return "random_confetti"; } }; -#endif diff --git a/include/effect_cycle.h b/include/effect_cycle.h index 6422380..96c0889 100644 --- a/include/effect_cycle.h +++ b/include/effect_cycle.h @@ -1,5 +1,4 @@ -#ifndef effect_cycle_H -#define effect_cycle_H +#pragma once #include "Effect.h" #include "effects.h" @@ -16,8 +15,7 @@ public: boolean can_be_shown_with_clock(); boolean clock_as_mask(); + String get_name() override; void loop(); }; - -#endif diff --git a/include/effect_dvd.h b/include/effect_dvd.h index 1ec0c17..ca316c2 100644 --- a/include/effect_dvd.h +++ b/include/effect_dvd.h @@ -14,4 +14,5 @@ public: ~DvdEffect(); void loop() override; bool can_be_shown_with_clock() override; + String get_name() override { return "dvd"; } }; diff --git a/include/effect_dynamic.h b/include/effect_dynamic.h index e5bc285..cba8af2 100644 --- a/include/effect_dynamic.h +++ b/include/effect_dynamic.h @@ -15,11 +15,13 @@ public: boolean can_be_shown_with_clock(); virtual void loop(); void draw(); + String get_name() override { return "single_dynamic"; } }; class MultiDynamicEffect : public SingleDynamicEffect { public: void loop(); + String get_name() override { return "multi_dynamic"; } }; class BigDynamicEffect : public Effect { @@ -29,4 +31,5 @@ public: void loop(); ~BigDynamicEffect(); boolean can_be_shown_with_clock() override; + String get_name() override { return "big_dynamic"; } }; diff --git a/include/effect_fire.h b/include/effect_fire.h index 684a7e4..2b7bbd8 100644 --- a/include/effect_fire.h +++ b/include/effect_fire.h @@ -16,4 +16,5 @@ public: FireEffect(); ~FireEffect(); void loop(); + String get_name() override { return "fire"; } }; diff --git a/include/effect_firework.h b/include/effect_firework.h index 9a8260a..26ea2e9 100644 --- a/include/effect_firework.h +++ b/include/effect_firework.h @@ -57,5 +57,6 @@ public: boolean supports_window = true; boolean can_be_shown_with_clock(); void loop(); + String get_name() override { return "firework"; } }; diff --git a/include/effect_gol.h b/include/effect_gol.h index 6646764..57ff641 100644 --- a/include/effect_gol.h +++ b/include/effect_gol.h @@ -19,4 +19,5 @@ public: ~GolEffect(); void loop(); bool can_be_shown_with_clock(); + String get_name() override { return "gol"; } }; diff --git a/include/effect_marquee.h b/include/effect_marquee.h index 66838c2..fa272c8 100644 --- a/include/effect_marquee.h +++ b/include/effect_marquee.h @@ -14,5 +14,6 @@ public: boolean can_be_shown_with_clock(); void loop(); void apply_option(String key, String value) override; + String get_name() override { return "marquee"; } }; diff --git a/include/effect_matrix.h b/include/effect_matrix.h index 7434782..783aee8 100644 --- a/include/effect_matrix.h +++ b/include/effect_matrix.h @@ -56,14 +56,17 @@ public: MatrixEffect(); virtual ~MatrixEffect(); void loop(); + String get_name() override { return "matrix"; } }; class RainbowMatrixEffect : public MatrixEffect { public: RainbowMatrixEffect(); + String get_name() override { return "rainbow_matrix"; } }; class RandomMatrixEffect : public MatrixEffect { public: RandomMatrixEffect(); + String get_name() override { return "random_matrix"; } }; diff --git a/include/effect_pixelclock.h b/include/effect_pixelclock.h index d6baee9..a0e3082 100644 --- a/include/effect_pixelclock.h +++ b/include/effect_pixelclock.h @@ -12,4 +12,5 @@ public: ~PixelClockEffect(); void loop(); bool can_be_shown_with_clock(); + String get_name() override { return "pixel_clock"; } }; diff --git a/include/effect_sinematrix3.h b/include/effect_sinematrix3.h index 2cb530d..ca59f2b 100644 --- a/include/effect_sinematrix3.h +++ b/include/effect_sinematrix3.h @@ -1,5 +1,4 @@ -#ifndef effect_sinematrix3_H -#define effect_sinematrix3_H +#pragma once #include "prototypes.h" #include "functions.h" @@ -32,6 +31,6 @@ public: boolean can_be_shown_with_clock(); boolean clock_as_mask(); void loop(); + String get_name() override { return "sinematrix3"; } }; -#endif diff --git a/include/effect_sines.h b/include/effect_sines.h index 12e7bc0..fbcd4f0 100644 --- a/include/effect_sines.h +++ b/include/effect_sines.h @@ -28,5 +28,6 @@ public: boolean supports_window = true; boolean can_be_shown_with_clock(); void loop(); + String get_name() override { return "sines"; } }; diff --git a/include/effect_snake.h b/include/effect_snake.h index a6f8465..7e7cb3c 100644 --- a/include/effect_snake.h +++ b/include/effect_snake.h @@ -1,5 +1,4 @@ -#ifndef effect_snake_H -#define effect_snake_H +#pragma once #include "Effect.h" #include "prototypes.h" @@ -22,6 +21,5 @@ public: boolean valid_position(Coords c); Coords update_position(Coords c, uint8_t direction); boolean can_be_shown_with_clock(); + String get_name() override { return "snake"; } }; - -#endif diff --git a/include/effect_static.h b/include/effect_static.h index 8ff68ce..13be43d 100644 --- a/include/effect_static.h +++ b/include/effect_static.h @@ -1,5 +1,4 @@ -#ifndef effect_static_H -#define effect_static_H +#pragma once #include "Effect.h" #include "my_fastled.h" @@ -11,6 +10,6 @@ public: StaticEffect(CRGB col); boolean supports_window = true; void loop(); + String get_name() override { return "static"; } }; -#endif diff --git a/include/effect_twirl.h b/include/effect_twirl.h index 0a5cdf1..34437e8 100644 --- a/include/effect_twirl.h +++ b/include/effect_twirl.h @@ -1,5 +1,4 @@ -#ifndef effect_twirl_H -#define effect_twirl_H +#pragma once #include "Effect.h" #include @@ -14,6 +13,6 @@ public: void loop(); boolean can_be_shown_with_clock() override; boolean clock_as_mask() override; + String get_name() override { return "twirl"; } }; -#endif diff --git a/src/effect_animation.cpp b/src/effect_animation.cpp index 09e201c..40b056c 100644 --- a/src/effect_animation.cpp +++ b/src/effect_animation.cpp @@ -2,6 +2,7 @@ #include "functions.h" AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) { + this->name = name; this->xOffset = x; this->yOffset = y; @@ -23,3 +24,9 @@ void AnimationEffect::loop() { this->animation->drawFrame(); this->animation->advance(); } + +String AnimationEffect::get_name() { + String s = "animation/"; + s += this->name; + return s; +} diff --git a/src/effect_cycle.cpp b/src/effect_cycle.cpp index 9791d8b..5e7ca09 100644 --- a/src/effect_cycle.cpp +++ b/src/effect_cycle.cpp @@ -47,3 +47,9 @@ void CycleEffect::loop() { } } } + +String CycleEffect::get_name() { + String s = "cycle/"; + s += effect->get_name(); + return s; +} diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 5bf98b2..6f902bc 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -108,7 +108,7 @@ void loop() { #if defined(MQTT_ENABLE) && defined(MQTT_REPORT_METRICS) EVERY_N_SECONDS(15) { 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); metrics_frame_count = 0; metrics_frame_time = 0;