From 085415868ff366f4df424b846c402cfae4140d76 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 2 Oct 2023 22:14:03 -0700 Subject: [PATCH] trip odometer run time --- firmware/controllers/algo/trip_odometer.cpp | 12 ++++++++++++ firmware/controllers/algo/trip_odometer.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/firmware/controllers/algo/trip_odometer.cpp b/firmware/controllers/algo/trip_odometer.cpp index 3fba94734d..f477c0affd 100644 --- a/firmware/controllers/algo/trip_odometer.cpp +++ b/firmware/controllers/algo/trip_odometer.cpp @@ -45,6 +45,18 @@ void TripOdometer::onSlowCallback() { m_distanceMeters++; m_distanceRemainder--; } + + constexpr float slowCallbackPerSecond = 1000 / SLOW_CALLBACK_PERIOD_MS; + m_slowCallbackCounter++; + if (m_slowCallbackCounter == slowCallbackPerSecond) { + m_slowCallbackCounter = 0; + + m_ignitionOnSeconds++; + + if (engine->rpmCalculator.isRunning()) { + m_engineRunningSeconds++; + } + } } uint32_t TripOdometer::getDistanceMeters() const { diff --git a/firmware/controllers/algo/trip_odometer.h b/firmware/controllers/algo/trip_odometer.h index 52bd7e295e..af452a1b20 100644 --- a/firmware/controllers/algo/trip_odometer.h +++ b/firmware/controllers/algo/trip_odometer.h @@ -12,12 +12,19 @@ public: uint32_t getDistanceMeters() const; private: + // Fuel consumed uint32_t m_consumedGrams = 0; float m_consumedRemainder = 0; float m_rate = 0; + // Distance travelled uint32_t m_distanceMeters = 0; float m_distanceRemainder = 0; + // Engine run time and ign on time + uint32_t m_slowCallbackCounter = 0; + uint32_t m_ignitionOnSeconds = 0; + uint32_t m_engineRunningSeconds = 0; + Timer m_timer; };