driving statistics fixes

This commit is contained in:
2021-11-21 01:36:44 +01:00
parent 28a4933928
commit ed51591489
10 changed files with 75 additions and 133 deletions

View File

@ -1,4 +1,6 @@
#include "utils.h"
// local includes
#include "globals.h"
using namespace std::chrono_literals;
@ -315,40 +317,19 @@ float wattToAmpere(float watt) {
return watt / voltage;
}
float wattToMotorCurrent(float watt) {
float wattToMotorCurrent(float watt)
{
return wattToAmpere(watt) / 4;
}
std::string get_current_uptime_string() {
std::string get_current_uptime_string()
{
const auto uptime_time_point = espchrono::utc_clock::now();
const auto dateTimeUptime = espchrono::toDateTime(uptime_time_point);
std::string out = fmt::format("Up: {:02d}:{:02d}:{:02d}", dateTimeUptime.hour, dateTimeUptime.minute, dateTimeUptime.second);
return out;
}
void secondsToHMS( const float seconds, uint16_t &h, uint16_t &m, uint16_t &s )
{
uint32_t t = seconds;
s = t % 60;
t = (t - s)/60;
m = t % 60;
t = (t - m)/60;
h = t;
}
std::string get_current_driving_time_string()
{
uint16_t hour{};
uint16_t minute{};
uint16_t second{};
secondsToHMS(drivingStatistics.currentDrivingTime, hour, minute, second);
std::string out = fmt::format("Drive: {:02d}:{:02d}:{:02d}", hour, minute, second);
return out;
}
uint8_t time_to_percent(std::chrono::duration<long, std::ratio<1,1000>> repeat, std::chrono::duration<long, std::ratio<1,1000>> riseTime, std::chrono::duration<long, std::ratio<1,1000>> fullTime, size_t numLeds, bool invert)
{
const auto now = espchrono::millis_clock::now().time_since_epoch() % repeat;