send screen names to ESP Insights
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -59,5 +59,37 @@ class MenuItem;
|
||||
*/
|
||||
typedef std::function<void(MenuItem, ButtonType)> ButtonCallback;
|
||||
|
||||
/**
|
||||
* @def IMPLEMENT_GET_NAME
|
||||
* @brief Macro to implement getName() method using __FILE__
|
||||
* @details Extracts the class name from the source filename automatically.
|
||||
* Use this macro in .cpp files to implement Widget::getName().
|
||||
* @param ClassName The class name for the method scope (e.g., MainMenu)
|
||||
*/
|
||||
#define IMPLEMENT_GET_NAME(ClassName) \
|
||||
const char *ClassName::getName() const \
|
||||
{ \
|
||||
static const char *cachedName = nullptr; \
|
||||
if (!cachedName) \
|
||||
{ \
|
||||
const char *file = __FILE__; \
|
||||
const char *lastSlash = file; \
|
||||
for (const char *p = file; *p; ++p) \
|
||||
{ \
|
||||
if (*p == '/' || *p == '\\') \
|
||||
lastSlash = p + 1; \
|
||||
} \
|
||||
static char buffer[64]; \
|
||||
size_t i = 0; \
|
||||
for (; lastSlash[i] && lastSlash[i] != '.' && i < sizeof(buffer) - 1; ++i) \
|
||||
{ \
|
||||
buffer[i] = lastSlash[i]; \
|
||||
} \
|
||||
buffer[i] = '\0'; \
|
||||
cachedName = buffer; \
|
||||
} \
|
||||
return cachedName; \
|
||||
}
|
||||
|
||||
// Include MenuItem.h after the typedef to avoid circular dependency
|
||||
#include "data/MenuItem.h"
|
||||
@@ -150,6 +150,19 @@ class Widget
|
||||
*/
|
||||
virtual void OnButtonClicked(ButtonType button);
|
||||
|
||||
/**
|
||||
* @brief Returns the name of this widget for diagnostic purposes
|
||||
* @return A string identifying the widget type
|
||||
*
|
||||
* @details This method returns a human-readable name for the widget which
|
||||
* is used for logging and diagnostic events. Derived classes should
|
||||
* override this method to return their specific screen/widget name.
|
||||
*
|
||||
* @note The base implementation returns "Widget". Override in derived classes
|
||||
* to provide meaningful screen names for diagnostics.
|
||||
*/
|
||||
virtual const char *getName() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Pointer to the u8g2 display context used for rendering operations
|
||||
|
||||
@@ -24,6 +24,7 @@ class ClockScreenSaver final : public Widget
|
||||
void Update(uint64_t dt) override;
|
||||
void Render() override;
|
||||
void OnButtonClicked(ButtonType button) override;
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
static constexpr int MOVE_INTERVAL = 50; // milliseconds between movements
|
||||
|
||||
@@ -7,6 +7,8 @@ class ExternalDevices final : public Menu
|
||||
public:
|
||||
explicit ExternalDevices(menu_options_t *options);
|
||||
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
void onButtonPressed(const MenuItem &menuItem, ButtonType button) override;
|
||||
menu_options_t *m_options;
|
||||
|
||||
@@ -80,6 +80,8 @@ class LightMenu final : public Menu
|
||||
*/
|
||||
explicit LightMenu(menu_options_t *options);
|
||||
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Handles button press events specific to light control menu items
|
||||
|
||||
@@ -57,6 +57,8 @@ class MainMenu final : public Menu
|
||||
*/
|
||||
explicit MainMenu(menu_options_t *options);
|
||||
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Handles button press events specific to main menu items
|
||||
|
||||
@@ -26,6 +26,7 @@ class ScreenSaver final : public Widget
|
||||
void Update(uint64_t dt) override;
|
||||
void Render() override;
|
||||
void OnButtonClicked(ButtonType button) override;
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
*/
|
||||
class SettingsMenu final : public Menu
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the settings menu with the specified configuration
|
||||
* @param options Pointer to menu options configuration structure
|
||||
@@ -74,4 +74,6 @@ public:
|
||||
* @see Menu::Menu for base class construction details
|
||||
*/
|
||||
explicit SettingsMenu(menu_options_t *options);
|
||||
|
||||
const char *getName() const override;
|
||||
};
|
||||
@@ -151,6 +151,8 @@ class SplashScreen final : public Widget
|
||||
*/
|
||||
void Render() override;
|
||||
|
||||
const char *getName() const override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Pointer to menu options configuration structure
|
||||
|
||||
@@ -31,3 +31,8 @@ void Widget::Render()
|
||||
void Widget::OnButtonClicked(ButtonType button)
|
||||
{
|
||||
}
|
||||
|
||||
const char *Widget::getName() const
|
||||
{
|
||||
return "Widget";
|
||||
}
|
||||
|
||||
@@ -132,3 +132,5 @@ void ClockScreenSaver::OnButtonClicked(ButtonType button)
|
||||
m_options->popScreen();
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(ClockScreenSaver)
|
||||
|
||||
@@ -23,3 +23,5 @@ void ExternalDevices::onButtonPressed(const MenuItem &menuItem, const ButtonType
|
||||
ble_connect_to_device(menuItem.getId());
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(ExternalDevices)
|
||||
|
||||
@@ -123,3 +123,5 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
m_options->pushScreen(widget);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(LightMenu)
|
||||
|
||||
@@ -48,3 +48,5 @@ void MainMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(MainMenu)
|
||||
|
||||
@@ -327,3 +327,5 @@ void ScreenSaver::OnButtonClicked(ButtonType button)
|
||||
m_options->popScreen();
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(ScreenSaver)
|
||||
|
||||
@@ -9,3 +9,5 @@ SettingsMenu::SettingsMenu(menu_options_t *options) : Menu(options)
|
||||
{
|
||||
addText(SettingsMenuItem::OTA_UPLOAD, "OTA Einspielen");
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(SettingsMenu)
|
||||
|
||||
@@ -28,3 +28,5 @@ void SplashScreen::Render()
|
||||
u8g2_SetFont(u8g2, u8g2_font_haxrcorp4089_tr);
|
||||
u8g2_DrawStr(u8g2, 35, 50, "Initialisierung...");
|
||||
}
|
||||
|
||||
IMPLEMENT_GET_NAME(SplashScreen)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "wifi_manager.h"
|
||||
#include <driver/i2c.h>
|
||||
#include <esp_diagnostics.h>
|
||||
#include <esp_insights.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <esp_timer.h>
|
||||
@@ -62,6 +63,7 @@ void setScreen(const std::shared_ptr<Widget> &screen)
|
||||
{
|
||||
if (screen != nullptr)
|
||||
{
|
||||
ESP_DIAG_EVENT(TAG, "Screen set: %s", screen->getName());
|
||||
m_widget = screen;
|
||||
m_history.clear();
|
||||
m_history.emplace_back(m_widget);
|
||||
@@ -77,6 +79,7 @@ void pushScreen(const std::shared_ptr<Widget> &screen)
|
||||
{
|
||||
m_widget->onPause();
|
||||
}
|
||||
ESP_DIAG_EVENT(TAG, "Screen pushed: %s", screen->getName());
|
||||
m_widget = screen;
|
||||
m_widget->onEnter();
|
||||
m_history.emplace_back(m_widget);
|
||||
@@ -97,6 +100,7 @@ void popScreen()
|
||||
m_widget->onExit();
|
||||
}
|
||||
m_widget = m_history.back();
|
||||
ESP_DIAG_EVENT(TAG, "Screen popped, now: %s", m_widget->getName());
|
||||
m_widget->onResume();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user