Files
bobbycar-boardcomputer-firm…/main/displays/menus/graphsmenu.cpp

225 lines
10 KiB
C++
Raw Normal View History

2021-11-02 16:11:57 +01:00
#include "graphsmenu.h"
// 3rdparty lib includes
2022-03-05 22:58:57 +01:00
#include "actions/pushscreenaction.h"
#include "actions/popscreenaction.h"
2021-11-02 16:11:57 +01:00
#include "icons/back.h"
#include "graphdisplay.h"
#include "splitgraphdisplay.h"
// local includes
2021-12-28 13:08:54 +01:00
#include "displays/bobbygraphdisplay.h"
#include "displays/bobbysplitgraphdisplay.h"
2021-11-02 16:11:57 +01:00
#include "utils.h"
#include "statistics.h"
namespace {
2021-12-30 03:17:30 +01:00
constexpr char TEXT_GRAPHS[] = "Graphs";
2022-10-21 21:18:31 +02:00
constexpr char TEXT_RAW_GAS[] = "Raw Gas";
constexpr char TEXT_RAW_BREMS[] = "Raw Brems";
2021-12-30 03:17:30 +01:00
constexpr char TEXT_GAS[] = "Gas";
constexpr char TEXT_BREMS[] = "Brems";
constexpr char TEXT_POTIS[] = "Potis";
constexpr char TEXT_AVGSPEED[] = "Avg. speed";
constexpr char TEXT_AVGSPEEDKMH[] = "Avg. speed KMH";
constexpr char TEXT_SUMCURRENT[] = "Sum current";
constexpr char TEXT_FRONTVOLTAGE[] = "Front voltage";
constexpr char TEXT_BACKVOLTAGE[] = "Back voltage";
constexpr char TEXT_VOLTAGES[] = "Voltages";
constexpr char TEXT_BMSVOLTAGE[] = "BMS voltage";
constexpr char TEXT_BMSCURRENT[] = "BMS current";
constexpr char TEXT_BMSPOWER[] = "BMS power";
constexpr char TEXT_SUMCURRENTSCOMPARISON[] = "Sum currents comparison";
constexpr char TEXT_MOTORCURRENTS[] = "Motor currents";
constexpr char TEXT_RSSI[] = "RSSI";
constexpr char TEXT_BACK[] = "Back";
2022-10-21 21:18:31 +02:00
using RawGasGraphDisplay = espgui::makeComponent<
BobbyGraphDisplay<1>,
espgui::StaticText<TEXT_RAW_GAS>,
espgui::SingleGraphAccessor<RawGasStatistics>,
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
using RawBremsGraphDisplay = espgui::makeComponent<
BobbyGraphDisplay<1>,
espgui::StaticText<TEXT_RAW_BREMS>,
espgui::SingleGraphAccessor<RawBremsStatistics>,
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
2021-11-02 16:11:57 +01:00
using GasGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_GAS>,
espgui::SingleGraphAccessor<GasStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using BremsGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_BREMS>,
espgui::SingleGraphAccessor<BremsStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using PotisGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<2>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_POTIS>,
espgui::DualGraphAccessor<GasStatistics, BremsStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using PotisSplitGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbySplitGraphDisplay<1, 1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_POTIS>,
espgui::SingleTopGraphAccessor<GasStatistics>,
espgui::SingleBottomGraphAccessor<BremsStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using AvgSpeedGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_AVGSPEED>,
espgui::SingleGraphAccessor<AvgSpeedStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using AvgSpeedKmhGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_AVGSPEEDKMH>,
espgui::SingleGraphAccessor<AvgSpeedKmhStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using SumCurrentGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_SUMCURRENT>,
espgui::SingleGraphAccessor<SumCurrentStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using FrontVoltageGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_FRONTVOLTAGE>,
espgui::SingleGraphAccessor<FrontVoltageStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using BackVoltageGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_BACKVOLTAGE>,
espgui::SingleGraphAccessor<BackVoltageStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using VoltagesGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<2>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_VOLTAGES>,
espgui::DualGraphAccessor<FrontVoltageStatistics, BackVoltageStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using VoltagesSplitGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbySplitGraphDisplay<1, 1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_VOLTAGES>,
espgui::SingleTopGraphAccessor<FrontVoltageStatistics>,
espgui::SingleBottomGraphAccessor<BackVoltageStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
#ifdef FEATURE_BMS
using BmsVoltageGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_BMSVOLTAGE>,
espgui::SingleGraphAccessor<BmsVoltageStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using BmsCurrentGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_BMSCURRENT>,
espgui::SingleGraphAccessor<BmsCurrentStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using BmsPowerGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_BMSPOWER>,
espgui::SingleGraphAccessor<BmsPowerStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using SumCurrentsComparisonGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<2>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_SUMCURRENTSCOMPARISON>,
DualGraphAccessor<SumCurrentStatistics, BmsCurrentStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
#endif
class MotorCurrentsStatistics : public virtual espgui::GraphAccessorInterface<4>
{
std::array<std::reference_wrapper<const statistics::ContainerType>, 4> getBuffers() const override
{
return {FrontLeftCurrentStatistics{}.getBuffer(), FrontRightCurrentStatistics{}.getBuffer(), BackLeftCurrentStatistics{}.getBuffer(), BackRightCurrentStatistics{}.getBuffer()};
}
};
using MotorCurrentsGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<4>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_MOTORCURRENTS>,
MotorCurrentsStatistics,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
using RssiGraphDisplay = espgui::makeComponent<
2021-12-28 13:08:54 +01:00
BobbyGraphDisplay<1>,
2021-11-02 16:11:57 +01:00
espgui::StaticText<TEXT_RSSI>,
espgui::SingleGraphAccessor<RssiStatistics>,
2022-03-05 22:58:57 +01:00
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
2021-11-02 16:11:57 +01:00
>;
} // namespace
GraphsMenu::GraphsMenu()
{
2021-12-30 03:17:30 +01:00
using namespace espgui;
2022-10-21 21:18:31 +02:00
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_RAW_GAS>, PushScreenAction<RawGasGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_RAW_BREMS>, PushScreenAction<RawBremsGraphDisplay>>>();
2022-03-05 22:58:57 +01:00
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_GAS>, PushScreenAction<GasGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BREMS>, PushScreenAction<BremsGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POTIS>, PushScreenAction<PotisGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POTIS>, PushScreenAction<PotisSplitGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AVGSPEED>, PushScreenAction<AvgSpeedGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AVGSPEEDKMH>, PushScreenAction<AvgSpeedKmhGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SUMCURRENT>, PushScreenAction<SumCurrentGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_FRONTVOLTAGE>, PushScreenAction<FrontVoltageGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACKVOLTAGE>, PushScreenAction<BackVoltageGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_VOLTAGES>, PushScreenAction<VoltagesGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_VOLTAGES>, PushScreenAction<VoltagesSplitGraphDisplay>>>();
2021-11-02 16:11:57 +01:00
#ifdef FEATURE_BMS
2022-03-05 22:58:57 +01:00
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BMSVOLTAGE>, PushScreenAction<BmsVoltageGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BMSCURRENT>, PushScreenAction<BmsCurrentGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BMSPOWER>, PushScreenAction<BmsPowerGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SUMCURRENTSCOMPARISON>, PushScreenAction<SumCurrentsComparisonGraphDisplay>>>();
2021-11-02 16:11:57 +01:00
#endif
2022-03-05 22:58:57 +01:00
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MOTORCURRENTS>, PushScreenAction<MotorCurrentsGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_RSSI>, PushScreenAction<RssiGraphDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, PopScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>();
2021-11-02 16:11:57 +01:00
}
2023-08-14 15:34:31 +02:00
std::string GraphsMenu::title() const
2021-12-30 03:17:30 +01:00
{
return TEXT_GRAPHS;
}
2021-11-02 16:11:57 +01:00
void GraphsMenu::back()
{
2022-03-05 22:58:57 +01:00
espgui::popScreen();
2021-11-02 16:11:57 +01:00
}