From db066968d2eda57a3aea3cf44f3718a6bda0c371 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 2 Nov 2021 16:11:37 +0100 Subject: [PATCH] Added graphs --- CMakeLists.txt | 4 ++ src/graphdisplay.cpp | 0 src/graphdisplay.h | 72 +++++++++++++++++++++++++++++++++ src/splitgraphdisplay.cpp | 0 src/splitgraphdisplay.h | 83 +++++++++++++++++++++++++++++++++++++++ src/widgets/graph.h | 1 + 6 files changed, 160 insertions(+) create mode 100644 src/graphdisplay.cpp create mode 100644 src/graphdisplay.h create mode 100644 src/splitgraphdisplay.cpp create mode 100644 src/splitgraphdisplay.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c9177c..ebdb301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,14 @@ set(headers src/display.h src/displaywithtitle.h src/fontinterface.h + src/graphdisplay.h src/icon.h src/iconinterface.h src/menudisplay.h src/menuitem.h src/richtextrenderer.h src/screenmanager.h + src/splitgraphdisplay.h src/tftinstance.h src/textinterface.h src/actions/backproxyaction.h @@ -41,8 +43,10 @@ set(sources src/changevaluedisplay_sntp_sync_mode_t.cpp src/display.cpp src/displaywithtitle.cpp + src/graphdisplay.cpp src/menudisplay.cpp src/screenmanager.cpp + src/splitgraphdisplay.cpp src/richtextrenderer.cpp src/tftinstance.cpp src/icons/back.cpp diff --git a/src/graphdisplay.cpp b/src/graphdisplay.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/graphdisplay.h b/src/graphdisplay.h new file mode 100644 index 0000000..c605688 --- /dev/null +++ b/src/graphdisplay.h @@ -0,0 +1,72 @@ +#pragma once + +// 3rdparty lib includes +#include + +// local includes +#include "displaywithtitle.h" +#include "textinterface.h" +#include "widgets/label.h" +#include "widgets/graph.h" +#include "tftinstance.h" + +namespace espgui { +template +class GraphAccessorInterface +{ +public: + virtual std::array>, COUNT> getBuffers() const = 0; +}; + +template +class SingleGraphAccessor : public virtual GraphAccessorInterface<1> +{ +public: + Graph<200, 1>::Container getBuffers() const + { + return {T{}.getBuffer()}; + } +}; + +template +class DualGraphAccessor : public virtual GraphAccessorInterface<2> +{ +public: + Graph<200, 2>::Container getBuffers() const + { + return {T1{}.getBuffer(), T2{}.getBuffer()}; + } +}; + +template +class GraphDisplay : + public DisplayWithTitle, + public virtual GraphAccessorInterface +{ + using Base = DisplayWithTitle; + +public: + void initScreen() override; + void redraw() override; + +private: + static constexpr int screenHeight = 320, topMargin = 40, bottomMargin = 10, labelOffset = -5; + static constexpr int graphHeight = screenHeight-topMargin-bottomMargin; + + Graph<200, COUNT> m_graph{0, 40, 270}; +}; + +template +void GraphDisplay::initScreen() +{ + Base::initScreen(); + + m_graph.start(static_cast &>(*this).getBuffers()); +} + +template +void GraphDisplay::redraw() +{ + m_graph.redraw(static_cast &>(*this).getBuffers()); +} +} diff --git a/src/splitgraphdisplay.cpp b/src/splitgraphdisplay.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/splitgraphdisplay.h b/src/splitgraphdisplay.h new file mode 100644 index 0000000..cc42ed9 --- /dev/null +++ b/src/splitgraphdisplay.h @@ -0,0 +1,83 @@ +#pragma once + +#include "display.h" +#include "textinterface.h" +#include "widgets/label.h" +#include "widgets/graph.h" + +namespace espgui { +template +class TopGraphAccessorInterface +{ +public: + virtual typename Graph<200, COUNT>::Container getTopBuffers() const = 0; +}; + +template +class SingleTopGraphAccessor : public virtual TopGraphAccessorInterface<1> +{ +public: + typename Graph<200, 1>::Container getTopBuffers() const override + { + return {T{}.getBuffer()}; + } +}; + +template +class BottomGraphAccessorInterface +{ +public: + virtual typename Graph<200, COUNT>::Container getBottomBuffers() const = 0; +}; + +template +class SingleBottomGraphAccessor : public virtual BottomGraphAccessorInterface<1> +{ +public: + typename Graph<200, 1>::Container getBottomBuffers() const override + { + return {T{}.getBuffer()}; + } +}; + +template +class SplitGraphDisplay : + public Display, + public virtual TextInterface, + public virtual TopGraphAccessorInterface, + public virtual BottomGraphAccessorInterface +{ +public: + void initScreen() override; + void redraw() override; + +private: + Label m_titleLabel{5, 5}; // 230, 25 + + Graph<200, COUNT0> m_graph0{0, 40, 133}; + Graph<200, COUNT1> m_graph1{0, 179, 133}; +}; + +template +void SplitGraphDisplay::initScreen() +{ + tft.fillScreen(TFT_BLACK); + + m_titleLabel.start(); + tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); + + m_graph0.start(static_cast&>(*this).getTopBuffers()); + m_graph1.start(static_cast&>(*this).getBottomBuffers()); +} + +template +void SplitGraphDisplay::redraw() +{ + tft.setTextFont(4); + tft.setTextColor(TFT_YELLOW, TFT_BLACK); + m_titleLabel.redraw(text()); + + m_graph0.redraw(static_cast&>(*this).getTopBuffers()); + m_graph1.redraw(static_cast&>(*this).getBottomBuffers()); +} +} diff --git a/src/widgets/graph.h b/src/widgets/graph.h index 117e11b..192c874 100644 --- a/src/widgets/graph.h +++ b/src/widgets/graph.h @@ -9,6 +9,7 @@ // local includes #include "label.h" +#include "tftinstance.h" namespace espgui { template