measurement mode partially implemented
This commit is contained in:
committed by
CommanderRedYT
parent
e6ddc39177
commit
a0b678de9d
@@ -75,6 +75,7 @@ set(headers
|
|||||||
displays/buttoncalibratedisplay.h
|
displays/buttoncalibratedisplay.h
|
||||||
displays/calibratevoltagedisplay.h
|
displays/calibratevoltagedisplay.h
|
||||||
displays/confiscationdisplay.h
|
displays/confiscationdisplay.h
|
||||||
|
displays/measurementdisplay.h
|
||||||
displays/gameoflifedisplay.h
|
displays/gameoflifedisplay.h
|
||||||
displays/gametrakcalibratedisplay.h
|
displays/gametrakcalibratedisplay.h
|
||||||
displays/joystickdebugdisplay.h
|
displays/joystickdebugdisplay.h
|
||||||
@@ -328,6 +329,7 @@ set(sources
|
|||||||
displays/buttoncalibratedisplay.cpp
|
displays/buttoncalibratedisplay.cpp
|
||||||
displays/calibratevoltagedisplay.cpp
|
displays/calibratevoltagedisplay.cpp
|
||||||
displays/confiscationdisplay.cpp
|
displays/confiscationdisplay.cpp
|
||||||
|
displays/measurementdisplay.cpp
|
||||||
displays/gameoflifedisplay.cpp
|
displays/gameoflifedisplay.cpp
|
||||||
displays/gametrakcalibratedisplay.cpp
|
displays/gametrakcalibratedisplay.cpp
|
||||||
displays/joystickdebugdisplay.cpp
|
displays/joystickdebugdisplay.cpp
|
||||||
|
@@ -218,6 +218,9 @@ template<uint8_t index>
|
|||||||
struct LockscreenPinDigitAccessor : public NewSettingsAccessor<int8_t> { ConfigWrapper<int8_t> &getConfig() const override { return configs.lockscreen.pin[index]; } };
|
struct LockscreenPinDigitAccessor : public NewSettingsAccessor<int8_t> { ConfigWrapper<int8_t> &getConfig() const override { return configs.lockscreen.pin[index]; } };
|
||||||
struct LockscreenKeepLockedAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.lockscreen.keepLockedAfterReboot; } };
|
struct LockscreenKeepLockedAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.lockscreen.keepLockedAfterReboot; } };
|
||||||
|
|
||||||
|
// MeasurementMode
|
||||||
|
struct MeasurementIntervalAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.measurementMode.measurementInterval; } };
|
||||||
|
|
||||||
// Handbremse
|
// Handbremse
|
||||||
struct HandbremsEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.handbremse.enable; } };
|
struct HandbremsEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.handbremse.enable; } };
|
||||||
struct HandbremsModeAccessor : public NewSettingsAccessor<HandbremseMode> { ConfigWrapper<HandbremseMode> &getConfig() const override { return configs.handbremse.mode; } };
|
struct HandbremsModeAccessor : public NewSettingsAccessor<HandbremseMode> { ConfigWrapper<HandbremseMode> &getConfig() const override { return configs.handbremse.mode; } };
|
||||||
|
149
main/displays/measurementdisplay.cpp
Normal file
149
main/displays/measurementdisplay.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#include "measurementdisplay.h"
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <menuitem.h>
|
||||||
|
#include <actions/pushscreenaction.h>
|
||||||
|
#include <actions/popscreenaction.h>
|
||||||
|
#include <icons/back.h>
|
||||||
|
#include <screenmanager.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <strutils.h>
|
||||||
|
#include <espchrono.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "displays/bobbychangevaluedisplay.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
#include "drivingstatistics.h"
|
||||||
|
#include "accessors/settingsaccessors.h"
|
||||||
|
#include "bobbycheckbox.h"
|
||||||
|
|
||||||
|
using namespace espgui;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr char TEXT_INTERVAL[] = "Set interval";
|
||||||
|
constexpr char TEXT_INTERVAL_KMH[] = "km/h Measurement Interval";
|
||||||
|
constexpr char TEXT_CLEARRESULTS[] = "Start Measurement";
|
||||||
|
constexpr char TEXT_ACCELERATION[] = "Show Acceleration";
|
||||||
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
|
bool showAcceleration;
|
||||||
|
struct ShowAccelerationAccessor : espgui::RefAccessor<bool> { bool &getRef() const override { return showAcceleration; } };
|
||||||
|
|
||||||
|
|
||||||
|
class ClearMeasurementsAction : public virtual espgui::ActionInterface {
|
||||||
|
public:
|
||||||
|
void triggered() override {
|
||||||
|
//TODO: call clearMeasurements()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MeasurementDisplayItem : public MenuItem {
|
||||||
|
public:
|
||||||
|
MeasurementDisplayItem(const MeasurementDisplay::Result result) : m_result{result} {}
|
||||||
|
|
||||||
|
void triggered() override;
|
||||||
|
|
||||||
|
std::string text() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MeasurementDisplay::Result m_result;
|
||||||
|
};
|
||||||
|
|
||||||
|
void MeasurementDisplayItem::triggered()
|
||||||
|
{
|
||||||
|
//pushScreen<MeasurementDetails>(m_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MeasurementDisplayItem::text() const
|
||||||
|
{
|
||||||
|
if(showAcceleration){
|
||||||
|
return fmt::format("{}: {}ms {:.2f}m/s² ", m_result.speed, m_result.time.count(),
|
||||||
|
m_result.speed / (m_result.time.count() * 1e-3));
|
||||||
|
}else{
|
||||||
|
return fmt::format("{}: {}ms {:.2f}m ", m_result.speed, m_result.time.count(), m_result.distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const size_t extraItemsAtBeginning = 3;
|
||||||
|
|
||||||
|
using MeasurementIntervalChangeScreen = espgui::makeComponent<
|
||||||
|
BobbyChangeValueDisplay<uint8_t>,
|
||||||
|
espgui::StaticText<TEXT_INTERVAL_KMH>,
|
||||||
|
MeasurementIntervalAccessor,
|
||||||
|
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
|
||||||
|
espgui::BackActionInterface<espgui::PopScreenAction>
|
||||||
|
>;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
MeasurementDisplay::MeasurementDisplay() {
|
||||||
|
clearMeasurements();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_INTERVAL>, PushScreenAction<MeasurementIntervalChangeScreen>>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CLEARRESULTS>, ClearMeasurementsAction>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ACCELERATION>, BobbyCheckbox, ShowAccelerationAccessor>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, PopScreenAction, StaticMenuItemIcon<&icons::back>>>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MeasurementDisplay::text() const {
|
||||||
|
return "Measurement Mode";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasurementDisplay::back() {
|
||||||
|
popScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasurementDisplay::start() {
|
||||||
|
Base::start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasurementDisplay::update() {
|
||||||
|
if (distance_at_line && !distance_at_start) {
|
||||||
|
if (drivingStatistics.meters_driven > *distance_at_line + 0.3) {
|
||||||
|
//start measurement
|
||||||
|
distance_at_start = drivingStatistics.meters_driven;
|
||||||
|
m_start_time = espchrono::millis_clock::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove excess menu items
|
||||||
|
if(menuItemCount() - extraItemsAtBeginning - 1 > m_results.size()) {
|
||||||
|
auto backButton = takeLastMenuItem();
|
||||||
|
while(menuItemCount() - extraItemsAtBeginning - 1 > m_results.size()) {
|
||||||
|
takeLastMenuItem();
|
||||||
|
}
|
||||||
|
emplaceMenuItem(std::move(backButton));
|
||||||
|
}
|
||||||
|
|
||||||
|
//take measurement and add menu items
|
||||||
|
while (distance_at_start && avgSpeedKmh + configs.measurementMode.measurementInterval.value() > m_max_speed) {
|
||||||
|
m_max_speed += configs.measurementMode.measurementInterval.value();
|
||||||
|
|
||||||
|
Result result = {
|
||||||
|
.time = std::chrono::floor<std::chrono::milliseconds>(espchrono::millis_clock::now() - *m_start_time),
|
||||||
|
.distance = drivingStatistics.meters_driven - *distance_at_start,
|
||||||
|
.speed = m_max_speed
|
||||||
|
};
|
||||||
|
m_results.push_back(result);
|
||||||
|
|
||||||
|
auto backButton = takeLastMenuItem();
|
||||||
|
constructMenuItem<MeasurementDisplayItem>(result);
|
||||||
|
emplaceMenuItem(std::move(backButton));
|
||||||
|
}
|
||||||
|
|
||||||
|
Base::update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasurementDisplay::clearMeasurements() {
|
||||||
|
distance_at_line = drivingStatistics.meters_driven;
|
||||||
|
distance_at_start = std::nullopt;
|
||||||
|
m_max_speed = 0;
|
||||||
|
m_start_time = std::nullopt;
|
||||||
|
}
|
||||||
|
|
42
main/displays/measurementdisplay.h
Normal file
42
main/displays/measurementdisplay.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <widgets/label.h>
|
||||||
|
#include <widgets/progressbar.h>
|
||||||
|
#include <espchrono.h>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "bobbydisplaywithtitle.h"
|
||||||
|
#include "modes/ignoreinputmode.h"
|
||||||
|
#include "bobbymenudisplay.h"
|
||||||
|
|
||||||
|
class MeasurementDisplay : public BobbyMenuDisplay
|
||||||
|
{
|
||||||
|
using Base = BobbyMenuDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MeasurementDisplay();
|
||||||
|
|
||||||
|
std::string text() const override;
|
||||||
|
|
||||||
|
void back() override;
|
||||||
|
void start() override;
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
|
||||||
|
void clearMeasurements();
|
||||||
|
|
||||||
|
struct Result {
|
||||||
|
std::chrono::milliseconds time;
|
||||||
|
float distance;
|
||||||
|
float speed;
|
||||||
|
};
|
||||||
|
std::vector<Result> m_results;
|
||||||
|
|
||||||
|
std::optional<float> distance_at_line; // measurement should start af 0.30m from starting line https://en.wikipedia.org/wiki/Rollout_(drag_racing)
|
||||||
|
std::optional<float> distance_at_start;
|
||||||
|
|
||||||
|
std::optional<espchrono::millis_clock::time_point> m_start_time;
|
||||||
|
float m_max_speed;
|
||||||
|
};
|
@@ -27,6 +27,7 @@
|
|||||||
#include "displays/poweroffdisplay.h"
|
#include "displays/poweroffdisplay.h"
|
||||||
#include "displays/menus/statisticsmenu.h"
|
#include "displays/menus/statisticsmenu.h"
|
||||||
#include "displays/confiscationdisplay.h"
|
#include "displays/confiscationdisplay.h"
|
||||||
|
#include "displays/measurementdisplay.h"
|
||||||
#include "actions/rebootaction.h"
|
#include "actions/rebootaction.h"
|
||||||
#include "displays/menus/debugmenu.h"
|
#include "displays/menus/debugmenu.h"
|
||||||
#include "icons/battery.h"
|
#include "icons/battery.h"
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
#include "icons/greenpass.h"
|
#include "icons/greenpass.h"
|
||||||
#include "icons/time.h"
|
#include "icons/time.h"
|
||||||
#include "displays/statusdisplay.h"
|
#include "displays/statusdisplay.h"
|
||||||
|
#include "displays/measurementdisplay.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char TAG[] = "BOBBY";
|
constexpr char TAG[] = "BOBBY";
|
||||||
@@ -75,6 +77,7 @@ constexpr char TEXT_DEBUG[] = "Debug";
|
|||||||
constexpr char TEXT_BATTERY[] = "Battery";
|
constexpr char TEXT_BATTERY[] = "Battery";
|
||||||
constexpr char TEXT_BATTERYDEBUG[] = "Bat Debug Menu";
|
constexpr char TEXT_BATTERYDEBUG[] = "Bat Debug Menu";
|
||||||
constexpr char TEXT_CONFISCATIONMODE[] = "Confiscation Mode";
|
constexpr char TEXT_CONFISCATIONMODE[] = "Confiscation Mode";
|
||||||
|
constexpr char TEXT_MEASUREMENT[] = "Measurement Mode";
|
||||||
constexpr char TEXT_TOGGLECLOUDDEBUG[] = "Cloud Debug";
|
constexpr char TEXT_TOGGLECLOUDDEBUG[] = "Cloud Debug";
|
||||||
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles";
|
constexpr char TEXT_MANAGEPROFILESMENU[] = "Manage Profiles";
|
||||||
|
|
||||||
@@ -118,6 +121,7 @@ MainMenu::MainMenu()
|
|||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MANAGEPROFILESMENU>,PushScreenAction<ManageProfilesMenu>, StaticMenuItemIcon<&bobbyicons::presets>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MANAGEPROFILESMENU>,PushScreenAction<ManageProfilesMenu>, StaticMenuItemIcon<&bobbyicons::presets>>>(); }
|
||||||
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEBUG>, PushScreenAction<DebugMenu>>>(); }
|
if (SHOWITEM) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DEBUG>, PushScreenAction<DebugMenu>>>(); }
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POWEROFF>, PushScreenAction<PoweroffDisplay>, StaticMenuItemIcon<&bobbyicons::poweroff>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POWEROFF>, PushScreenAction<PoweroffDisplay>, StaticMenuItemIcon<&bobbyicons::poweroff>>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MEASUREMENT>, PushScreenAction<MeasurementDisplay>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CONFISCATIONMODE>, PushScreenAction<ConfiscationDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CONFISCATIONMODE>, PushScreenAction<ConfiscationDisplay>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_REBOOT>, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_REBOOT>, RebootAction, StaticMenuItemIcon<&bobbyicons::reboot>>>();
|
||||||
//#ifdef MAINMENU_PLUGIN
|
//#ifdef MAINMENU_PLUGIN
|
||||||
|
@@ -450,6 +450,12 @@ public:
|
|||||||
ConfigWrapperLegacy<uint32_t> totalCentimeters {0, DoReset, {}, "totalCentimeter" };
|
ConfigWrapperLegacy<uint32_t> totalCentimeters {0, DoReset, {}, "totalCentimeter" };
|
||||||
} savedStatistics;
|
} savedStatistics;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
ConfigWrapperLegacy<uint8_t> measurementInterval{1, DoReset, {}, "measurementiv" };
|
||||||
|
} measurementMode;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
ConfigWrapperLegacy<HandbremseMode> mode {HandbremseMode::MOSFETS_OFF, DoReset, {}, "handBremsM" };
|
ConfigWrapperLegacy<HandbremseMode> mode {HandbremseMode::MOSFETS_OFF, DoReset, {}, "handBremsM" };
|
||||||
ConfigWrapperLegacy<uint16_t> triggerTimeout {10, DoReset, {}, "handBremsT" };
|
ConfigWrapperLegacy<uint16_t> triggerTimeout {10, DoReset, {}, "handBremsT" };
|
||||||
@@ -781,6 +787,8 @@ public:
|
|||||||
\
|
\
|
||||||
x(savedStatistics.totalCentimeters) \
|
x(savedStatistics.totalCentimeters) \
|
||||||
\
|
\
|
||||||
|
x(measurementMode.measurementInterval) \
|
||||||
|
\
|
||||||
x(handbremse.mode) \
|
x(handbremse.mode) \
|
||||||
x(handbremse.triggerTimeout) \
|
x(handbremse.triggerTimeout) \
|
||||||
x(handbremse.automatic) \
|
x(handbremse.automatic) \
|
||||||
|
Reference in New Issue
Block a user