C
Qt Quick Ultralite Automotive Cluster Demo
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
#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 _lowBeamHeadlightsTimestamp;
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