#pragma once #include #include #include namespace roro { // Smooths battery voltage samples and turns them into a charge percentage. class BatteryEstimator { public: // Typical single-cell LiPo discharge curve under light load. static int percentFromMillivolts(int millivolts); void addSample(int millivolts); bool hasReading() const { return count_ > 0; } int millivolts() const; // median of the recent samples int percent() const { return percentFromMillivolts(millivolts()); } private: static constexpr size_t kWindow = 8; std::array samples_{}; size_t next_ = 0; size_t count_ = 0; }; } // namespace roro