C

Qt Quick Ultralite Motorcycle Cluster Demo

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#ifndef DRIVETRAIN_H #define DRIVETRAIN_H #include <stdint.h> namespace Simulation { class Drivetrain { public: struct Config { static const int MAX_GEARS = 7; int maxRpm; int minRpm; int shiftUpAtRpm; int shiftDownAtRpm; float tireCircumference; // cm float diffRatio; int gearNum; float gearRatios[MAX_GEARS]; }; struct DriveData { int speed; int rpm; int gear; float fuelLevel; float odometer; float tripDistance; int targetSpeed; float acceleration; float targetFuel; float fuelSpeed; }; Drivetrain(const Config &config); void update(uint32_t tick); void reset(); void setSpeedTarget(int targetSpeed, bool withRandomAccChanges); void setFuelTarget(float targetFuel, float fuelSpeed); void forceNeutraulGear(bool setNeutral); const DriveData &getDriveData() const; bool isTargetSpeedReached() const; private: void calculateSpeedData(uint32_t tick, float acceleration); void updateRpm(uint32_t tick, float acceleration); void updateGearShift(uint32_t tick); void shiftGear(int delta); int calculateRpm(int speed, int gear) const; void updateSpeed(); int calculateSpeed(int rpm, int gear) const; void updateFuelLevel(); void updateOdometers(uint32_t tick); DriveData _data; uint32_t _timeFromLastRandomAccChange; bool _enableRandomAccChanges; uint32_t _timeCounterForShiftUp; const Config &_config; }; } // namespace Simulation #endif // DRIVETRAIN_H