Merge pull request #257 from bobbycar-graz/espchrono-fixes
This commit is contained in:
@ -48,7 +48,8 @@ class SendBobbycarTimesyncMessageAction : public virtual espgui::ActionInterface
|
||||
public:
|
||||
void triggered() override
|
||||
{
|
||||
const auto message = fmt::format("BOBBYT:{}", espchrono::utc_clock::now().time_since_epoch().count());
|
||||
using namespace std::chrono_literals;
|
||||
const auto message = fmt::format("BOBBYT:{}", espchrono::utc_clock::now().time_since_epoch() / 1ms);
|
||||
espnow::send_espnow_message(message);
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ float getAvgWhPerKm()
|
||||
|
||||
float getAvgKmh()
|
||||
{
|
||||
return (drivingStatistics.meters_driven / 1000.) / (drivingStatistics.currentDrivingTime.count() / 1000 / 60 / 60); // (meter / 1000) / (ms / 1000 / 60 / 60)
|
||||
return (drivingStatistics.meters_driven / 1000.) / ((drivingStatistics.currentDrivingTime / 1ms) / 1000 / 60 / 60); // (meter / 1000) / (ms / 1000 / 60 / 60)
|
||||
}
|
||||
|
||||
float getEstimatedKmLeft()
|
||||
@ -85,7 +85,7 @@ void calculateStatistics()
|
||||
const auto duration = espchrono::ago(last_km_calculation);
|
||||
last_km_calculation = espchrono::millis_clock::now();
|
||||
|
||||
const float meters_driven_now = (abs(avgSpeedKmh) / 3.6) * (duration.count() / 1000.);
|
||||
const float meters_driven_now = (abs(avgSpeedKmh) / 3.6) * ((duration / 1ms) / 1000.);
|
||||
drivingStatistics.meters_driven += meters_driven_now;
|
||||
drivingStatistics.totalMeters += meters_driven_now; // Udate meters driven
|
||||
|
||||
@ -100,14 +100,14 @@ void calculateStatistics()
|
||||
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
|
||||
{
|
||||
auto watt = sumCurrent * *avgVoltage;
|
||||
const float ws_driven_now = watt * (duration.count() / 1000.);
|
||||
const float ws_driven_now = watt * ((duration / 1ms) / 1000.);
|
||||
drivingStatistics.wh_used += ws_driven_now / 3600; // Wh
|
||||
drivingStatistics.batteryWhEstimate -= ws_driven_now / 3600;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
drivingStatistics.wh_used += (13 * (duration.count() / 1000.)) / 3600; // Wh
|
||||
drivingStatistics.wh_used += (13 * ((duration / 1ms) / 1000.)) / 3600; // Wh
|
||||
drivingStatistics.batteryWhEstimate = getRemainingWattHours();
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ void showSpeedSyncAnimation()
|
||||
#endif
|
||||
|
||||
static auto last_interval = espchrono::millis_clock::now();
|
||||
auto difference_ms = espchrono::ago(last_interval).count();
|
||||
const auto difference_ms = espchrono::ago(last_interval) / 1ms;
|
||||
|
||||
static float hue_result = 0;
|
||||
|
||||
|
@ -55,7 +55,7 @@ void spamUdpBroadcast()
|
||||
}
|
||||
|
||||
std::string buf;
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch().count();
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch() / 1ms;
|
||||
|
||||
buf = fmt::format("uptime: {}", uptime);
|
||||
|
||||
@ -81,7 +81,7 @@ std::string buildUdpCloudJson()
|
||||
}
|
||||
StaticJsonDocument<1024> doc;
|
||||
std::string buf;
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch().count();
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch() / 1ms;
|
||||
|
||||
float watt{0};
|
||||
const auto avgVoltage = controllers.getAvgVoltage();
|
||||
@ -147,7 +147,7 @@ std::string buildUdpCloudJson()
|
||||
doc["l"] = isLocked;
|
||||
doc["mN"] = drivingStatistics.meters_driven;
|
||||
doc["mT"] = drivingStatistics.totalMeters;
|
||||
doc["dT"] = drivingStatistics.currentDrivingTime.count();
|
||||
doc["dT"] = drivingStatistics.currentDrivingTime / 1ms;
|
||||
doc["cW"] = watt;
|
||||
doc["wN"] = drivingStatistics.wh_used;
|
||||
doc["wL"] = getRemainingWattHours();
|
||||
@ -177,7 +177,7 @@ std::string buildUdpCloudString()
|
||||
std::string buf;
|
||||
buf.reserve(1024);
|
||||
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch().count();
|
||||
const auto uptime = espchrono::millis_clock::now().time_since_epoch() / 1ms;
|
||||
|
||||
float watt{0};
|
||||
const auto avgVoltage = controllers.getAvgVoltage();
|
||||
@ -294,7 +294,7 @@ std::string buildUdpCloudString()
|
||||
buf += fmt::format("\"l\":{},", isLocked);
|
||||
buf += fmt::format("\"mN\":{},", drivingStatistics.meters_driven);
|
||||
buf += fmt::format("\"mT\":{},", drivingStatistics.totalMeters);
|
||||
buf += fmt::format("\"dT\":{},", drivingStatistics.currentDrivingTime.count());
|
||||
buf += fmt::format("\"dT\":{},", drivingStatistics.currentDrivingTime / 1ms);
|
||||
buf += fmt::format("\"cW\":{},", watt);
|
||||
buf += fmt::format("\"wN\":{},", drivingStatistics.wh_used);
|
||||
buf += fmt::format("\"wL\":{},", getRemainingWattHours());
|
||||
|
Reference in New Issue
Block a user