Merge pull request #160 from bobbycar-graz/more_tasks_in_taskmanager
More tasks in task manager
This commit is contained in:
@ -30,6 +30,7 @@ set(headers
|
|||||||
battery.h
|
battery.h
|
||||||
ble_bobby.h
|
ble_bobby.h
|
||||||
bletexthelpers.h
|
bletexthelpers.h
|
||||||
|
bluetooth_bobby.h
|
||||||
bluetoothmode.h
|
bluetoothmode.h
|
||||||
bluetoothtexthelpers.h
|
bluetoothtexthelpers.h
|
||||||
bmsutils.h
|
bmsutils.h
|
||||||
@ -179,10 +180,12 @@ set(headers
|
|||||||
mosfets.h
|
mosfets.h
|
||||||
newsettings.h
|
newsettings.h
|
||||||
ota.h
|
ota.h
|
||||||
|
potis.h
|
||||||
presets.h
|
presets.h
|
||||||
qrimport.h
|
qrimport.h
|
||||||
rotary.h
|
rotary.h
|
||||||
screens.h
|
screens.h
|
||||||
|
serial.h
|
||||||
serialhandler.h
|
serialhandler.h
|
||||||
settings.h
|
settings.h
|
||||||
settingspersister.h
|
settingspersister.h
|
||||||
@ -242,6 +245,7 @@ set(sources
|
|||||||
battery.cpp
|
battery.cpp
|
||||||
ble_bobby.cpp
|
ble_bobby.cpp
|
||||||
bletexthelpers.cpp
|
bletexthelpers.cpp
|
||||||
|
bluetooth_bobby.cpp
|
||||||
bluetoothmode.cpp
|
bluetoothmode.cpp
|
||||||
bluetoothtexthelpers.cpp
|
bluetoothtexthelpers.cpp
|
||||||
bmsutils.cpp
|
bmsutils.cpp
|
||||||
@ -392,10 +396,12 @@ set(sources
|
|||||||
mosfets.cpp
|
mosfets.cpp
|
||||||
newsettings.cpp
|
newsettings.cpp
|
||||||
ota.cpp
|
ota.cpp
|
||||||
|
potis.cpp
|
||||||
presets.cpp
|
presets.cpp
|
||||||
qrimport.cpp
|
qrimport.cpp
|
||||||
rotary.cpp
|
rotary.cpp
|
||||||
screens.cpp
|
screens.cpp
|
||||||
|
serial.cpp
|
||||||
serialhandler.cpp
|
serialhandler.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
settingspersister.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 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; } };
|
struct GametrakDistMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.gametrakDistMax; } };
|
||||||
#endif
|
#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 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 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; } };
|
struct DisplayUpdateRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.displayUpdateRate; } };
|
||||||
|
37
main/bluetooth_bobby.cpp
Normal file
37
main/bluetooth_bobby.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "bluetooth_bobby.h"
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
#include "actions/bluetoothbeginaction.h"
|
||||||
|
#include "actions/bluetoothbeginmasteraction.h"
|
||||||
|
#ifdef FEATURE_BMS
|
||||||
|
#include "actions/bluetoothconnectbmsaction.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
void bluetooth_init()
|
||||||
|
{
|
||||||
|
if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master)
|
||||||
|
{
|
||||||
|
bootLabel.redraw("bluetooth begin master");
|
||||||
|
BluetoothBeginMasterAction{}.triggered();
|
||||||
|
#ifdef FEATURE_BMS
|
||||||
|
if (settings.autoConnectBms)
|
||||||
|
{
|
||||||
|
bootLabel.redraw("connect BMS");
|
||||||
|
BluetoothConnectBmsAction{}.triggered();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave)
|
||||||
|
{
|
||||||
|
bootLabel.redraw("bluetooth begin");
|
||||||
|
BluetoothBeginAction{}.triggered();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bluetooth_update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
6
main/bluetooth_bobby.h
Normal file
6
main/bluetooth_bobby.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
void bluetooth_init();
|
||||||
|
void bluetooth_update();
|
||||||
|
#endif
|
@ -11,14 +11,6 @@
|
|||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using PotiReadRateChangeDisplay = makeComponent<
|
|
||||||
ChangeValueDisplay<int16_t>,
|
|
||||||
StaticText<TEXT_POTIREADRATE>,
|
|
||||||
PotiReadRateAccessor,
|
|
||||||
BackActionInterface<SwitchScreenAction<TimersMenu>>,
|
|
||||||
SwitchScreenAction<TimersMenu>
|
|
||||||
>;
|
|
||||||
|
|
||||||
using ModeUpdateRateChangeDisplay = makeComponent<
|
using ModeUpdateRateChangeDisplay = makeComponent<
|
||||||
ChangeValueDisplay<int16_t>,
|
ChangeValueDisplay<int16_t>,
|
||||||
StaticText<TEXT_MODEUPDATERATE>,
|
StaticText<TEXT_MODEUPDATERATE>,
|
||||||
@ -64,7 +56,6 @@ using CanReceiveRateChangeDisplay = makeComponent<
|
|||||||
|
|
||||||
TimersMenu::TimersMenu()
|
TimersMenu::TimersMenu()
|
||||||
{
|
{
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_POTIREADRATE>, SwitchScreenAction<PotiReadRateChangeDisplay>>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MODEUPDATERATE>, SwitchScreenAction<ModeUpdateRateChangeDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MODEUPDATERATE>, SwitchScreenAction<ModeUpdateRateChangeDisplay>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STATSUPDATERATE>, SwitchScreenAction<StatsUpdateRateChangeDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STATSUPDATERATE>, SwitchScreenAction<StatsUpdateRateChangeDisplay>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISPLAYUPDATERATE>, SwitchScreenAction<DisplayUpdateRateChangeDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DISPLAYUPDATERATE>, SwitchScreenAction<DisplayUpdateRateChangeDisplay>>>();
|
||||||
|
@ -32,13 +32,6 @@ using namespace std::chrono_literals;
|
|||||||
#endif
|
#endif
|
||||||
#include "presets.h"
|
#include "presets.h"
|
||||||
#include "statistics.h"
|
#include "statistics.h"
|
||||||
#ifdef FEATURE_BLUETOOTH
|
|
||||||
#include "actions/bluetoothbeginaction.h"
|
|
||||||
#include "actions/bluetoothbeginmasteraction.h"
|
|
||||||
#ifdef FEATURE_BMS
|
|
||||||
#include "actions/bluetoothconnectbmsaction.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#ifdef FEATURE_BLE
|
#ifdef FEATURE_BLE
|
||||||
#include "ble_bobby.h"
|
#include "ble_bobby.h"
|
||||||
#endif
|
#endif
|
||||||
@ -71,7 +64,6 @@ using namespace std::chrono_literals;
|
|||||||
#include "taskmanager.h"
|
#include "taskmanager.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::optional<espchrono::millis_clock::time_point> lastPotiRead;
|
|
||||||
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastModeUpdate;
|
||||||
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastStatsUpdate;
|
||||||
std::optional<espchrono::millis_clock::time_point> lastDisplayUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastDisplayUpdate;
|
||||||
@ -141,26 +133,6 @@ extern "C" void app_main()
|
|||||||
task.setup();
|
task.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
|
||||||
if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master)
|
|
||||||
{
|
|
||||||
bootLabel.redraw("bluetooth begin master");
|
|
||||||
BluetoothBeginMasterAction{}.triggered();
|
|
||||||
#ifdef FEATURE_BMS
|
|
||||||
if (settings.autoConnectBms)
|
|
||||||
{
|
|
||||||
bootLabel.redraw("connect BMS");
|
|
||||||
BluetoothConnectBmsAction{}.triggered();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave)
|
|
||||||
{
|
|
||||||
bootLabel.redraw("bluetooth begin");
|
|
||||||
BluetoothBeginAction{}.triggered();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FEATURE_CAN
|
#ifdef FEATURE_CAN
|
||||||
bootLabel.redraw("can");
|
bootLabel.redraw("can");
|
||||||
can::initCan();
|
can::initCan();
|
||||||
@ -182,11 +154,6 @@ extern "C" void app_main()
|
|||||||
initLedStrip();
|
initLedStrip();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
raw_gas = std::nullopt;
|
|
||||||
raw_brems = std::nullopt;
|
|
||||||
gas = std::nullopt;
|
|
||||||
brems = std::nullopt;
|
|
||||||
|
|
||||||
for (Controller &controller : controllers)
|
for (Controller &controller : controllers)
|
||||||
controller.command.buzzer = {};
|
controller.command.buzzer = {};
|
||||||
|
|
||||||
@ -250,14 +217,6 @@ extern "C" void app_main()
|
|||||||
for (auto &schedulerTask : schedulerTasks)
|
for (auto &schedulerTask : schedulerTasks)
|
||||||
{
|
{
|
||||||
schedulerTask.loop();
|
schedulerTask.loop();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lastPotiRead || now - *lastPotiRead >= 1000ms/settings.boardcomputerHardware.timersSettings.potiReadRate)
|
|
||||||
{
|
|
||||||
readPotis();
|
|
||||||
|
|
||||||
lastPotiRead = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lastModeUpdate || now - *lastModeUpdate >= 1000ms/settings.boardcomputerHardware.timersSettings.modeUpdateRate)
|
if (!lastModeUpdate || now - *lastModeUpdate >= 1000ms/settings.boardcomputerHardware.timersSettings.modeUpdateRate)
|
||||||
|
85
main/potis.cpp
Normal file
85
main/potis.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#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()
|
||||||
|
{
|
||||||
|
raw_gas = std::nullopt;
|
||||||
|
raw_brems = std::nullopt;
|
||||||
|
gas = std::nullopt;
|
||||||
|
brems = std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void readPotis()
|
||||||
|
{
|
||||||
|
[[maybe_unused]]
|
||||||
|
constexpr auto sampleMultipleTimes = [](uint8_t 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 {
|
constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings {
|
||||||
.potiReadRate = 50,
|
|
||||||
.modeUpdateRate = 50,
|
.modeUpdateRate = 50,
|
||||||
.statsUpdateRate = 50,
|
.statsUpdateRate = 50,
|
||||||
.displayUpdateRate = 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
|
#endif
|
||||||
|
|
||||||
struct TimersSettings {
|
struct TimersSettings {
|
||||||
int16_t potiReadRate;
|
|
||||||
int16_t modeUpdateRate;
|
int16_t modeUpdateRate;
|
||||||
int16_t statsUpdateRate;
|
int16_t statsUpdateRate;
|
||||||
int16_t displayUpdateRate;
|
int16_t displayUpdateRate;
|
||||||
@ -300,7 +299,6 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
|||||||
callable("gametrakDistMax", boardcomputerHardware.gametrakDistMax);
|
callable("gametrakDistMax", boardcomputerHardware.gametrakDistMax);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
callable("potiReadRate", boardcomputerHardware.timersSettings.potiReadRate);
|
|
||||||
callable("modeUpdateRate", boardcomputerHardware.timersSettings.modeUpdateRate);
|
callable("modeUpdateRate", boardcomputerHardware.timersSettings.modeUpdateRate);
|
||||||
callable("statsUpdateRate", boardcomputerHardware.timersSettings.statsUpdateRate);
|
callable("statsUpdateRate", boardcomputerHardware.timersSettings.statsUpdateRate);
|
||||||
callable("displayUpdateRa", boardcomputerHardware.timersSettings.displayUpdateRate);
|
callable("displayUpdateRa", boardcomputerHardware.timersSettings.displayUpdateRate);
|
||||||
|
@ -37,6 +37,10 @@
|
|||||||
#ifdef FEATURE_NTP
|
#ifdef FEATURE_NTP
|
||||||
#include "time_bobbycar.h"
|
#include "time_bobbycar.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "potis.h"
|
||||||
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
#include "bluetooth_bobby.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
@ -70,6 +74,10 @@ espcpputils::SchedulerTask schedulerTasksArr[] {
|
|||||||
espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms },
|
espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms },
|
||||||
#ifdef FEATURE_NTP
|
#ifdef FEATURE_NTP
|
||||||
espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms },
|
espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms },
|
||||||
|
#endif
|
||||||
|
espcpputils::SchedulerTask { "potis", initPotis, readPotis, 20ms },
|
||||||
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
espcpputils::SchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -424,7 +424,6 @@ char TEXT_MOTORTEST[] = "Motortest";
|
|||||||
|
|
||||||
//TimersMenu
|
//TimersMenu
|
||||||
//char TEXT_TIMERS[] = "Timers";
|
//char TEXT_TIMERS[] = "Timers";
|
||||||
char TEXT_POTIREADRATE[] = "Poti read rate";
|
|
||||||
char TEXT_MODEUPDATERATE[] = "Mode update rate";
|
char TEXT_MODEUPDATERATE[] = "Mode update rate";
|
||||||
char TEXT_STATSUPDATERATE[] = "Stats update rate";
|
char TEXT_STATSUPDATERATE[] = "Stats update rate";
|
||||||
char TEXT_DISPLAYUPDATERATE[] = "Display update rate";
|
char TEXT_DISPLAYUPDATERATE[] = "Display update rate";
|
||||||
|
@ -424,7 +424,6 @@ extern char TEXT_MOTORTEST[];
|
|||||||
|
|
||||||
//TimersMenu
|
//TimersMenu
|
||||||
//extern char TEXT_TIMERS[];
|
//extern char TEXT_TIMERS[];
|
||||||
extern char TEXT_POTIREADRATE[];
|
|
||||||
extern char TEXT_MODEUPDATERATE[];
|
extern char TEXT_MODEUPDATERATE[];
|
||||||
extern char TEXT_STATSUPDATERATE[];
|
extern char TEXT_STATSUPDATERATE[];
|
||||||
extern char TEXT_DISPLAYUPDATERATE[];
|
extern char TEXT_DISPLAYUPDATERATE[];
|
||||||
|
@ -247,69 +247,6 @@ void updateAccumulators()
|
|||||||
avgSpeedKmh = convertToKmh(avgSpeed);
|
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 wattToAmpere(float watt) {
|
||||||
float voltage = std::max(controllers.front.feedback.batVoltage, controllers.back.feedback.batVoltage);
|
float voltage = std::max(controllers.front.feedback.batVoltage, controllers.back.feedback.batVoltage);
|
||||||
if (voltage > 50) voltage = 50;
|
if (voltage > 50) voltage = 50;
|
||||||
|
Reference in New Issue
Block a user