More tasks in task manager
This commit is contained in:
@ -179,10 +179,12 @@ set(headers
|
||||
mosfets.h
|
||||
newsettings.h
|
||||
ota.h
|
||||
potis.h
|
||||
presets.h
|
||||
qrimport.h
|
||||
rotary.h
|
||||
screens.h
|
||||
serial.h
|
||||
serialhandler.h
|
||||
settings.h
|
||||
settingspersister.h
|
||||
@ -392,10 +394,12 @@ set(sources
|
||||
mosfets.cpp
|
||||
newsettings.cpp
|
||||
ota.cpp
|
||||
potis.cpp
|
||||
presets.cpp
|
||||
qrimport.cpp
|
||||
rotary.cpp
|
||||
screens.cpp
|
||||
serial.cpp
|
||||
serialhandler.cpp
|
||||
settings.cpp
|
||||
settingspersister.cpp
|
||||
|
@ -125,7 +125,6 @@ struct GametrakYMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t
|
||||
struct GametrakDistMinAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.gametrakDistMin; } };
|
||||
struct GametrakDistMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.gametrakDistMax; } };
|
||||
#endif
|
||||
struct PotiReadRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.potiReadRate; } };
|
||||
struct ModeUpdateRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.modeUpdateRate; } };
|
||||
struct StatsUpdateRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.statsUpdateRate; } };
|
||||
struct DisplayUpdateRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.displayUpdateRate; } };
|
||||
|
@ -11,14 +11,6 @@
|
||||
using namespace espgui;
|
||||
|
||||
namespace {
|
||||
using PotiReadRateChangeDisplay = makeComponent<
|
||||
ChangeValueDisplay<int16_t>,
|
||||
StaticText<TEXT_POTIREADRATE>,
|
||||
PotiReadRateAccessor,
|
||||
BackActionInterface<SwitchScreenAction<TimersMenu>>,
|
||||
SwitchScreenAction<TimersMenu>
|
||||
>;
|
||||
|
||||
using ModeUpdateRateChangeDisplay = makeComponent<
|
||||
ChangeValueDisplay<int16_t>,
|
||||
StaticText<TEXT_MODEUPDATERATE>,
|
||||
@ -64,7 +56,6 @@ using CanReceiveRateChangeDisplay = makeComponent<
|
||||
|
||||
TimersMenu::TimersMenu()
|
||||
{
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POTIREADRATE>, SwitchScreenAction<PotiReadRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MODEUPDATERATE>, SwitchScreenAction<ModeUpdateRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STATSUPDATERATE>, SwitchScreenAction<StatsUpdateRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISPLAYUPDATERATE>, SwitchScreenAction<DisplayUpdateRateChangeDisplay>>>();
|
||||
|
@ -71,7 +71,6 @@ using namespace std::chrono_literals;
|
||||
#include "taskmanager.h"
|
||||
|
||||
namespace {
|
||||
std::optional<espchrono::millis_clock::time_point> lastPotiRead;
|
||||
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
||||
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
||||
std::optional<espchrono::millis_clock::time_point> lastDisplayUpdate;
|
||||
@ -250,14 +249,6 @@ extern "C" void app_main()
|
||||
for (auto &schedulerTask : schedulerTasks)
|
||||
{
|
||||
schedulerTask.loop();
|
||||
|
||||
}
|
||||
|
||||
if (!lastPotiRead || now - *lastPotiRead >= 1000ms/settings.boardcomputerHardware.timersSettings.potiReadRate)
|
||||
{
|
||||
readPotis();
|
||||
|
||||
lastPotiRead = now;
|
||||
}
|
||||
|
||||
if (!lastModeUpdate || now - *lastModeUpdate >= 1000ms/settings.boardcomputerHardware.timersSettings.modeUpdateRate)
|
||||
|
82
main/potis.cpp
Normal file
82
main/potis.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include "potis.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <Arduino.h>
|
||||
#include <cpputils.h>
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
|
||||
#ifdef FEATURE_CAN
|
||||
#include "can.h"
|
||||
#endif
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void initPotis()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void readPotis()
|
||||
{
|
||||
[[maybe_unused]]
|
||||
constexpr auto sampleMultipleTimes = [](int pin){
|
||||
analogRead(pin);
|
||||
double sum{};
|
||||
const auto sampleCount = settings.boardcomputerHardware.sampleCount;
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
sum += analogRead(pin);
|
||||
return sum / sampleCount;
|
||||
};
|
||||
|
||||
raw_gas = std::nullopt;
|
||||
raw_brems = std::nullopt;
|
||||
|
||||
#ifdef FEATURE_CAN
|
||||
const auto now = espchrono::millis_clock::now();
|
||||
|
||||
if (can::can_gas)
|
||||
{
|
||||
if (now - can::last_can_gas < 100ms)
|
||||
raw_gas = *can::can_gas;
|
||||
else
|
||||
can::can_gas = std::nullopt;
|
||||
}
|
||||
|
||||
if (can::can_brems)
|
||||
{
|
||||
if (now - can::last_can_brems < 100ms)
|
||||
raw_brems = *can::can_brems;
|
||||
else
|
||||
can::can_brems = std::nullopt;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_ADC_IN
|
||||
if (!raw_gas)
|
||||
raw_gas = sampleMultipleTimes(PINS_GAS);
|
||||
if (!raw_brems)
|
||||
raw_brems = sampleMultipleTimes(PINS_BREMS);
|
||||
#endif
|
||||
|
||||
if (raw_gas)
|
||||
gas = cpputils::mapValueClamped<float>(*raw_gas, settings.boardcomputerHardware.gasMin, settings.boardcomputerHardware.gasMax, 0., 1000.);
|
||||
else
|
||||
gas = std::nullopt;
|
||||
if (raw_brems)
|
||||
brems = cpputils::mapValueClamped<float>(*raw_brems, settings.boardcomputerHardware.bremsMin, settings.boardcomputerHardware.bremsMax, 0., 1000.);
|
||||
else
|
||||
brems = std::nullopt;
|
||||
|
||||
#ifdef FEATURE_GAMETRAK
|
||||
raw_gametrakX = sampleMultipleTimes(PINS_GAMETRAKX);
|
||||
gametrakX = cpputils::mapValueClamped<float>(raw_gametrakX, settings.boardcomputerHardware.gametrakXMin, settings.boardcomputerHardware.gametrakXMax, 0., 1000.);
|
||||
|
||||
raw_gametrakY = sampleMultipleTimes(PINS_GAMETRAKY);
|
||||
gametrakY = cpputils::mapValueClamped<float>(raw_gametrakY, settings.boardcomputerHardware.gametrakYMin, settings.boardcomputerHardware.gametrakYMax, 0., 1000.);
|
||||
|
||||
raw_gametrakDist = sampleMultipleTimes(PINS_GAMETRAKDIST);
|
||||
gametrakDist = cpputils::mapValueClamped<float>(raw_gametrakDist, settings.boardcomputerHardware.gametrakDistMin, settings.boardcomputerHardware.gametrakDistMax, 0., 1000.);
|
||||
#endif
|
||||
}
|
4
main/potis.h
Normal file
4
main/potis.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void initPotis();
|
||||
void readPotis();
|
@ -136,7 +136,6 @@ constexpr Settings::ControllerHardware spinnerControllerHardware {
|
||||
};
|
||||
|
||||
constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings {
|
||||
.potiReadRate = 50,
|
||||
.modeUpdateRate = 50,
|
||||
.statsUpdateRate = 50,
|
||||
.displayUpdateRate = 50,
|
||||
|
0
main/serial.cpp
Normal file
0
main/serial.cpp
Normal file
0
main/serial.h
Normal file
0
main/serial.h
Normal file
@ -103,7 +103,6 @@ struct Settings
|
||||
#endif
|
||||
|
||||
struct TimersSettings {
|
||||
int16_t potiReadRate;
|
||||
int16_t modeUpdateRate;
|
||||
int16_t statsUpdateRate;
|
||||
int16_t displayUpdateRate;
|
||||
@ -300,7 +299,6 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
||||
callable("gametrakDistMax", boardcomputerHardware.gametrakDistMax);
|
||||
#endif
|
||||
|
||||
callable("potiReadRate", boardcomputerHardware.timersSettings.potiReadRate);
|
||||
callable("modeUpdateRate", boardcomputerHardware.timersSettings.modeUpdateRate);
|
||||
callable("statsUpdateRate", boardcomputerHardware.timersSettings.statsUpdateRate);
|
||||
callable("displayUpdateRa", boardcomputerHardware.timersSettings.displayUpdateRate);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#ifdef FEATURE_NTP
|
||||
#include "time_bobbycar.h"
|
||||
#endif
|
||||
#include "potis.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@ -71,6 +72,7 @@ espcpputils::SchedulerTask schedulerTasksArr[] {
|
||||
#ifdef FEATURE_NTP
|
||||
espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms },
|
||||
#endif
|
||||
espcpputils::SchedulerTask { "potis", initPotis, readPotis, 20ms },
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
@ -424,7 +424,6 @@ char TEXT_MOTORTEST[] = "Motortest";
|
||||
|
||||
//TimersMenu
|
||||
//char TEXT_TIMERS[] = "Timers";
|
||||
char TEXT_POTIREADRATE[] = "Poti read rate";
|
||||
char TEXT_MODEUPDATERATE[] = "Mode update rate";
|
||||
char TEXT_STATSUPDATERATE[] = "Stats update rate";
|
||||
char TEXT_DISPLAYUPDATERATE[] = "Display update rate";
|
||||
|
@ -424,7 +424,6 @@ extern char TEXT_MOTORTEST[];
|
||||
|
||||
//TimersMenu
|
||||
//extern char TEXT_TIMERS[];
|
||||
extern char TEXT_POTIREADRATE[];
|
||||
extern char TEXT_MODEUPDATERATE[];
|
||||
extern char TEXT_STATSUPDATERATE[];
|
||||
extern char TEXT_DISPLAYUPDATERATE[];
|
||||
|
@ -247,69 +247,6 @@ void updateAccumulators()
|
||||
avgSpeedKmh = convertToKmh(avgSpeed);
|
||||
}
|
||||
|
||||
void readPotis()
|
||||
{
|
||||
[[maybe_unused]]
|
||||
constexpr auto sampleMultipleTimes = [](int pin){
|
||||
analogRead(pin);
|
||||
double sum{};
|
||||
const auto sampleCount = settings.boardcomputerHardware.sampleCount;
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
sum += analogRead(pin);
|
||||
return sum / sampleCount;
|
||||
};
|
||||
|
||||
raw_gas = std::nullopt;
|
||||
raw_brems = std::nullopt;
|
||||
|
||||
#ifdef FEATURE_CAN
|
||||
const auto now = espchrono::millis_clock::now();
|
||||
|
||||
if (can::can_gas)
|
||||
{
|
||||
if (now - can::last_can_gas < 100ms)
|
||||
raw_gas = *can::can_gas;
|
||||
else
|
||||
can::can_gas = std::nullopt;
|
||||
}
|
||||
|
||||
if (can::can_brems)
|
||||
{
|
||||
if (now - can::last_can_brems < 100ms)
|
||||
raw_brems = *can::can_brems;
|
||||
else
|
||||
can::can_brems = std::nullopt;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_ADC_IN
|
||||
if (!raw_gas)
|
||||
raw_gas = sampleMultipleTimes(PINS_GAS);
|
||||
if (!raw_brems)
|
||||
raw_brems = sampleMultipleTimes(PINS_BREMS);
|
||||
#endif
|
||||
|
||||
if (raw_gas)
|
||||
gas = cpputils::mapValueClamped<float>(*raw_gas, settings.boardcomputerHardware.gasMin, settings.boardcomputerHardware.gasMax, 0., 1000.);
|
||||
else
|
||||
gas = std::nullopt;
|
||||
if (raw_brems)
|
||||
brems = cpputils::mapValueClamped<float>(*raw_brems, settings.boardcomputerHardware.bremsMin, settings.boardcomputerHardware.bremsMax, 0., 1000.);
|
||||
else
|
||||
brems = std::nullopt;
|
||||
|
||||
#ifdef FEATURE_GAMETRAK
|
||||
raw_gametrakX = sampleMultipleTimes(PINS_GAMETRAKX);
|
||||
gametrakX = cpputils::mapValueClamped<float>(raw_gametrakX, settings.boardcomputerHardware.gametrakXMin, settings.boardcomputerHardware.gametrakXMax, 0., 1000.);
|
||||
|
||||
raw_gametrakY = sampleMultipleTimes(PINS_GAMETRAKY);
|
||||
gametrakY = cpputils::mapValueClamped<float>(raw_gametrakY, settings.boardcomputerHardware.gametrakYMin, settings.boardcomputerHardware.gametrakYMax, 0., 1000.);
|
||||
|
||||
raw_gametrakDist = sampleMultipleTimes(PINS_GAMETRAKDIST);
|
||||
gametrakDist = cpputils::mapValueClamped<float>(raw_gametrakDist, settings.boardcomputerHardware.gametrakDistMin, settings.boardcomputerHardware.gametrakDistMax, 0., 1000.);
|
||||
#endif
|
||||
}
|
||||
|
||||
float wattToAmpere(float watt) {
|
||||
float voltage = std::max(controllers.front.feedback.batVoltage, controllers.back.feedback.batVoltage);
|
||||
if (voltage > 50) voltage = 50;
|
||||
|
Reference in New Issue
Block a user