restructure folder
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
37
components/insa/CMakeLists.txt
Normal file
37
components/insa/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
if (DEFINED ENV{IDF_PATH})
|
||||
idf_component_register(SRCS
|
||||
src/common/PSMenu.cpp
|
||||
src/common/ScrollBar.cpp
|
||||
src/common/Widget.cpp
|
||||
src/data/MenuItem.cpp
|
||||
src/ui/LightMenu.cpp
|
||||
src/ui/MainMenu.cpp
|
||||
src/ui/SettingsMenu.cpp
|
||||
src/ui/SplashScreen.cpp
|
||||
INCLUDE_DIRS "include"
|
||||
)
|
||||
return()
|
||||
endif ()
|
||||
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
project(insa)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
src/common/PSMenu.cpp
|
||||
src/common/ScrollBar.cpp
|
||||
src/common/Widget.cpp
|
||||
src/data/MenuItem.cpp
|
||||
src/ui/LightMenu.cpp
|
||||
src/ui/MainMenu.cpp
|
||||
src/ui/SettingsMenu.cpp
|
||||
src/ui/SplashScreen.cpp
|
||||
)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
u8g2
|
||||
ruth
|
||||
)
|
20
components/insa/include/MenuOptions.h
Normal file
20
components/insa/include/MenuOptions.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "common/Widget.h"
|
||||
#include "u8g2.h"
|
||||
|
||||
class Widget;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8g2_t *u8g2;
|
||||
|
||||
std::function<void(std::shared_ptr<Widget>)> setScreen;
|
||||
std::function<void(std::shared_ptr<Widget>)> pushScreen;
|
||||
std::function<void()> popScreen;
|
||||
|
||||
std::function<void(uint8_t button)> onButtonClicked;
|
||||
} menu_options_t;
|
7
components/insa/include/common/Common.h
Normal file
7
components/insa/include/common/Common.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
enum class ButtonType { NONE, UP, DOWN, LEFT, RIGHT, SELECT, BACK };
|
||||
|
||||
typedef std::function<void(uint8_t, ButtonType)> ButtonCallback;
|
41
components/insa/include/common/PSMenu.h
Normal file
41
components/insa/include/common/PSMenu.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "Common.h"
|
||||
#include "MenuOptions.h"
|
||||
#include "Widget.h"
|
||||
#include "data/MenuItem.h"
|
||||
|
||||
class PSMenu : public Widget
|
||||
{
|
||||
public:
|
||||
explicit PSMenu(menu_options_t *options);
|
||||
~PSMenu() override;
|
||||
|
||||
void addText(uint8_t id, const std::string &text, const ButtonCallback &callback);
|
||||
void addSelection(uint8_t id, const std::string &text, std::string &value, const std::vector<std::string>& values,
|
||||
const ButtonCallback &callback);
|
||||
void addNumber(uint8_t id, const std::string &text, std::string &value, const ButtonCallback &callback);
|
||||
void addToggle(uint8_t id, const std::string &text, bool selected, const ButtonCallback &callback);
|
||||
|
||||
private:
|
||||
void render() override;
|
||||
void onButtonClicked(uint8_t button) override;
|
||||
|
||||
void onPressedDown();
|
||||
void onPressedUp();
|
||||
void onPressedLeft() const;
|
||||
void onPressedRight() const;
|
||||
void onPressedSelect() const;
|
||||
void onPressedBack() const;
|
||||
|
||||
void drawScrollBar() const;
|
||||
void drawSelectionBox() const;
|
||||
|
||||
void renderWidget(const MenuItem *item, const uint8_t *font, int x, int y) const;
|
||||
|
||||
size_t m_selected_item = 0;
|
||||
std::vector<MenuItem> m_items;
|
||||
menu_options_t *m_options;
|
||||
};
|
24
components/insa/include/common/ScrollBar.h
Normal file
24
components/insa/include/common/ScrollBar.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "MenuOptions.h"
|
||||
#include "Widget.h"
|
||||
|
||||
class ScrollBar final : public Widget
|
||||
{
|
||||
public:
|
||||
ScrollBar(const menu_options_t *options, size_t x, size_t y, size_t width, size_t height);
|
||||
void render() override;
|
||||
void refresh(size_t value, size_t max, size_t min = 0);
|
||||
|
||||
private:
|
||||
size_t m_x;
|
||||
size_t m_y;
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
size_t m_value;
|
||||
size_t m_max;
|
||||
size_t m_min;
|
||||
|
||||
size_t m_thumbHeight;
|
||||
size_t m_thumbY;
|
||||
};
|
22
components/insa/include/common/Widget.h
Normal file
22
components/insa/include/common/Widget.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
class Widget
|
||||
{
|
||||
public:
|
||||
explicit Widget(u8g2_t *u8g2);
|
||||
|
||||
virtual ~Widget() = default;
|
||||
|
||||
virtual void update(uint64_t dt);
|
||||
|
||||
virtual void render();
|
||||
|
||||
virtual void onButtonClicked(uint8_t button);
|
||||
|
||||
protected:
|
||||
u8g2_t *u8g2;
|
||||
};
|
31
components/insa/include/data/MenuItem.h
Normal file
31
components/insa/include/data/MenuItem.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "common/Common.h"
|
||||
|
||||
class MenuItem
|
||||
{
|
||||
public:
|
||||
MenuItem(uint8_t id, uint8_t type, std::string text, ButtonCallback callback);
|
||||
MenuItem(uint8_t id, uint8_t type, std::string text, std::string value, ButtonCallback callback);
|
||||
MenuItem(uint8_t id, uint8_t type, std::string text, std::string value, std::vector<std::string> values,
|
||||
ButtonCallback callback);
|
||||
MenuItem(uint8_t id, uint8_t type, std::string text, bool selected, ButtonCallback callback);
|
||||
[[nodiscard]] uint8_t getId() const;
|
||||
[[nodiscard]] uint8_t getType() const;
|
||||
[[nodiscard]] const std::string &getText() const;
|
||||
[[nodiscard]] const std::string &getValue() const;
|
||||
void setValue(const std::string &value);
|
||||
void onButtonPressed(uint8_t id, ButtonType button) const;
|
||||
[[nodiscard]] bool hasCallback() const;
|
||||
|
||||
private:
|
||||
uint8_t m_id;
|
||||
uint8_t m_type;
|
||||
std::string m_text;
|
||||
std::string m_value;
|
||||
std::vector<std::string> m_values;
|
||||
ButtonCallback m_callback;
|
||||
};
|
14
components/insa/include/ui/LightMenu.h
Normal file
14
components/insa/include/ui/LightMenu.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/PSMenu.h"
|
||||
|
||||
class LightMenu final : public PSMenu
|
||||
{
|
||||
public:
|
||||
explicit LightMenu(menu_options_t *options);
|
||||
|
||||
private:
|
||||
void onButtonPressed(uint8_t id, ButtonType button) const;
|
||||
|
||||
menu_options_t *m_options;
|
||||
};
|
14
components/insa/include/ui/MainMenu.h
Normal file
14
components/insa/include/ui/MainMenu.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/PSMenu.h"
|
||||
|
||||
class MainMenu final : public PSMenu
|
||||
{
|
||||
public:
|
||||
explicit MainMenu(menu_options_t *options);
|
||||
|
||||
private:
|
||||
void onButtonPressed(uint8_t id, ButtonType button) const;
|
||||
|
||||
menu_options_t *m_options;
|
||||
};
|
9
components/insa/include/ui/SettingsMenu.h
Normal file
9
components/insa/include/ui/SettingsMenu.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/PSMenu.h"
|
||||
|
||||
class SettingsMenu final : public PSMenu
|
||||
{
|
||||
public:
|
||||
explicit SettingsMenu(menu_options_t *options);
|
||||
};
|
15
components/insa/include/ui/SplashScreen.h
Normal file
15
components/insa/include/ui/SplashScreen.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "MenuOptions.h"
|
||||
#include "common/Widget.h"
|
||||
|
||||
class SplashScreen final : public Widget
|
||||
{
|
||||
public:
|
||||
explicit SplashScreen(menu_options_t *options);
|
||||
void update(uint64_t dt) override;
|
||||
void render() override;
|
||||
|
||||
private:
|
||||
menu_options_t *m_options;
|
||||
};
|
207
components/insa/src/common/PSMenu.cpp
Normal file
207
components/insa/src/common/PSMenu.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
#include "common/PSMenu.h"
|
||||
|
||||
#include "PushButton.h"
|
||||
#include "common/ScrollBar.h"
|
||||
#include "u8g2.h"
|
||||
|
||||
PSMenu::PSMenu(menu_options_t *options) : Widget(options->u8g2), m_options(options)
|
||||
{
|
||||
m_options->onButtonClicked = [this](const uint8_t button) {
|
||||
onButtonClicked(button);
|
||||
};
|
||||
}
|
||||
|
||||
PSMenu::~PSMenu()
|
||||
{
|
||||
m_options->onButtonClicked = nullptr;
|
||||
}
|
||||
|
||||
void PSMenu::render()
|
||||
{
|
||||
if (m_selected_item < 0)
|
||||
{
|
||||
onPressedDown();
|
||||
}
|
||||
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
u8g2_DrawBox(u8g2, 0, 0, u8g2->width, u8g2->height);
|
||||
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
|
||||
drawScrollBar();
|
||||
drawSelectionBox();
|
||||
|
||||
int x = 8; // sure?
|
||||
auto widget = m_items.at(m_selected_item);
|
||||
renderWidget(&widget, u8g2_font_helvB08_tr, x, u8g2->height / 2 + 3);
|
||||
|
||||
if (m_selected_item > 0)
|
||||
{
|
||||
auto item = m_items.at(m_selected_item - 1);
|
||||
renderWidget(&item, u8g2_font_haxrcorp4089_tr, x, 14);
|
||||
}
|
||||
if (m_selected_item < m_items.size() - 1)
|
||||
{
|
||||
auto item = m_items.at(m_selected_item + 1);
|
||||
renderWidget(&item, u8g2_font_haxrcorp4089_tr, x, u8g2->height - 10);
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::renderWidget(const MenuItem *item, const uint8_t *font, const int x, const int y) const
|
||||
{
|
||||
u8g2_SetFont(u8g2, font);
|
||||
u8g2_DrawStr(u8g2, x, y, item->getText().c_str());
|
||||
switch (item->getType())
|
||||
{
|
||||
case 1: // Selection
|
||||
{
|
||||
std::string value = "< ";
|
||||
value += item->getValue();
|
||||
value += " >";
|
||||
const u8g2_uint_t w = u8g2_GetStrWidth(u8g2, value.c_str());
|
||||
u8g2_DrawStr(u8g2, u8g2->width - w - 10, y, value.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: // toggle
|
||||
{
|
||||
u8g2_DrawFrame(u8g2, u8g2->width - 24, y - 11, 14, 14);
|
||||
if (strcmp(item->getValue().c_str(), "true") == 0)
|
||||
{
|
||||
u8g2_DrawLine(u8g2, u8g2->width - 22, y - 9, u8g2->width - 13, y);
|
||||
u8g2_DrawLine(u8g2, u8g2->width - 22, y, u8g2->width - 13, y - 9);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::onButtonClicked(const uint8_t button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case BUTTON_UP:
|
||||
onPressedUp();
|
||||
break;
|
||||
|
||||
case BUTTON_DOWN:
|
||||
onPressedDown();
|
||||
break;
|
||||
|
||||
case BUTTON_LEFT:
|
||||
onPressedLeft();
|
||||
break;
|
||||
|
||||
case BUTTON_RIGHT:
|
||||
onPressedRight();
|
||||
break;
|
||||
|
||||
case BUTTON_SELECT:
|
||||
onPressedSelect();
|
||||
break;
|
||||
|
||||
case BUTTON_BACK:
|
||||
onPressedBack();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::onPressedDown()
|
||||
{
|
||||
if (m_selected_item == m_items.size() - 1)
|
||||
{
|
||||
m_selected_item = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selected_item++;
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::onPressedUp()
|
||||
{
|
||||
if (m_selected_item == 0)
|
||||
{
|
||||
m_selected_item = m_items.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selected_item--;
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::onPressedLeft() const
|
||||
{
|
||||
const auto item = m_items.at(m_selected_item);
|
||||
item.onButtonPressed(item.getId(), ButtonType::LEFT);
|
||||
}
|
||||
|
||||
void PSMenu::onPressedRight() const
|
||||
{
|
||||
const auto item = m_items.at(m_selected_item);
|
||||
item.onButtonPressed(item.getId(), ButtonType::RIGHT);
|
||||
}
|
||||
|
||||
void PSMenu::onPressedSelect() const
|
||||
{
|
||||
const auto item = m_items.at(m_selected_item);
|
||||
item.onButtonPressed(item.getId(), ButtonType::SELECT);
|
||||
}
|
||||
|
||||
void PSMenu::onPressedBack() const
|
||||
{
|
||||
if (m_options && m_options->popScreen)
|
||||
{
|
||||
m_options->popScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void PSMenu::addText(uint8_t id, const std::string &text, const ButtonCallback &callback)
|
||||
{
|
||||
m_items.emplace_back(id, 0, text, callback);
|
||||
}
|
||||
|
||||
void PSMenu::addSelection(uint8_t id, const std::string &text, std::string &value,
|
||||
const std::vector<std::string> &values,
|
||||
const ButtonCallback &callback)
|
||||
{
|
||||
m_items.emplace_back(id, 1, text, value, values, callback);
|
||||
}
|
||||
|
||||
void PSMenu::addNumber(uint8_t id, const std::string &text, std::string &value, const ButtonCallback &callback)
|
||||
{
|
||||
m_items.emplace_back(id, 2, text, value, callback);
|
||||
}
|
||||
|
||||
void PSMenu::addToggle(uint8_t id, const std::string &text, bool selected, const ButtonCallback &callback)
|
||||
{
|
||||
m_items.emplace_back(id, 3, text, selected, callback);
|
||||
}
|
||||
|
||||
void PSMenu::drawScrollBar() const
|
||||
{
|
||||
ScrollBar scrollBar(m_options, u8g2->width - 3, 3, 1, u8g2->height - 6);
|
||||
scrollBar.refresh(m_selected_item, m_items.size());
|
||||
scrollBar.render();
|
||||
}
|
||||
|
||||
void PSMenu::drawSelectionBox() const
|
||||
{
|
||||
const auto displayHeight = u8g2->height;
|
||||
const auto displayWidth = u8g2->width;
|
||||
constexpr auto rightPadding = 8;
|
||||
const auto boxHeight = displayHeight / 3;
|
||||
const auto y = boxHeight * 2 - 2;
|
||||
const auto x = displayWidth - rightPadding;
|
||||
|
||||
u8g2_DrawRFrame(u8g2, 2, boxHeight, displayWidth - rightPadding, boxHeight, 3);
|
||||
u8g2_DrawLine(u8g2, 4, y, displayWidth - rightPadding, y);
|
||||
u8g2_DrawLine(u8g2, x, y - boxHeight + 3, x, y - 1);
|
||||
}
|
36
components/insa/src/common/ScrollBar.cpp
Normal file
36
components/insa/src/common/ScrollBar.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "common/ScrollBar.h"
|
||||
|
||||
ScrollBar::ScrollBar(const menu_options_t *options, const size_t x, const size_t y, const size_t width,
|
||||
const size_t height)
|
||||
: Widget(options->u8g2), m_x(x), m_y(y), m_width(width), m_height(height), m_value(0), m_max(0), m_min(0),
|
||||
m_thumbHeight(0), m_thumbY(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollBar::render()
|
||||
{
|
||||
if (1 == m_max)
|
||||
return;
|
||||
|
||||
// draw dotted line
|
||||
for (size_t y = m_y; y < m_y + m_height; y++)
|
||||
{
|
||||
if (y % 2 == 0)
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, m_x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// draw thumb
|
||||
u8g2_DrawBox(u8g2, u8g2->width - 4, m_thumbY, 3, m_thumbHeight);
|
||||
}
|
||||
|
||||
void ScrollBar::refresh(const size_t value, const size_t max, const size_t min)
|
||||
{
|
||||
m_value = value;
|
||||
m_max = max;
|
||||
m_min = min;
|
||||
|
||||
m_thumbHeight = m_height / m_max;
|
||||
m_thumbY = m_y + (m_value - m_min) * m_thumbHeight;
|
||||
}
|
17
components/insa/src/common/Widget.cpp
Normal file
17
components/insa/src/common/Widget.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "common/Widget.h"
|
||||
|
||||
Widget::Widget(u8g2_t *u8g2) : u8g2(u8g2)
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::update(uint64_t dt)
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::render()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::onButtonClicked(uint8_t button)
|
||||
{
|
||||
}
|
65
components/insa/src/data/MenuItem.cpp
Normal file
65
components/insa/src/data/MenuItem.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "data/MenuItem.h"
|
||||
|
||||
MenuItem::MenuItem(const uint8_t id, const uint8_t type, std::string text, ButtonCallback callback)
|
||||
: m_id(id), m_type(type), m_text(std::move(text)), m_callback(std::move(callback))
|
||||
{
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(const uint8_t id, const uint8_t type, std::string text, std::string value,
|
||||
ButtonCallback callback)
|
||||
: m_id(id), m_type(type), m_text(std::move(text)), m_value(std::move(value)), m_callback(std::move(callback))
|
||||
{
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(const uint8_t id, const uint8_t type, std::string text, std::string value,
|
||||
std::vector<std::string> values,
|
||||
ButtonCallback callback)
|
||||
: m_id(id), m_type(type), m_text(std::move(text)), m_value(std::move(value)), m_values(std::move(values)),
|
||||
m_callback(std::move(callback))
|
||||
{
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(const uint8_t id, const uint8_t type, std::string text, const bool selected,
|
||||
ButtonCallback callback)
|
||||
: m_id(id), m_type(type), m_text(std::move(text)), m_value(selected ? "true" : "false"),
|
||||
m_callback(std::move(callback))
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t MenuItem::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
uint8_t MenuItem::getType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const std::string &MenuItem::getText() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
const std::string &MenuItem::getValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void MenuItem::setValue(const std::string &value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
void MenuItem::onButtonPressed(const uint8_t id, const ButtonType button) const
|
||||
{
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback(id, button);
|
||||
}
|
||||
}
|
||||
|
||||
bool MenuItem::hasCallback() const
|
||||
{
|
||||
return (m_callback != nullptr);
|
||||
}
|
36
components/insa/src/ui/LightMenu.cpp
Normal file
36
components/insa/src/ui/LightMenu.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "ui/LightMenu.h"
|
||||
|
||||
LightMenu::LightMenu(menu_options_t *options) : PSMenu(options), m_options(options)
|
||||
{
|
||||
std::vector<std::string> values;
|
||||
values.emplace_back("Tag");
|
||||
values.emplace_back("Nacht");
|
||||
addSelection(1, "Modus", values.front(), values, [this](const uint8_t id, const ButtonType button) {
|
||||
onButtonPressed(id, button);
|
||||
});
|
||||
|
||||
addText(2, "LED Einstellungen", [this](const uint8_t id, const ButtonType button) {
|
||||
onButtonPressed(id, button);
|
||||
});
|
||||
|
||||
addToggle(3, "Toggle", false, nullptr);
|
||||
}
|
||||
|
||||
void LightMenu::onButtonPressed(const uint8_t id, const ButtonType button) const
|
||||
{
|
||||
std::shared_ptr<Widget> widget;
|
||||
switch (id)
|
||||
{
|
||||
case 2:
|
||||
widget = std::make_shared<LightMenu>(m_options);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_options && m_options->pushScreen)
|
||||
{
|
||||
m_options->pushScreen(widget);
|
||||
}
|
||||
}
|
40
components/insa/src/ui/MainMenu.cpp
Normal file
40
components/insa/src/ui/MainMenu.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "ui/MainMenu.h"
|
||||
|
||||
#include "common/Widget.h"
|
||||
#include "ui/LightMenu.h"
|
||||
#include "ui/SettingsMenu.h"
|
||||
|
||||
MainMenu::MainMenu(menu_options_t *options) : PSMenu(options), m_options(options)
|
||||
{
|
||||
addText(1, "Lichtsteuerung", [this](const uint8_t id, const ButtonType button) {
|
||||
onButtonPressed(id, button);
|
||||
});
|
||||
addText(2, "externe Geraete", [this](const uint8_t id, const ButtonType button) {
|
||||
onButtonPressed(id, button);
|
||||
});
|
||||
addText(3, "Einstellungen", [this](const uint8_t id, const ButtonType button) {
|
||||
onButtonPressed(id, button);
|
||||
});
|
||||
}
|
||||
|
||||
void MainMenu::onButtonPressed(const uint8_t id, const ButtonType button) const
|
||||
{
|
||||
std::shared_ptr<Widget> widget;
|
||||
switch (id)
|
||||
{
|
||||
case 1:
|
||||
widget = std::make_shared<LightMenu>(m_options);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
widget = std::make_shared<SettingsMenu>(m_options);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_options && m_options->pushScreen)
|
||||
{
|
||||
m_options->pushScreen(widget);
|
||||
}
|
||||
}
|
11
components/insa/src/ui/SettingsMenu.cpp
Normal file
11
components/insa/src/ui/SettingsMenu.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "ui/SettingsMenu.h"
|
||||
|
||||
void demo(uint8_t id, ButtonType button)
|
||||
{
|
||||
///
|
||||
}
|
||||
|
||||
SettingsMenu::SettingsMenu(menu_options_t *options) : PSMenu(options)
|
||||
{
|
||||
addText(1, "OTA Einspielen", demo);
|
||||
}
|
40
components/insa/src/ui/SplashScreen.cpp
Normal file
40
components/insa/src/ui/SplashScreen.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "ui/SplashScreen.h"
|
||||
|
||||
#include "ui/MainMenu.h"
|
||||
|
||||
#ifdef ESP32
|
||||
#else
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
uint64_t counter = 0;
|
||||
|
||||
SplashScreen::SplashScreen(menu_options_t *options) : Widget(options->u8g2), m_options(options)
|
||||
{
|
||||
}
|
||||
|
||||
void SplashScreen::update(const uint64_t dt)
|
||||
{
|
||||
counter += dt;
|
||||
if (counter > 200000)
|
||||
{
|
||||
counter = 0;
|
||||
if (m_options && m_options->setScreen)
|
||||
{
|
||||
m_options->setScreen(std::make_shared<MainMenu>(m_options));
|
||||
}
|
||||
}
|
||||
#ifndef ESP32
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
#endif
|
||||
}
|
||||
|
||||
void SplashScreen::render()
|
||||
{
|
||||
u8g2_SetFont(u8g2, u8g2_font_DigitalDisco_tr);
|
||||
u8g2_DrawStr(u8g2, 28, u8g2->height / 2 - 10, "HO Anlage");
|
||||
u8g2_DrawStr(u8g2, 30, u8g2->height / 2 + 5, "Axel Janz");
|
||||
u8g2_SetFont(u8g2, u8g2_font_haxrcorp4089_tr);
|
||||
u8g2_DrawStr(u8g2, 35, 50, "Initialisierung...");
|
||||
}
|
Reference in New Issue
Block a user