C
Qt Quick Ultralite Automotive 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 DRIVESTATES_H #define DRIVESTATES_H #include "simulation/smfwd.h" #include "simulation/states.h" namespace Simulation { struct DriveState : public ClusterModeState { protected: DriveState(Automotive::MainModel::ClusterMode, char gearLabel); void onEnter(const StateId &prevState, const Layer &layer, Machine &sm); void onUpdate(uint32_t tick, const Layer &layer, Machine &sm); void onLeave(const StateId &nextState, const Layer &layer, Machine &sm); protected: virtual void updateModels(); virtual void drive(uint32_t tick) = 0; void updateLights(uint32_t tick); void updateLaneAssist(); void updateGuides(); void updateDrivetrain(uint32_t tick, float acceleration); uint64_t getStateTime() const { return _cumulatedTime; } private: char _gearLabel; uint64_t _cumulatedTime; int _lastGear; uint32_t _highBeamTimestamp; uint32_t _turnSignalTimestamp; uint32_t _laneAssistTimestamp; float _guideArrowNextChange; float _acceleration; bool _comesFromDriveState; }; struct NormalDriveState : DriveState { NormalDriveState(); void onEnter(const StateId &prevState, const Layer &layer, Machine &sm); void onUpdate(uint32_t tick, const Layer &layer, Machine &sm); void updateModels(); private: void randomizeAccChange(); void drive(uint32_t tick); uint32_t _accChangeTimestamp; float _targetAcc; float _accChange; }; struct SportDriveState : DriveState { SportDriveState(); void onEnter(const StateId &prevState, const Layer &layer, Machine &sm); void onUpdate(uint32_t tick, const Layer &layer, Machine &sm); private: void drive(uint32_t tick); void randomizeTargetSpeed(); void updateCooldown(); float _targetSpeed; bool _cooldown; }; } // namespace Simulation #endif // DRIVESTATES_H