Added graphs

This commit is contained in:
2021-11-02 16:11:37 +01:00
parent aad3fcedcb
commit db066968d2
6 changed files with 160 additions and 0 deletions

View File

@ -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

0
src/graphdisplay.cpp Normal file
View File

72
src/graphdisplay.h Normal file
View File

@ -0,0 +1,72 @@
#pragma once
// 3rdparty lib includes
#include <ring-buffer.h>
// local includes
#include "displaywithtitle.h"
#include "textinterface.h"
#include "widgets/label.h"
#include "widgets/graph.h"
#include "tftinstance.h"
namespace espgui {
template<size_t COUNT>
class GraphAccessorInterface
{
public:
virtual std::array<std::reference_wrapper<const ring_buffer<float, 200>>, COUNT> getBuffers() const = 0;
};
template<typename T>
class SingleGraphAccessor : public virtual GraphAccessorInterface<1>
{
public:
Graph<200, 1>::Container getBuffers() const
{
return {T{}.getBuffer()};
}
};
template<typename T1, typename T2>
class DualGraphAccessor : public virtual GraphAccessorInterface<2>
{
public:
Graph<200, 2>::Container getBuffers() const
{
return {T1{}.getBuffer(), T2{}.getBuffer()};
}
};
template<size_t COUNT>
class GraphDisplay :
public DisplayWithTitle,
public virtual GraphAccessorInterface<COUNT>
{
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<size_t COUNT>
void GraphDisplay<COUNT>::initScreen()
{
Base::initScreen();
m_graph.start(static_cast<const GraphAccessorInterface<COUNT> &>(*this).getBuffers());
}
template<size_t COUNT>
void GraphDisplay<COUNT>::redraw()
{
m_graph.redraw(static_cast<const GraphAccessorInterface<COUNT> &>(*this).getBuffers());
}
}

View File

83
src/splitgraphdisplay.h Normal file
View File

@ -0,0 +1,83 @@
#pragma once
#include "display.h"
#include "textinterface.h"
#include "widgets/label.h"
#include "widgets/graph.h"
namespace espgui {
template<std::size_t COUNT>
class TopGraphAccessorInterface
{
public:
virtual typename Graph<200, COUNT>::Container getTopBuffers() const = 0;
};
template<typename T>
class SingleTopGraphAccessor : public virtual TopGraphAccessorInterface<1>
{
public:
typename Graph<200, 1>::Container getTopBuffers() const override
{
return {T{}.getBuffer()};
}
};
template<std::size_t COUNT>
class BottomGraphAccessorInterface
{
public:
virtual typename Graph<200, COUNT>::Container getBottomBuffers() const = 0;
};
template<typename T>
class SingleBottomGraphAccessor : public virtual BottomGraphAccessorInterface<1>
{
public:
typename Graph<200, 1>::Container getBottomBuffers() const override
{
return {T{}.getBuffer()};
}
};
template<std::size_t COUNT0, std::size_t COUNT1>
class SplitGraphDisplay :
public Display,
public virtual TextInterface,
public virtual TopGraphAccessorInterface<COUNT0>,
public virtual BottomGraphAccessorInterface<COUNT1>
{
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<std::size_t COUNT0, std::size_t COUNT1>
void SplitGraphDisplay<COUNT0, COUNT1>::initScreen()
{
tft.fillScreen(TFT_BLACK);
m_titleLabel.start();
tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE);
m_graph0.start(static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers());
m_graph1.start(static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers());
}
template<std::size_t COUNT0, std::size_t COUNT1>
void SplitGraphDisplay<COUNT0, COUNT1>::redraw()
{
tft.setTextFont(4);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
m_titleLabel.redraw(text());
m_graph0.redraw(static_cast<const TopGraphAccessorInterface<COUNT0>&>(*this).getTopBuffers());
m_graph1.redraw(static_cast<const BottomGraphAccessorInterface<COUNT1>&>(*this).getBottomBuffers());
}
}

View File

@ -9,6 +9,7 @@
// local includes
#include "label.h"
#include "tftinstance.h"
namespace espgui {
template<size_t LENGTH, size_t COUNT>